@Test
 public void test() throws IOException, ClassNotFoundException {
   this.test((Serializable) null, true);
   this.test("test", true);
   this.test(Boolean.TRUE, true);
   this.test(Byte.valueOf(Byte.MAX_VALUE), true);
   this.test(Character.valueOf(Character.MAX_VALUE), true);
   this.test(Double.valueOf(Double.MAX_VALUE), true);
   this.test(Float.valueOf(Float.MAX_VALUE), true);
   this.test(Integer.valueOf(Integer.MAX_VALUE), true);
   this.test(Long.valueOf(Long.MAX_VALUE), true);
   this.test(Short.valueOf(Short.MAX_VALUE), true);
   this.test(new String[] {"test"}, true);
   this.test(new boolean[] {Boolean.TRUE}, true);
   this.test(new byte[] {Byte.MAX_VALUE}, true);
   this.test(new char[] {Character.MAX_VALUE}, true);
   this.test(new double[] {Double.MAX_VALUE}, true);
   this.test(new float[] {Float.MAX_VALUE}, true);
   this.test(new int[] {Integer.MAX_VALUE}, true);
   this.test(new long[] {Long.MAX_VALUE}, true);
   this.test(new short[] {Short.MAX_VALUE}, true);
   this.test(new Boolean[] {Boolean.TRUE}, true);
   this.test(new Byte[] {Byte.valueOf(Byte.MAX_VALUE)}, true);
   this.test(new Character[] {Character.valueOf(Character.MAX_VALUE)}, true);
   this.test(new Double[] {Double.valueOf(Double.MAX_VALUE)}, true);
   this.test(new Float[] {Float.valueOf(Float.MAX_VALUE)}, true);
   this.test(new Integer[] {Integer.valueOf(Integer.MAX_VALUE)}, true);
   this.test(new Long[] {Long.valueOf(Long.MAX_VALUE)}, true);
   this.test(new Short[] {Short.valueOf(Short.MAX_VALUE)}, true);
   this.test(this.getClass(), false);
   this.test(new Date(System.currentTimeMillis()), false);
   this.test(new Object(), false);
 }
  @Test
  public void testMapping() {
    List<String> input = Arrays.asList("Capital", "lower", "Foo", "bar");
    Collector<String, ?, Map<Boolean, Optional<Integer>>> collector =
        MoreCollectors.partitioningBy(
            str -> Character.isUpperCase(str.charAt(0)),
            MoreCollectors.mapping(String::length, MoreCollectors.first()));
    checkShortCircuitCollector(
        "mapping", new BooleanMap<>(Optional.of(7), Optional.of(5)), 2, input::stream, collector);
    Collector<String, ?, Map<Boolean, Optional<Integer>>> collectorLast =
        MoreCollectors.partitioningBy(
            str -> Character.isUpperCase(str.charAt(0)),
            MoreCollectors.mapping(String::length, MoreCollectors.last()));
    checkCollector(
        "last", new BooleanMap<>(Optional.of(3), Optional.of(3)), input::stream, collectorLast);

    input = Arrays.asList("Abc", "Bac", "Aac", "Abv", "Bbc", "Bgd", "Atc", "Bpv");
    Map<Character, List<String>> expected =
        EntryStream.of('A', Arrays.asList("Abc", "Aac"), 'B', Arrays.asList("Bac", "Bbc")).toMap();
    AtomicInteger cnt = new AtomicInteger();
    Collector<String, ?, Map<Character, List<String>>> groupMap =
        Collectors.groupingBy(
            s -> s.charAt(0),
            MoreCollectors.mapping(
                x -> {
                  cnt.incrementAndGet();
                  return x;
                },
                MoreCollectors.head(2)));
    checkCollector("groupMap", expected, input::stream, groupMap);
    cnt.set(0);
    assertEquals(expected, input.stream().collect(groupMap));
    assertEquals(4, cnt.get());
  }
