Exemplo n.º 1
0
 @Test
 public void testMultiSet() {
   HashMultiset<Integer> multiset = HashMultiset.create();
   multiset.add(1);
   multiset.add(1);
   multiset.add(2);
   multiset.add(2);
   multiset.add(4);
   multiset.add(4);
   multiset.add(4);
   Assert.assertTrue(multiset.size() == 7);
   Assert.assertTrue(multiset.contains(4));
   Assert.assertTrue(multiset.count(4) == 3);
   multiset.add(4, 5);
   Assert.assertTrue(multiset.count(4) == 8);
 }
  @BeforeExperiment
  void setUp() {
    hashMultiset = HashMultiset.create(size);
    linkedHashMultiset = LinkedHashMultiset.create(size);
    treeMultiset = TreeMultiset.create();

    Random random = new Random();

    int sizeRemaining = size;

    // TODO(kevinb): generate better test contents for multisets
    for (int i = 0; sizeRemaining > 0; i++) {
      // The JVM will return interned values for small ints.
      Integer value = random.nextInt(1000) + 128;
      int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
      sizeRemaining -= count;
      hashMultiset.add(value, count);
      linkedHashMultiset.add(value, count);
      treeMultiset.add(value, count);
    }

    // TODO(kevinb): convert to assert once benchmark tests enable asserts by default
    Preconditions.checkState(hashMultiset.size() == size);
  }