public void testBuilderAddAllMultiset() {
   Multiset<String> a = HashMultiset.create(asList("a", "b", "b"));
   Multiset<String> b = HashMultiset.create(asList("c", "b"));
   ImmutableSortedMultiset<String> multiset =
       ImmutableSortedMultiset.<String>naturalOrder().addAll(a).addAll(b).build();
   assertEquals(HashMultiset.create(asList("a", "b", "b", "b", "c")), multiset);
 }
 public void testBuilderSetCountIllegal() {
   ImmutableSortedMultiset.Builder<String> builder = ImmutableSortedMultiset.naturalOrder();
   try {
     builder.setCount("a", -2);
     fail("expected IllegalArgumentException");
   } catch (IllegalArgumentException expected) {
   }
 }
 public void testBuilderAddCopiesHandlesNullsCorrectly() {
   ImmutableSortedMultiset.Builder<String> builder = ImmutableSortedMultiset.naturalOrder();
   try {
     builder.addCopies(null, 2);
     fail("expected NullPointerException");
   } catch (NullPointerException expected) {
   }
 }
 public void testBuilderSetCount() {
   ImmutableSortedMultiset<String> multiset =
       ImmutableSortedMultiset.<String>naturalOrder()
           .add("a")
           .setCount("a", 2)
           .setCount("b", 3)
           .build();
   assertEquals(HashMultiset.create(asList("a", "a", "b", "b", "b")), multiset);
 }
  public void testBuilderAddAllHandlesNullsCorrectly() {
    ImmutableSortedMultiset.Builder<String> builder = ImmutableSortedMultiset.naturalOrder();
    try {
      builder.addAll((Collection<String>) null);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }

    builder = ImmutableSortedMultiset.naturalOrder();
    List<String> listWithNulls = asList("a", null, "b");
    try {
      builder.addAll(listWithNulls);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }

    builder = ImmutableSortedMultiset.naturalOrder();
    Multiset<String> multisetWithNull = LinkedHashMultiset.create(asList("a", null, "b"));
    try {
      builder.addAll(multisetWithNull);
      fail("expected NullPointerException");
    } catch (NullPointerException expected) {
    }
  }
Пример #6
0
  public String getResultsComparison(int precision) {
    List<List<Object>> controlResults = controlResult.getResults();
    List<List<Object>> testResults = testResult.getResults();

    if (valid() || (controlResults == null) || (testResults == null)) {
      return "";
    }

    Multiset<List<Object>> control =
        ImmutableSortedMultiset.copyOf(rowComparator(precision), controlResults);
    Multiset<List<Object>> test =
        ImmutableSortedMultiset.copyOf(rowComparator(precision), testResults);

    try {
      Iterable<ChangedRow> diff =
          ImmutableSortedMultiset.<ChangedRow>naturalOrder()
              .addAll(
                  Iterables.transform(
                      Multisets.difference(control, test),
                      row -> new ChangedRow(Changed.REMOVED, row, precision)))
              .addAll(
                  Iterables.transform(
                      Multisets.difference(test, control),
                      row -> new ChangedRow(Changed.ADDED, row, precision)))
              .build();
      diff = Iterables.limit(diff, 100);

      StringBuilder sb = new StringBuilder();

      sb.append(format("Control %s rows, Test %s rows%n", control.size(), test.size()));
      if (verboseResultsComparison) {
        Joiner.on("\n").appendTo(sb, diff);
      } else {
        sb.append("RESULTS DO NOT MATCH\n");
      }

      return sb.toString();
    } catch (TypesDoNotMatchException e) {
      return e.getMessage();
    }
  }
 public void testBuilderAddAllIterator() {
   Iterator<String> iterator = asList("a", "b", "a", "c").iterator();
   ImmutableSortedMultiset<String> multiset =
       ImmutableSortedMultiset.<String>naturalOrder().addAll(iterator).build();
   assertEquals(HashMultiset.create(asList("a", "b", "a", "c")), multiset);
 }