Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exercises/concept/gotta-snatch-em-all/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ static boolean addCard(String card, Set<String> collection) {
}

static boolean canTrade(Set<String> myCollection, Set<String> theirCollection) {
Set<String> cardsWorthTradingFor = new HashSet<>(theirCollection);
cardsWorthTradingFor.removeAll(myCollection);
return !myCollection.isEmpty() && !cardsWorthTradingFor.isEmpty();
Set<String> myUniqueCards = new HashSet<>(myCollection);
Set<String> theirUniqueCards = new HashSet<>(theirCollection);
myUniqueCards.removeAll(theirCollection);
theirUniqueCards.removeAll(myCollection);
return !myUniqueCards.isEmpty() && !theirUniqueCards.isEmpty();
}

static Set<String> commonCards(List<Set<String>> collections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> myCollection = new HashSet<>(Set.of("Gyros", "Garilord"));
Set<String> theirCollection = new HashSet<>(Set.of("Garilord", "Veevee", "Gyros"));
assertThat(GottaSnatchEmAll.canTrade(myCollection, theirCollection)).isTrue();
assertThat(GottaSnatchEmAll.canTrade(myCollection, theirCollection)).isFalse();
}

@Test
Expand Down