Example #3
0
  @Test
  public void stringSerialization() {
    // Characters
    DataOutput out = serialize.getDataOutput(((int) Character.MAX_VALUE) * 2 + 8, true);
    for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
      out.writeObjectNotNull(Character.valueOf(c));
    }
    ReadBuffer b = out.getStaticBuffer().asReadBuffer();
    for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
      assertEquals(c, serialize.readObjectNotNull(b, Character.class).charValue());
    }

    // String
    for (int t = 0; t < 10000; t++) {
      DataOutput out1 = serialize.getDataOutput(32 + 5, true);
      DataOutput out2 = serialize.getDataOutput(32 + 5, true);
      String s1 = RandomGenerator.randomString(1, 32);
      String s2 = RandomGenerator.randomString(1, 32);
      out1.writeObjectNotNull(s1);
      out2.writeObjectNotNull(s2);
      StaticBuffer b1 = out1.getStaticBuffer();
      StaticBuffer b2 = out2.getStaticBuffer();
      assertEquals(s1, serialize.readObjectNotNull(b1.asReadBuffer(), String.class));
      assertEquals(s2, serialize.readObjectNotNull(b2.asReadBuffer(), String.class));
      assertEquals(
          s1 + " vs " + s2, Integer.signum(s1.compareTo(s2)), Integer.signum(b1.compareTo(b2)));
    }
  }
Example #4
0
 @Test
 public void selectSupplementaryCharacter() {
   String s = new String(Character.toChars(135361));
   Document doc = Jsoup.parse("<div k" + s + "='" + s + "'>^" + s + "$/div>");
   assertEquals("div", doc.select("div[k" + s + "]").first().tagName());
   assertEquals("div", doc.select("div:containsOwn(" + s + ")").first().tagName());
 }
  private static String trimRight(String in) {
    int endIdx = in.length() - 1;
    while (endIdx > -1 && Character.isWhitespace(in.charAt(endIdx))) {
      endIdx--;
    }

    return in.substring(0, endIdx);
  }
 /** Test of prepWordForSave method, of class PdfWord. */
 @Test
 public void testPrepWordForSave() {
   assertEquals(instance.prepWordForSave(""), "");
   assertEquals(instance.prepWordForSave("az"), "az");
   assertEquals(instance.prepWordForSave("AZ"), "AZ");
   assertEquals(instance.prepWordForSave("09"), "09");
   assertEquals(instance.prepWordForSave("a'b"), "a'b");
   assertEquals(instance.prepWordForSave("a'"), "a");
   assertNotEquals(instance.prepWordForSave(Character.toString((char) 127)), "");
 }
Example #7
0
  @Test
  public void testLongLangRoundTrip() throws Exception {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 512; i++) {
      sb.append(Character.toChars('A' + (i % 26)));
    }
    URI subj = new URIImpl(EXAMPLE_NS + PICASSO);
    URI pred = new URIImpl(EXAMPLE_NS + PAINTS);
    Literal obj = new LiteralImpl("guernica" + sb.toString(), "es");

    testValueRoundTrip(subj, pred, obj);
  }
Example #8
0
  @Test
  public void testLongURIRoundTrip() throws Exception {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 512; i++) {
      sb.append(Character.toChars('A' + (i % 26)));
    }
    URI subj = new URIImpl(EXAMPLE_NS + PICASSO);
    URI pred = new URIImpl(EXAMPLE_NS + PAINTS);
    URI obj = new URIImpl(EXAMPLE_NS + GUERNICA + sb.toString());

    testValueRoundTrip(subj, pred, obj);
  }
  @Test
  public void testVerifyQualitySangerOutOfRange() {
    frag.setSequence(new Text("AGTAGTAGTAGTAGTAGTAGTAGTAGTAGT"));
    frag.setQuality(
        new Text("#############################" + Character.toString((char) 127))); // over range
    assertEquals(
        29,
        SequencedFragment.verifyQuality(
            frag.getQuality(), FormatConstants.BaseQualityEncoding.Sanger));

    frag.setQuality(new Text("##### ########################")); // under range
    assertEquals(
        5,
        SequencedFragment.verifyQuality(
            frag.getQuality(), FormatConstants.BaseQualityEncoding.Sanger));
  }