Skip to content

Commit

Permalink
Add new test "lessthan30" in candy kata
Browse files Browse the repository at this point in the history
  • Loading branch information
aqsa505 committed Sep 16, 2024
1 parent af282f3 commit ae953f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ public void commonInTop10()
Assertions.assertEquals(expectedSet, commonInTop10);
}

@Test
@Tag("SOLUTION")
public void lessThan30()
{
MutableList<Bag<Candy>> bagsOfCandy = this.collectBagsOfCandy();

Bag<Candy> bigBagOfCandy = null;

String stringOfItemToCount = null;

var expected = "{WHOPPERS=28, NERDS=28, HERSHEYS_KISSES=24, TWIX=26, SWEDISH_FISH=26}";
Assertions.assertEquals(null, stringOfItemToCount);
}

private MutableList<Bag<Candy>> collectBagsOfCandy()
{
return SchoolGroup.all().collect(SchoolGroup::trickOrTreat).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ public void commonInTop10()
Assertions.assertEquals(expectedSet, commonInTop10);
}

@Test
@Tag("KATA")
public void lessThan30()
{
MutableList<Bag<Candy>> bagsOfCandy = this.collectBagsOfCandy();

// Hint: Flatten the Bags of Candy into a single Bag
Bag<Candy> bigBagOfCandy = null;

// Find candies that are less than 30 in number in the big bag of candy and
// convert them to a string with its item count like so: "{WHOPPERS=28}
// Hint: use Bag#toStringOfItemToCount()
// Replace null with expected value in the solution

String stringOfItemToCount = bigBagOfCandy.selectByOccurrences(i -> i < 30).toStringOfItemToCount();

var expected = "{WHOPPERS=28, NERDS=28, HERSHEYS_KISSES=24, TWIX=26, SWEDISH_FISH=26}";
Assertions.assertEquals(expected, stringOfItemToCount);
}

private MutableList<Bag<Candy>> collectBagsOfCandy()
{
return SchoolGroup.all().collect(SchoolGroup::trickOrTreat).toList();
Expand Down

0 comments on commit ae953f9

Please sign in to comment.