From 820bd59678e047563d39bd53ffdb3356d3434518 Mon Sep 17 00:00:00 2001 From: Jennifer Martinez <77757004+itsjenm@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:11:26 +0000 Subject: [PATCH 1/2] issue #356: Added solution to lessThan30() Test passed --- .../candykata/CandyKataSolutionsTest.java | 4 ++-- .../collections/candykata/CandyKataTest.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) 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..4f4d475 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,8 +57,8 @@ public void commonInTop10() Assertions.assertEquals(expectedSet, commonInTop10); } -// @Test -// @Tag("SOLUTION") + @Test + @Tag("SOLUTION") public void lessThan30() { MutableList> bagsOfCandy = this.collectBagsOfCandy(); 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..9ac542c 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; @@ -70,17 +73,22 @@ public void lessThan30() // Hint: Flatten the Bags of Candy into a single Bag Bag bigBagOfCandy = null; + bigBagOfCandy = bagsOfCandy.flatCollect(bag -> bag).toBag(); + // 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} + Bag filteredCandies = bigBagOfCandy.selectByOccurrences(i -> i < 30); + // Hint: use Bag#toStringOfItemToCount() and sort the items in the bag + SortedBag sortedCandies = filteredCandies.toSortedBag(); + String stringOfItemToCount = sortedCandies.toStringOfItemToCount(); + // 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() { From ddc91e36dca766f6bc43b4fcca5c299c45454dc1 Mon Sep 17 00:00:00 2001 From: Jennifer Martinez <77757004+itsjenm@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:13:03 +0000 Subject: [PATCH 2/2] changed placement of lessThan30() --- .../collections/candykata/CandyKataSolutionsTest.java | 8 +++++++- .../org/eclipse/collections/candykata/CandyKataTest.java | 9 +-------- 2 files changed, 8 insertions(+), 9 deletions(-) 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 4f4d475..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; @@ -65,7 +66,12 @@ public void lessThan30() 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 9ac542c..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 @@ -73,22 +73,15 @@ public void lessThan30() // Hint: Flatten the Bags of Candy into a single Bag Bag bigBagOfCandy = null; - bigBagOfCandy = bagsOfCandy.flatCollect(bag -> bag).toBag(); - // 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} - Bag filteredCandies = bigBagOfCandy.selectByOccurrences(i -> i < 30); - // Hint: use Bag#toStringOfItemToCount() and sort the items in the bag - SortedBag sortedCandies = filteredCandies.toSortedBag(); - String stringOfItemToCount = sortedCandies.toStringOfItemToCount(); - // 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() {