diff --git a/exercises/concept/gotta-snatch-em-all/.docs/instructions.md b/exercises/concept/gotta-snatch-em-all/.docs/instructions.md index 27cc340b8..f6e87ead7 100644 --- a/exercises/concept/gotta-snatch-em-all/.docs/instructions.md +++ b/exercises/concept/gotta-snatch-em-all/.docs/instructions.md @@ -42,8 +42,8 @@ collection.contains("Scientuna"); You really want your friends to join your Blorkemon™️ madness, so it's time to start trading! -Not every trade is worth doing, or can be done at all. -You cannot trade a card you don't have, and you shouldn't trade a card for one that you already have. +When trading with friends not every trade is worth doing, or can be done at all. +You should only trade if both you and your friend have a card the other does not have. Implement the `canTrade` method, that takes your current collection and the collection of one of your friends. It should return a `boolean` indicating whether a trade is possible, following the rules above. diff --git a/exercises/concept/gotta-snatch-em-all/.meta/src/reference/java/GottaSnatchEmAll.java b/exercises/concept/gotta-snatch-em-all/.meta/src/reference/java/GottaSnatchEmAll.java index 7e9429bae..cf6a3b428 100644 --- a/exercises/concept/gotta-snatch-em-all/.meta/src/reference/java/GottaSnatchEmAll.java +++ b/exercises/concept/gotta-snatch-em-all/.meta/src/reference/java/GottaSnatchEmAll.java @@ -13,9 +13,11 @@ static boolean addCard(String card, Set collection) { } static boolean canTrade(Set myCollection, Set theirCollection) { - Set cardsWorthTradingFor = new HashSet<>(theirCollection); - cardsWorthTradingFor.removeAll(myCollection); - return !myCollection.isEmpty() && !cardsWorthTradingFor.isEmpty(); + Set myUniqueCards = new HashSet<>(myCollection); + Set theirUniqueCards = new HashSet<>(theirCollection); + myUniqueCards.removeAll(theirCollection); + theirUniqueCards.removeAll(myCollection); + return !myUniqueCards.isEmpty() && !theirUniqueCards.isEmpty(); } static Set commonCards(List> collections) { diff --git a/exercises/concept/gotta-snatch-em-all/src/test/java/GottaSnatchEmAllTest.java b/exercises/concept/gotta-snatch-em-all/src/test/java/GottaSnatchEmAllTest.java index 100bbae2f..d2466e8a4 100644 --- a/exercises/concept/gotta-snatch-em-all/src/test/java/GottaSnatchEmAllTest.java +++ b/exercises/concept/gotta-snatch-em-all/src/test/java/GottaSnatchEmAllTest.java @@ -136,11 +136,11 @@ void testCanTradeBothCollectionsMixedCards() { @Test @Tag("task:3") - @DisplayName("canTrade returns true when my collection is a non-empty subset of their collection") + @DisplayName("canTrade returns false when my collection is a non-empty subset of their collection") void testCanTradeMyCollectionSubsetOfTheirCollection() { Set myCollection = new HashSet<>(Set.of("Gyros", "Garilord")); Set theirCollection = new HashSet<>(Set.of("Garilord", "Veevee", "Gyros")); - assertThat(GottaSnatchEmAll.canTrade(myCollection, theirCollection)).isTrue(); + assertThat(GottaSnatchEmAll.canTrade(myCollection, theirCollection)).isFalse(); } @Test