コード例 #1
0
 @Test
 public void contains() {
   ImmutableBag<String> bag = this.newBag();
   for (int i = 1; i <= this.numKeys(); i++) {
     String key = String.valueOf(i);
     Assert.assertTrue(bag.contains(key));
     Assert.assertEquals(i, bag.occurrencesOf(key));
   }
   String missingKey = "0";
   Assert.assertFalse(bag.contains(missingKey));
   Assert.assertEquals(0, bag.occurrencesOf(missingKey));
 }
コード例 #2
0
  @Test
  public void newWithoutAll() {
    ImmutableBag<String> bag = this.newBag();
    ImmutableBag<String> withoutAll = bag.newWithoutAll(UnifiedSet.newSet(this.newBag()));
    Assert.assertEquals(Bags.immutable.of(), withoutAll);

    ImmutableBag<String> newBag =
        bag.newWithAll(Lists.fixedSize.of("0", "0", "0")).newWithoutAll(Lists.fixedSize.of("0"));

    Assert.assertEquals(0, newBag.occurrencesOf("0"));
  }
コード例 #3
0
  private void groupByAssertions(ImmutableBagMultimap<Boolean, String> multimap) {
    Verify.assertIterableEmpty(multimap.get(null));

    ImmutableBag<String> odds = multimap.get(true);
    ImmutableBag<String> evens = multimap.get(false);
    for (int i = 1; i <= this.numKeys(); i++) {
      String key = String.valueOf(i);
      ImmutableBag<String> containingBag = IntegerPredicates.isOdd().accept(i) ? odds : evens;
      ImmutableBag<String> nonContainingBag = IntegerPredicates.isOdd().accept(i) ? evens : odds;
      Assert.assertTrue(containingBag.contains(key));
      Assert.assertFalse(nonContainingBag.contains(key));

      Assert.assertEquals(i, containingBag.occurrencesOf(key));
    }
  }