From 6a2f9b45e85d9c3fd1ada04185272b37da01cb5f Mon Sep 17 00:00:00 2001 From: Aqsa Malik Date: Fri, 13 Sep 2024 20:21:03 -0400 Subject: [PATCH] Add new test "lessthan30" in candy kata --- .../candykata/CandyKataSolutionsTest.java | 14 +++++++++++++ .../collections/candykata/CandyKataTest.java | 21 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/candy-kata-solutions/src/test/java/org/eclipse/collections/candykata/CandyKataSolutionsTest.java b/candy-kata-solutions/src/test/java/org/eclipse/collections/candykata/CandyKataSolutionsTest.java index ddade154..e2c43845 100644 --- a/candy-kata-solutions/src/test/java/org/eclipse/collections/candykata/CandyKataSolutionsTest.java +++ b/candy-kata-solutions/src/test/java/org/eclipse/collections/candykata/CandyKataSolutionsTest.java @@ -57,6 +57,20 @@ public void commonInTop10() Assertions.assertEquals(expectedSet, commonInTop10); } +// @Test +// @Tag("SOLUTION") + public void lessThan30() + { + MutableList> bagsOfCandy = this.collectBagsOfCandy(); + + Bag bigBagOfCandy = null; + + String stringOfItemToCount = null; + + var expected = "{WHOPPERS=28, TWIX=26, NERDS=28, HERSHEYS_KISSES=24, SWEDISH_FISH=26}"; + Assertions.assertEquals(expected, stringOfItemToCount); + } + private MutableList> collectBagsOfCandy() { return SchoolGroup.all().collect(SchoolGroup::trickOrTreat).toList(); diff --git a/candy-kata/src/test/java/org/eclipse/collections/candykata/CandyKataTest.java b/candy-kata/src/test/java/org/eclipse/collections/candykata/CandyKataTest.java index 9b23ddc9..e2dced98 100644 --- a/candy-kata/src/test/java/org/eclipse/collections/candykata/CandyKataTest.java +++ b/candy-kata/src/test/java/org/eclipse/collections/candykata/CandyKataTest.java @@ -61,6 +61,27 @@ public void commonInTop10() Assertions.assertEquals(expectedSet, commonInTop10); } + @Test + @Tag("KATA") + public void lessThan30() + { + MutableList> bagsOfCandy = this.collectBagsOfCandy(); + + // Hint: Flatten the Bags of Candy into a single Bag + Bag 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() and sort the items in the bag + // before converting them to a string + // Uncomment the @Test and @Solution annotations before running the test + + String stringOfItemToCount = null; + + var expected = "{WHOPPERS=28, TWIX=26, NERDS=28, HERSHEYS_KISSES=24, SWEDISH_FISH=26}"; + Assertions.assertEquals(expected, stringOfItemToCount); + } + private MutableList> collectBagsOfCandy() { return SchoolGroup.all().collect(SchoolGroup::trickOrTreat).toList();