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 e2c4384..6988a42 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 @@ -11,6 +11,7 @@ package org.eclipse.collections.candykata; import org.eclipse.collections.api.bag.Bag; +import org.eclipse.collections.api.bag.sorted.SortedBag; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.primitive.ObjectIntPair; @@ -57,15 +58,20 @@ public void commonInTop10() Assertions.assertEquals(expectedSet, commonInTop10); } -// @Test -// @Tag("SOLUTION") + @Test + @Tag("SOLUTION") public void lessThan30() { MutableList> bagsOfCandy = this.collectBagsOfCandy(); Bag bigBagOfCandy = null; - String stringOfItemToCount = null; + bigBagOfCandy = bagsOfCandy.flatCollect(bag -> bag).toBag(); + + Bag filteredCandies = bigBagOfCandy.selectByOccurrences(i -> i < 30); + + SortedBag sortedCandies = filteredCandies.toSortedBag(); + String stringOfItemToCount = sortedCandies.toStringOfItemToCount(); var expected = "{WHOPPERS=28, TWIX=26, NERDS=28, HERSHEYS_KISSES=24, SWEDISH_FISH=26}"; Assertions.assertEquals(expected, stringOfItemToCount); 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 e2dced9..6bf68e9 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 @@ -16,10 +16,13 @@ import java.time.LocalTime; import java.time.Month; import java.time.ZoneId; +import java.util.Collection; import java.util.Random; import java.util.stream.IntStream; import org.eclipse.collections.api.bag.Bag; +import org.eclipse.collections.api.bag.sorted.SortedBag; +import org.eclipse.collections.api.factory.Bags; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.MutableSet; import org.eclipse.collections.api.tuple.primitive.ObjectIntPair; @@ -75,9 +78,7 @@ public void lessThan30() // 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); }