method2testcases
stringlengths
118
6.63k
### Question: GoogleGuavaDeckOfCardsAsSortedSet { public Multiset<Rank> countsByRank() { return null; } GoogleGuavaDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( Deque<Card> shuffled, int hands, int cardsPerHand); Set<Card> diamonds(); Set<Card> hearts(); Set<Card> spades(); Set<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals( this.jdkDeck.countsByRank().get(Rank.TEN).intValue(), this.ggDeck.countsByRank().count(Rank.NINE)); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableSortedSet<Card> getCards() { return this.cards; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(this.ecDeck.getCards(), this.jdkDeck.getCards()); } @Test public void cardsAreImmutable() { var ecCards = this.ecDeck.getCards().castToSortedSet(); Verify.assertThrows( UnsupportedOperationException.class, () -> ecCards.remove(null)); Verify.assertThrows( UnsupportedOperationException.class, ecCards::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> ecCards.add(null)); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableSortedSet<Card> diamonds() { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(this.ecDeck.diamonds(), this.jdkDeck.diamonds()); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableSortedSet<Card> hearts() { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(this.ecDeck.hearts(), this.jdkDeck.hearts()); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableSortedSet<Card> spades() { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(this.ecDeck.spades(), this.jdkDeck.spades()); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableSortedSet<Card> clubs() { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(this.ecDeck.clubs(), this.jdkDeck.clubs()); }
### Question: JDK8DeckOfCardsAsList { public List<Card> clubs() { return null; } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(this.jdk1Deck.clubs(), this.jdk2Deck.clubs()); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public MutableSet<Card> deal(MutableStack<Card> stack, int count) { return stack.pop(count).toSet(); } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void deal() { MutableStack<Card> ecShuffle = this.ecDeck.shuffle(new Random(1)); Deque<Card> jdkShuffle = this.jdkDeck.shuffle(new Random(1)); MutableSet<Card> ecHand = this.ecDeck.deal(ecShuffle, 5); Set<Card> jdkHand = this.jdkDeck.deal(jdkShuffle, 5); Assert.assertEquals(ecHand, jdkHand); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { MutableStack<Card> shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { ImmutableList<Set<Card>> ecHands = this.ecDeck.shuffleAndDeal(new Random(1), 5, 5); List<Set<Card>> jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(ecHands, jdkHands); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand) { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void dealHands() { MutableStack<Card> ecShuffled = this.ecDeck.shuffle(new Random(1)); Deque<Card> jdkShuffled = this.jdkDeck.shuffle(new Random(1)); ImmutableList<Set<Card>> ecHands = this.ecDeck.dealHands(ecShuffled, 5, 5); List<Set<Card>> jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); Assert.assertEquals(ecHands, jdkHands); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit() { return this.cardsBySuit; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { ImmutableSortedSetMultimap<Suit, Card> ecCardsBySuit = this.ecDeck.getCardsBySuit(); Map<Suit, SortedSet<Card>> jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); Assert.assertEquals(ecCardsBySuit.get(Suit.CLUBS), jdkCardsBySuit.get(Suit.CLUBS)); } @Test public void cardsBySuitIsImmutable() { var ecCardsBySuit = this.ecDeck.getCardsBySuit(); Verify.assertThrows( UnsupportedOperationException.class, () -> ecCardsBySuit.get(Suit.CLUBS).castToSortedSet().remove(null)); Verify.assertThrows( UnsupportedOperationException.class, () -> ecCardsBySuit.get(Suit.CLUBS).castToSortedSet().add(null)); Verify.assertThrows( UnsupportedOperationException.class, ecCardsBySuit.get(Suit.CLUBS).castToSortedSet()::clear); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public Bag<Suit> countsBySuit() { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals( this.jdkDeck.countsBySuit().get(Suit.CLUBS).intValue(), this.ecDeck.countsBySuit().occurrencesOf(Suit.CLUBS)); }
### Question: EclipseCollectionsDeckOfCardsAsSortedSet { public Bag<Rank> countsByRank() { return null; } EclipseCollectionsDeckOfCardsAsSortedSet(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableSortedSet<Card> diamonds(); ImmutableSortedSet<Card> hearts(); ImmutableSortedSet<Card> spades(); ImmutableSortedSet<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableSortedSet<Card> getCards(); ImmutableSortedSetMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals( this.jdkDeck.countsByRank().get(Rank.TEN).intValue(), this.ecDeck.countsByRank().occurrencesOf(Rank.SEVEN)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public SortedSet<Card> getCards() { return this.cards; } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(52, this.jdkDeck.getCards().size()); Assert.assertEquals(new Card(Rank.ACE, Suit.SPADES), this.jdkDeck.getCards().first()); Assert.assertEquals(new Card(Rank.KING, Suit.CLUBS), this.jdkDeck.getCards().last()); } @Test public void cardsAreImmutable() { var jdkCards = this.jdkDeck.getCards(); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCards.remove(null)); Verify.assertThrows( UnsupportedOperationException.class, jdkCards::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCards.add(null)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public SortedSet<Card> diamonds() { return this.cardsBySuit.get(Suit.DIAMONDS); } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(13, this.jdkDeck.diamonds().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.diamonds(), Card::isDiamonds)); }
### Question: JDK8DeckOfCardsAsList { public Set<Card> deal(Deque<Card> deque, int count) { var hand = new HashSet<Card>(); IntStream.range(0, count).forEach(i -> hand.add(deque.pop())); return hand; } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void deal() { var jdk1Shuffle = this.jdk1Deck.shuffle(new Random(1)); var jdk2Shuffle = this.jdk2Deck.shuffle(new Random(1)); var jdk1Hand = this.jdk1Deck.deal(jdk1Shuffle, 5); var jdk2Hand = this.jdk2Deck.deal(jdk2Shuffle, 5); Assert.assertEquals(jdk1Hand, jdk2Hand); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public SortedSet<Card> hearts() { return this.cardsBySuit.get(Suit.HEARTS); } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(13, this.jdkDeck.hearts().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.hearts(), Card::isHearts)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public SortedSet<Card> spades() { return this.cardsBySuit.get(Suit.SPADES); } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(13, this.jdkDeck.spades().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.spades(), Card::isSpades)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public SortedSet<Card> clubs() { return this.cardsBySuit.get(Suit.CLUBS); } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(13, this.jdkDeck.clubs().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.clubs(), Card::isClubs)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public Set<Card> deal(Deque<Card> deque, int count) { Set<Card> hand = new HashSet<>(); for (int i = 0; i < count; i++) { hand.add(deque.pop()); } return hand; } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void deal() { Deque<Card> jdkShuffle = this.jdkDeck.shuffle(new Random(1)); Set<Card> jdkHand = this.jdkDeck.deal(jdkShuffle, 5); Assert.assertEquals(5, jdkHand.size()); Assert.assertEquals(47, jdkShuffle.size()); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { Deque<Card> shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { List<Set<Card>> jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(5, jdkHands.size()); Assert.assertTrue(Iterate.allSatisfy(jdkHands, each -> each.size() == 5)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand) { List<Set<Card>> result = new ArrayList<>(); for (int i = 0; i < hands; i++) { result.add(this.deal(shuffled, cardsPerHand)); } return Collections.unmodifiableList(result); } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void dealHands() { Deque<Card> jdkShuffled = this.jdkDeck.shuffle(new Random(1)); List<Set<Card>> jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); Assert.assertEquals(5, jdkHands.size()); Assert.assertTrue(Iterate.allSatisfy(jdkHands, each -> each.size() == 5)); Assert.assertEquals(27, jdkShuffled.size()); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public Map<Suit, SortedSet<Card>> getCardsBySuit() { return this.cardsBySuit; } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { Map<Suit, SortedSet<Card>> jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); Assert.assertEquals(4, jdkCardsBySuit.size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.CLUBS).size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.DIAMONDS).size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.SPADES).size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.HEARTS).size()); } @Test public void cardsBySuitIsImmutable() { var jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCardsBySuit.remove(Suit.CLUBS)); Verify.assertThrows( UnsupportedOperationException.class, jdkCardsBySuit::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCardsBySuit.get(Suit.CLUBS).remove(null)); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCardsBySuit.get(Suit.CLUBS).add(null)); Verify.assertThrows( UnsupportedOperationException.class, jdkCardsBySuit.get(Suit.CLUBS)::clear); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public Map<Suit, Long> countsBySuit() { Map<Suit, Long> result = new HashMap<>(); for (Card card : this.cards) { Suit suit = card.suit(); Long value = result.get(suit); if (value == null) { value = Long.valueOf(0); } result.put(suit, value + 1); } return result; } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals(Long.valueOf(13), this.jdkDeck.countsBySuit().get(Suit.CLUBS)); }
### Question: JDKImperativeDeckOfCardsAsSortedSet { public Map<Rank, Long> countsByRank() { Map<Rank, Long> result = new HashMap<>(); for (Card card : this.cards) { Rank rank = card.rank(); Long value = result.get(rank); if (value == null) { value = Long.valueOf(0); } result.put(rank, value + 1); } return result; } JDKImperativeDeckOfCardsAsSortedSet(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); SortedSet<Card> diamonds(); SortedSet<Card> hearts(); SortedSet<Card> spades(); SortedSet<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); SortedSet<Card> getCards(); Map<Suit, SortedSet<Card>> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals(Long.valueOf(4), this.jdkDeck.countsByRank().get(Rank.TEN)); }
### Question: JDK8DeckOfCardsAsList { public List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { var jdk1Hands = this.jdk1Deck.shuffleAndDeal(new Random(1), 5, 5); var jdk2Hands = this.jdk2Deck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(jdk1Hands, jdk2Hands); }
### Question: DonutShop { public MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n) { return this.deliveries .flatCollect(Delivery::donuts) .countBy(Donut::type) .topOccurrences(n); } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getTop2Donuts() { var expected = Lists.mutable.empty() .with(pair(DonutType.BOSTON_CREAM, 15)) .with(pair(DonutType.GLAZED, 11)); Assert.assertEquals(expected, this.donutShop.getTopDonuts(2)); }
### Question: DonutShop { public double getTotalDeliveryValueFor(LocalDate date) { return this.deliveries .selectWith(Delivery::deliveredOn, date) .sumOfDouble(Delivery::getTotalPrice); } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void totalDeliveryValueByDate() { Assert.assertEquals( 9.45d, this.donutShop.getTotalDeliveryValueFor(this.today), 0.001); Assert.assertEquals( 12.0d, this.donutShop.getTotalDeliveryValueFor(this.tomorrow), 0.001); Assert.assertEquals( 20.9d, this.donutShop.getTotalDeliveryValueFor(this.yesterday), 0.001); }
### Question: DonutShop { public Customer getTopCustomer() { return this.customers.maxBy(Customer::getTotalDonutsOrdered); } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getTopCustomer() { Assert.assertEquals("Donnie Dapper", this.donutShop.getTopCustomer().name()); }
### Question: DonutShop { public Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered() { return this.customers.groupByEach(Customer::getDonutTypesOrdered); } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getCustomersByDonutTypesOrdered() { var multimap = this.donutShop.getCustomersByDonutTypesOrdered(); Assert.assertEquals(6, multimap.keySet().size()); Verify.assertIterableSize(1, multimap.get(DonutType.BAVARIAN_CREAM)); Verify.assertAllSatisfy( multimap.get(DonutType.BAVARIAN_CREAM), customer -> customer.named("Ted Smith")); }
### Question: DonutShop { public DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate) { return this.deliveries .select(each -> (each.deliveredOn(fromDate) || each.getDate().isAfter(fromDate))) .select(each -> (each.deliveredOn(toDate) || each.getDate().isBefore(toDate))) .flatCollect(Delivery::donuts) .summarizeDouble(Donut::price); } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getDonutPriceStatistics() { var stats1 = this.donutShop.getDonutPriceStatistics(this.today, this.today); Assert.assertEquals(9.45d, stats1.getSum(), 0.01); Assert.assertEquals(1.35d, stats1.getAverage(), 0.01); Assert.assertEquals(7, stats1.getCount(), 0.01); var stats2 = this.donutShop.getDonutPriceStatistics(this.tomorrow, this.tomorrow); Assert.assertEquals(12.0d, stats2.getSum(), 0.01); Assert.assertEquals(1.0d, stats2.getAverage(), 0.01); Assert.assertEquals(12, stats2.getCount(), 0.01); var stats3 = this.donutShop.getDonutPriceStatistics(this.yesterday, this.yesterday); Assert.assertEquals(20.9d, stats3.getSum(), 0.001); Assert.assertEquals(0.95d, stats3.getAverage(), 0.01); Assert.assertEquals(22, stats3.getCount(), 0.01); var statsTotal = this.donutShop.getDonutPriceStatistics(this.yesterday, this.tomorrow); Assert.assertEquals(42.35d, statsTotal.getSum(), 0.01); Assert.assertEquals(1.03d, statsTotal.getAverage(), 0.01); Assert.assertEquals(41, statsTotal.getCount(), 0.01); Assert.assertEquals(0.95, statsTotal.getMin(), 0.01); Assert.assertEquals(1.35, statsTotal.getMax(), 0.01); }
### Question: DonutShop { public MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n) { return null; } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getTop2Donuts() { var expected = Lists.mutable.empty() .with(pair(DonutType.BOSTON_CREAM, 15)) .with(pair(DonutType.GLAZED, 11)); Assert.assertEquals(expected, this.donutShop.getTopDonuts(2)); }
### Question: DonutShop { public double getTotalDeliveryValueFor(LocalDate date) { return 0.0d; } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void totalDeliveryValueByDate() { Assert.assertEquals( 9.45d, this.donutShop.getTotalDeliveryValueFor(this.today), 0.001); Assert.assertEquals( 12.0d, this.donutShop.getTotalDeliveryValueFor(this.tomorrow), 0.001); Assert.assertEquals( 20.9d, this.donutShop.getTotalDeliveryValueFor(this.yesterday), 0.001); }
### Question: DonutShop { public Customer getTopCustomer() { return null; } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getTopCustomer() { Assert.assertEquals("Donnie Dapper", this.donutShop.getTopCustomer().name()); }
### Question: DonutShop { public Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered() { return null; } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getCustomersByDonutTypesOrdered() { var multimap = this.donutShop.getCustomersByDonutTypesOrdered(); Assert.assertEquals(6, multimap.keySet().size()); Verify.assertIterableSize(1, multimap.get(DonutType.BAVARIAN_CREAM)); Verify.assertAllSatisfy( multimap.get(DonutType.BAVARIAN_CREAM), customer -> customer.named("Ted Smith")); }
### Question: DonutShop { public DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate) { return null; } void makeDonuts(DonutType type, int count); Delivery deliverOrder(String customerName, LocalDate date, String donutTypeCounts); Bag<DonutType> getDonuts(); MutableList<ObjectIntPair<DonutType>> getTopDonuts(int n); double getTotalDeliveryValueFor(LocalDate date); Customer getTopCustomer(); Multimap<DonutType, Customer> getCustomersByDonutTypesOrdered(); DoubleSummaryStatistics getDonutPriceStatistics(LocalDate fromDate, LocalDate toDate); @Override String toString(); }### Answer: @Test public void getDonutPriceStatistics() { var stats1 = this.donutShop.getDonutPriceStatistics(this.today, this.today); Assert.assertEquals(9.45d, stats1.getSum(), 0.01); Assert.assertEquals(1.35d, stats1.getAverage(), 0.01); Assert.assertEquals(7, stats1.getCount(), 0.01); var stats2 = this.donutShop.getDonutPriceStatistics(this.tomorrow, this.tomorrow); Assert.assertEquals(12.0d, stats2.getSum(), 0.01); Assert.assertEquals(1.0d, stats2.getAverage(), 0.01); Assert.assertEquals(12, stats2.getCount(), 0.01); var stats3 = this.donutShop.getDonutPriceStatistics(this.yesterday, this.yesterday); Assert.assertEquals(20.9d, stats3.getSum(), 0.001); Assert.assertEquals(0.95d, stats3.getAverage(), 0.01); Assert.assertEquals(22, stats3.getCount(), 0.01); var statsTotal = this.donutShop.getDonutPriceStatistics(this.yesterday, this.tomorrow); Assert.assertEquals(42.35d, statsTotal.getSum(), 0.01); Assert.assertEquals(1.03d, statsTotal.getAverage(), 0.01); Assert.assertEquals(41, statsTotal.getCount(), 0.01); Assert.assertEquals(0.95, statsTotal.getMin(), 0.01); Assert.assertEquals(1.35, statsTotal.getMax(), 0.01); }
### Question: JDK8DeckOfCardsAsList { public List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand) { return null; } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void dealHands() { var jdk1Shuffled = this.jdk1Deck.shuffle(new Random(1)); var jdk2Shuffled = this.jdk2Deck.shuffle(new Random(1)); var jdk1Hands = this.jdk1Deck.dealHands(jdk1Shuffled, 5, 5); var jdk2Hands = this.jdk2Deck.dealHands(jdk2Shuffled, 5, 5); Assert.assertEquals(jdk1Hands, jdk2Hands); }
### Question: MyCalendar { public boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration) { return false; } MyCalendar(TimeZone timezone); ZoneId getZoneId(); FullMonth getMeetingsForYearMonth(int year, Month month); SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date); WorkWeek getMeetingsForWorkWeekOf(LocalDate value); FullWeek getMeetingsForFullWeekOf(LocalDate value); boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration); boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration); MutableList<Interval> getAvailableTimeslots(LocalDate date); @Override String toString(); }### Answer: @Test public void hasOverlappingMeeting() { Assert.assertTrue(this.calendar.hasOverlappingMeeting( LocalDate.of(2017, 7, 7), LocalTime.NOON, Duration.ofHours(1))); }
### Question: MyCalendar { public SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date) { SortedSetIterable<Meeting> set = this.meetings.get(date); return set; } MyCalendar(TimeZone timezone); ZoneId getZoneId(); FullMonth getMeetingsForYearMonth(int year, Month month); SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date); WorkWeek getMeetingsForWorkWeekOf(LocalDate value); FullWeek getMeetingsForFullWeekOf(LocalDate value); boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration); boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration); MutableList<Interval> getAvailableTimeslots(LocalDate date); @Override String toString(); }### Answer: @Test public void getMeetingsForDate() { SortedSetIterable<Meeting> meetingsForJuly6 = this.calendar.getMeetingsForDate(LocalDate.of(2017, 7, 6)); Verify.assertSize(1, meetingsForJuly6); System.out.println(meetingsForJuly6); }
### Question: MyCalendar { public WorkWeek getMeetingsForWorkWeekOf(LocalDate value) { return new WorkWeek(value, this.meetings); } MyCalendar(TimeZone timezone); ZoneId getZoneId(); FullMonth getMeetingsForYearMonth(int year, Month month); SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date); WorkWeek getMeetingsForWorkWeekOf(LocalDate value); FullWeek getMeetingsForFullWeekOf(LocalDate value); boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration); boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration); MutableList<Interval> getAvailableTimeslots(LocalDate date); @Override String toString(); }### Answer: @Test public void getMeetingsForWorkWeekOf() { final WorkWeek week = this.calendar.getMeetingsForWorkWeekOf(LocalDate.of(2017, 7, 6)); Assert.assertEquals(4, week.getNumberOfMeetings()); System.out.println(week); }
### Question: MyCalendar { public FullWeek getMeetingsForFullWeekOf(LocalDate value) { return new FullWeek(value, this.meetings); } MyCalendar(TimeZone timezone); ZoneId getZoneId(); FullMonth getMeetingsForYearMonth(int year, Month month); SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date); WorkWeek getMeetingsForWorkWeekOf(LocalDate value); FullWeek getMeetingsForFullWeekOf(LocalDate value); boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration); boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration); MutableList<Interval> getAvailableTimeslots(LocalDate date); @Override String toString(); }### Answer: @Test public void getMeetingsForFullWeekOf() { final FullWeek week = this.calendar.getMeetingsForFullWeekOf(LocalDate.of(2017, 7, 6)); Assert.assertEquals(6, week.getNumberOfMeetings()); System.out.println(week); }
### Question: MyCalendar { public FullMonth getMeetingsForYearMonth(int year, Month month) { return new FullMonth(LocalDate.of(year, month, 1), this.meetings); } MyCalendar(TimeZone timezone); ZoneId getZoneId(); FullMonth getMeetingsForYearMonth(int year, Month month); SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date); WorkWeek getMeetingsForWorkWeekOf(LocalDate value); FullWeek getMeetingsForFullWeekOf(LocalDate value); boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration); boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration); MutableList<Interval> getAvailableTimeslots(LocalDate date); @Override String toString(); }### Answer: @Test public void getMeetingsForMonthOf() { FullMonth month = this.calendar.getMeetingsForYearMonth(2017, Month.JULY); Assert.assertEquals(6, month.getNumberOfMeetings()); System.out.println(month); }
### Question: MyCalendar { public MutableList<Interval> getAvailableTimeslots(LocalDate date) { return Lists.mutable.empty(); } MyCalendar(TimeZone timezone); ZoneId getZoneId(); FullMonth getMeetingsForYearMonth(int year, Month month); SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date); WorkWeek getMeetingsForWorkWeekOf(LocalDate value); FullWeek getMeetingsForFullWeekOf(LocalDate value); boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration); boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration); MutableList<Interval> getAvailableTimeslots(LocalDate date); @Override String toString(); }### Answer: @Test public void getAvailableTimeslots() { MutableList<Interval> availableTimeslots1 = this.calendar.getAvailableTimeslots(LocalDate.of(2017, 7, 6)); Assert.assertEquals(2, availableTimeslots1.size()); System.out.println(availableTimeslots1); MutableList<Interval> availableTimeslots2 = this.calendar.getAvailableTimeslots(LocalDate.of(2017, 7, 1)); Assert.assertEquals(1, availableTimeslots2.size()); System.out.println(availableTimeslots2); }
### Question: JDK8DeckOfCardsAsList { public Map<Suit, List<Card>> getCardsBySuit() { return this.cardsBySuit; } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { var jdk1CardsBySuit = this.jdk1Deck.getCardsBySuit(); var jdk2CardsBySuit = this.jdk2Deck.getCardsBySuit(); Assert.assertEquals(jdk1CardsBySuit.get(Suit.CLUBS), jdk2CardsBySuit.get(Suit.CLUBS)); } @Test public void cardsBySuitIsImmutable() { var jdk2CardsBySuit = this.jdk2Deck.getCardsBySuit(); Verify.assertThrows( UnsupportedOperationException.class, () -> jdk2CardsBySuit.remove(Suit.CLUBS)); Verify.assertThrows( UnsupportedOperationException.class, jdk2CardsBySuit::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> jdk2CardsBySuit.get(Suit.CLUBS).remove(0)); Verify.assertThrows( UnsupportedOperationException.class, () -> jdk2CardsBySuit.get(Suit.CLUBS).add(null)); Verify.assertThrows( UnsupportedOperationException.class, jdk2CardsBySuit.get(Suit.CLUBS)::clear); }
### Question: JDK8DeckOfCardsAsList { public Map<Suit, Long> countsBySuit() { return null; } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals( this.jdk1Deck.countsBySuit().get(Suit.CLUBS), this.jdk2Deck.countsBySuit().get(Suit.CLUBS)); }
### Question: JDK8DeckOfCardsAsList { public Map<Rank, Long> countsByRank() { return null; } JDK8DeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals( this.jdk1Deck.countsByRank().get(Rank.TEN), this.jdk2Deck.countsByRank().get(Rank.TEN)); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Card> getCards() { return this.cards; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(this.jdkDeck.getCards(), this.acDeck.getCards()); } @Test public void cardsAreImmutable() { var acCards = this.acDeck.getCards(); Verify.assertThrows( UnsupportedOperationException.class, () -> acCards.remove(0)); Verify.assertThrows( UnsupportedOperationException.class, acCards::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> acCards.add(null)); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Card> diamonds() { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(this.jdkDeck.diamonds(), this.acDeck.diamonds()); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Card> hearts() { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(this.jdkDeck.hearts(), this.acDeck.hearts()); }
### Question: EclipseCollectionsDeckOfCardsAsList { public ImmutableList<Card> diamonds() { return null; } EclipseCollectionsDeckOfCardsAsList(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(this.jdkDeck.diamonds(), this.ecDeck.diamonds()); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Card> spades() { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(this.jdkDeck.spades(), this.acDeck.spades()); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Card> clubs() { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(this.jdkDeck.clubs(), this.acDeck.clubs()); }
### Question: ApacheCommonsDeckOfCardsAsList { public Set<Card> deal(Deque<Card> deque, int count) { var hand = new HashSet<Card>(); IntStream.range(0, count).forEach(i -> hand.add(deque.pop())); return hand; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void deal() { var jdkShuffle = this.jdkDeck.shuffle(new Random(1)); var acShuffle = this.acDeck.shuffle(new Random(1)); var jdkHand = this.jdkDeck.deal(jdkShuffle, 5); var acHand = this.acDeck.deal(acShuffle, 5); Assert.assertEquals(jdkHand, acHand); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { var jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); var acHands = this.acDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(jdkHands, acHands); }
### Question: ApacheCommonsDeckOfCardsAsList { public List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand) { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void dealHands() { var jdkShuffled = this.jdkDeck.shuffle(new Random(1)); var acShuffled = this.acDeck.shuffle(new Random(1)); var jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); var acHands = this.acDeck.dealHands(acShuffled, 5, 5); Assert.assertEquals(jdkHands, acHands); }
### Question: ApacheCommonsDeckOfCardsAsList { public MultiValuedMap<Suit, Card> getCardsBySuit() { return this.cardsBySuit; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { var jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); var acCardsBySuit = this.acDeck.getCardsBySuit(); Assert.assertEquals(jdkCardsBySuit.get(Suit.CLUBS), new ArrayList<>(acCardsBySuit.get(Suit.CLUBS))); } @Test public void cardsBySuitIsImmutable() { var acCardsBySuit = this.acDeck.getCardsBySuit(); Verify.assertThrows( UnsupportedOperationException.class, () -> acCardsBySuit.remove(Suit.CLUBS)); Verify.assertThrows( UnsupportedOperationException.class, acCardsBySuit::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> acCardsBySuit.get(Suit.CLUBS).remove(0)); Verify.assertThrows( UnsupportedOperationException.class, () -> acCardsBySuit.get(Suit.CLUBS).add(null)); Verify.assertThrows( UnsupportedOperationException.class, acCardsBySuit.get(Suit.CLUBS)::clear); }
### Question: ApacheCommonsDeckOfCardsAsList { public Bag<Suit> countsBySuit() { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals( this.jdkDeck.countsBySuit().get(Suit.CLUBS).intValue(), this.acDeck.countsBySuit().getCount(Suit.CLUBS)); }
### Question: ApacheCommonsDeckOfCardsAsList { public MultiSet<Rank> countsByRank() { return null; } ApacheCommonsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Bag<Suit> countsBySuit(); MultiSet<Rank> countsByRank(); List<Card> getCards(); MultiValuedMap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals( this.jdkDeck.countsByRank().get(Rank.TEN).intValue(), this.acDeck.countsByRank().getCount(Rank.EIGHT)); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Card> getCards() { return this.cards; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(this.jdkDeck.getCards(), this.ggDeck.getCards()); } @Test public void cardsAreImmutable() { var ggCards = this.ggDeck.getCards(); Verify.assertThrows( UnsupportedOperationException.class, () -> ggCards.remove(0)); Verify.assertThrows( UnsupportedOperationException.class, ggCards::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> ggCards.add(null)); }
### Question: EclipseCollectionsDeckOfCardsAsList { public ImmutableList<Card> hearts() { return null; } EclipseCollectionsDeckOfCardsAsList(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(this.jdkDeck.hearts(), this.ecDeck.hearts()); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Card> diamonds() { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(this.jdkDeck.diamonds(), this.ggDeck.diamonds()); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Card> hearts() { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(this.jdkDeck.hearts(), this.ggDeck.hearts()); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Card> spades() { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(this.jdkDeck.spades(), this.ggDeck.spades()); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Card> clubs() { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(this.jdkDeck.clubs(), this.ggDeck.clubs()); }
### Question: GoogleGuavaDeckOfCardsAsList { public Set<Card> deal(Deque<Card> deque, int count) { var hand = new HashSet<Card>(); IntStream.range(0, count).forEach(i -> hand.add(deque.pop())); return hand; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void deal() { var jdkShuffle = this.jdkDeck.shuffle(new Random(1)); var ggShuffle = this.ggDeck.shuffle(new Random(1)); var jdkHand = this.jdkDeck.deal(jdkShuffle, 5); var ggHand = this.ggDeck.deal(ggShuffle, 5); Assert.assertEquals(jdkHand, ggHand); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { var jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); var ggHands = this.ggDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(jdkHands, ggHands); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand) { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void dealHands() { var jdkShuffled = this.jdkDeck.shuffle(new Random(1)); var ggShuffled = this.ggDeck.shuffle(new Random(1)); var jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); var ggHands = this.ggDeck.dealHands(ggShuffled, 5, 5); Assert.assertEquals(jdkHands, ggHands); }
### Question: GoogleGuavaDeckOfCardsAsList { public ImmutableListMultimap<Suit, Card> getCardsBySuit() { return this.cardsBySuit; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { var jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); var ggCardsBySuit = this.ggDeck.getCardsBySuit(); Assert.assertEquals(jdkCardsBySuit.get(Suit.CLUBS), ggCardsBySuit.get(Suit.CLUBS)); } @Test public void cardsBySuitIsImmutable() { var ggCardsBySuit = this.ggDeck.getCardsBySuit(); Verify.assertThrows( UnsupportedOperationException.class, () -> ggCardsBySuit.removeAll(Suit.CLUBS)); Verify.assertThrows( UnsupportedOperationException.class, ggCardsBySuit::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> ggCardsBySuit.get(Suit.CLUBS).remove(0)); Verify.assertThrows( UnsupportedOperationException.class, () -> ggCardsBySuit.get(Suit.CLUBS).add(null)); Verify.assertThrows( UnsupportedOperationException.class, ggCardsBySuit.get(Suit.CLUBS)::clear); }
### Question: EclipseCollectionsDeckOfCardsAsList { public ImmutableList<Card> spades() { return null; } EclipseCollectionsDeckOfCardsAsList(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(this.jdkDeck.spades(), this.ecDeck.spades()); }
### Question: GoogleGuavaDeckOfCardsAsList { public Multiset<Suit> countsBySuit() { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals( this.jdkDeck.countsBySuit().get(Suit.CLUBS).intValue(), this.ggDeck.countsBySuit().count(Suit.CLUBS)); }
### Question: GoogleGuavaDeckOfCardsAsList { public Multiset<Rank> countsByRank() { return null; } GoogleGuavaDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Multiset<Suit> countsBySuit(); Multiset<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals( this.jdkDeck.countsByRank().get(Rank.TEN).intValue(), this.ggDeck.countsByRank().count(Rank.NINE)); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Card> getCards() { return this.cards; } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(52, this.jdkDeck.getCards().size()); Assert.assertEquals(new Card(Rank.ACE, Suit.SPADES), this.jdkDeck.getCards().get(0)); Assert.assertEquals(new Card(Rank.KING, Suit.CLUBS), this.jdkDeck.getCards().get(51)); } @Test public void cardsAreImmutable() { var jdkCards = this.jdkDeck.getCards(); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCards.remove(0)); Verify.assertThrows( UnsupportedOperationException.class, jdkCards::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCards.add(null)); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Card> diamonds() { return this.cardsBySuit.get(Suit.DIAMONDS); } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(13, this.jdkDeck.diamonds().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.diamonds(), Card::isDiamonds)); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Card> hearts() { return this.cardsBySuit.get(Suit.HEARTS); } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(13, this.jdkDeck.hearts().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.hearts(), Card::isHearts)); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Card> spades() { return this.cardsBySuit.get(Suit.SPADES); } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(13, this.jdkDeck.spades().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.spades(), Card::isSpades)); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Card> clubs() { return this.cardsBySuit.get(Suit.CLUBS); } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(13, this.jdkDeck.clubs().size()); Assert.assertTrue(Iterate.allSatisfy(this.jdkDeck.clubs(), Card::isClubs)); }
### Question: JDKImperativeDeckOfCardsAsList { public Set<Card> deal(Deque<Card> deque, int count) { var hand = new HashSet<Card>(); for (int i = 0; i < count; i++) { hand.add(deque.pop()); } return hand; } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void deal() { var jdkShuffle = this.jdkDeck.shuffle(new Random(1)); var jdkHand = this.jdkDeck.deal(jdkShuffle, 5); Assert.assertEquals(5, jdkHand.size()); Assert.assertEquals(47, jdkShuffle.size()); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { var jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(5, jdkHands.size()); Assert.assertTrue(Iterate.allSatisfy(jdkHands, each -> each.size() == 5)); }
### Question: EclipseCollectionsDeckOfCardsAsList { public ImmutableList<Card> clubs() { return null; } EclipseCollectionsDeckOfCardsAsList(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(this.jdkDeck.clubs(), this.ecDeck.clubs()); }
### Question: JDKImperativeDeckOfCardsAsList { public List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand) { var result = new ArrayList<Set<Card>>(); for (int i = 0; i < hands; i++) { result.add(this.deal(shuffled, cardsPerHand)); } return List.copyOf(result); } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void dealHands() { var jdkShuffled = this.jdkDeck.shuffle(new Random(1)); var jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); Assert.assertEquals(5, jdkHands.size()); Assert.assertTrue(Iterate.allSatisfy(jdkHands, each -> each.size() == 5)); Assert.assertEquals(27, jdkShuffled.size()); }
### Question: JDKImperativeDeckOfCardsAsList { public Map<Suit, List<Card>> getCardsBySuit() { return this.cardsBySuit; } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { var jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); Assert.assertEquals(4, jdkCardsBySuit.size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.CLUBS).size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.DIAMONDS).size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.SPADES).size()); Assert.assertEquals(13, jdkCardsBySuit.get(Suit.HEARTS).size()); } @Test public void cardsBySuitIsImmutable() { var jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCardsBySuit.remove(Suit.CLUBS)); Verify.assertThrows( UnsupportedOperationException.class, jdkCardsBySuit::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCardsBySuit.get(Suit.CLUBS).remove(0)); Verify.assertThrows( UnsupportedOperationException.class, () -> jdkCardsBySuit.get(Suit.CLUBS).add(null)); Verify.assertThrows( UnsupportedOperationException.class, jdkCardsBySuit.get(Suit.CLUBS)::clear); }
### Question: JDKImperativeDeckOfCardsAsList { public Map<Suit, Long> countsBySuit() { var result = new HashMap<Suit, Long>(); for (var card : this.cards) { var suit = card.suit(); var value = result.computeIfAbsent(suit, s -> Long.valueOf(0)); result.put(suit, value + 1); } return result; } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals(Long.valueOf(13), this.jdkDeck.countsBySuit().get(Suit.CLUBS)); }
### Question: JDKImperativeDeckOfCardsAsList { public Map<Rank, Long> countsByRank() { var result = new HashMap<Rank, Long>(); for (var card : this.cards) { var rank = card.rank(); var value = result.computeIfAbsent(rank, r -> Long.valueOf(0)); result.put(rank, value + 1); } return result; } JDKImperativeDeckOfCardsAsList(); Deque<Card> shuffle(Random random); Set<Card> deal(Deque<Card> deque, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, List<Card>> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals(Long.valueOf(4), this.jdkDeck.countsByRank().get(Rank.TEN)); }
### Question: VavrDeckOfCardsAsList { public List<Card> getCards() { return this.cards; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(this.jdkDeck.getCards(), this.vavrDeck.getCards().toJavaList()); }
### Question: VavrDeckOfCardsAsList { public List<Card> diamonds() { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(this.jdkDeck.diamonds(), this.vavrDeck.diamonds().toJavaList()); }
### Question: VavrDeckOfCardsAsList { public List<Card> hearts() { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(this.jdkDeck.hearts(), this.vavrDeck.hearts().toJavaList()); }
### Question: VavrDeckOfCardsAsList { public List<Card> spades() { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void spades() { Assert.assertEquals(this.jdkDeck.spades(), this.vavrDeck.spades().toJavaList()); }
### Question: VavrDeckOfCardsAsList { public List<Card> clubs() { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void clubs() { Assert.assertEquals(this.jdkDeck.clubs(), this.vavrDeck.clubs().toJavaList()); }
### Question: EclipseCollectionsDeckOfCardsAsList { public MutableSet<Card> deal(MutableStack<Card> stack, int count) { return stack.pop(count).toSet(); } EclipseCollectionsDeckOfCardsAsList(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void deal() { var ecShuffle = this.ecDeck.shuffle(new Random(1)); var jdkShuffle = this.jdkDeck.shuffle(new Random(1)); var ecHand = this.ecDeck.deal(ecShuffle, 5); var jdkHand = this.jdkDeck.deal(jdkShuffle, 5); Assert.assertEquals(jdkHand, ecHand); }
### Question: VavrDeckOfCardsAsList { public Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count) { var hand = HashSet.<Card>empty(); for (int i = 0; i < count; i++) { var cardTuple2 = stack.pop2(); stack = cardTuple2._2(); hand = hand.add(cardTuple2._1()); } return Tuple.of(hand, stack); } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void deal() { var jdkShuffle = this.jdkDeck.shuffle(new Random(1)); var vavrShuffle = this.vavrDeck.shuffle(new Random(1)); var jdkHand = this.jdkDeck.deal(jdkShuffle, 5); var vavrHand = this.vavrDeck.deal(vavrShuffle, 5)._1().toJavaSet(); Assert.assertEquals(jdkHand, vavrHand); }
### Question: VavrDeckOfCardsAsList { public List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { var jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); var vavrHands = this.vavrDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(jdkHands.get(0), vavrHands.get(0).toJavaSet()); Assert.assertEquals(jdkHands.get(1), vavrHands.get(1).toJavaSet()); Assert.assertEquals(jdkHands.get(2), vavrHands.get(2).toJavaSet()); Assert.assertEquals(jdkHands.get(3), vavrHands.get(3).toJavaSet()); Assert.assertEquals(jdkHands.get(4), vavrHands.get(4).toJavaSet()); }
### Question: VavrDeckOfCardsAsList { public List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand) { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void dealHands() { var jdkShuffled = this.jdkDeck.shuffle(new Random(1)); var vavrShuffled = this.vavrDeck.shuffle(new Random(1)); var jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); var vavrHands = this.vavrDeck.dealHands(vavrShuffled, 5, 5); Assert.assertEquals(jdkHands.get(0), vavrHands.get(0).toJavaSet()); Assert.assertEquals(jdkHands.get(1), vavrHands.get(1).toJavaSet()); Assert.assertEquals(jdkHands.get(2), vavrHands.get(2).toJavaSet()); Assert.assertEquals(jdkHands.get(3), vavrHands.get(3).toJavaSet()); Assert.assertEquals(jdkHands.get(4), vavrHands.get(4).toJavaSet()); }
### Question: VavrDeckOfCardsAsList { public Map<Suit, ? extends List<Card>> getCardsBySuit() { return this.cardsBySuit; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void cardsBySuit() { var jdkCardsBySuit = this.jdkDeck.getCardsBySuit(); var vavrCardsBySuit = this.vavrDeck.getCardsBySuit(); Assert.assertEquals(jdkCardsBySuit.get(Suit.CLUBS), vavrCardsBySuit.get(Suit.CLUBS).get().toJavaList()); }
### Question: VavrDeckOfCardsAsList { public Map<Suit, Long> countsBySuit() { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void countsBySuit() { Assert.assertEquals( this.jdkDeck.countsBySuit().get(Suit.CLUBS), this.vavrDeck.countsBySuit().get(Suit.CLUBS).get()); }
### Question: VavrDeckOfCardsAsList { public Map<Rank, Long> countsByRank() { return null; } VavrDeckOfCardsAsList(); List<Card> shuffle(Random random); Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count); List<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); List<Set<Card>> dealHands( List<Card> shuffled, int hands, int cardsPerHand); List<Card> diamonds(); List<Card> hearts(); List<Card> spades(); List<Card> clubs(); Map<Suit, Long> countsBySuit(); Map<Rank, Long> countsByRank(); List<Card> getCards(); Map<Suit, ? extends List<Card>> getCardsBySuit(); }### Answer: @Test public void countsByRank() { Assert.assertEquals( this.jdkDeck.countsByRank().get(Rank.TEN), this.vavrDeck.countsByRank().get(Rank.TEN).get()); }
### Question: EclipseCollectionsDeckOfCardsAsList { public ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } EclipseCollectionsDeckOfCardsAsList(); MutableStack<Card> shuffle(Random random); MutableSet<Card> deal(MutableStack<Card> stack, int count); ImmutableList<Set<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand); ImmutableList<Card> diamonds(); ImmutableList<Card> hearts(); ImmutableList<Card> spades(); ImmutableList<Card> clubs(); Bag<Suit> countsBySuit(); Bag<Rank> countsByRank(); ImmutableList<Card> getCards(); ImmutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void shuffleAndDealHands() { var ecHands = this.ecDeck.shuffleAndDeal(new Random(1), 5, 5); var jdkHands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(jdkHands, ecHands); }
### Question: HashSetMultimap extends AbstractMutableMultimap<K, V, MutableSet<V>> implements MutableSetMultimap<K, V> { public static <K, V> HashSetMultimap<K, V> newMultimap() { return new HashSetMultimap<>(); } static HashSetMultimap<K, V> newMultimap(); @Override int size(); }### Answer: @Test public void hashCodeEquals() { this.testObj.putAll(MutableMap.of("A", MutableList.of(1, 2, 3, 1))); this.testObj.putAll(MutableMap.of("B", MutableList.of(10, 10))); HashSetMultimap<String, Integer> other = HashSetMultimap.newMultimap(); other.putAll(MutableMap.of("A", MutableList.of(1, 2, 3, 1))); Assert.assertTrue(this.testObj.equals(this.testObj)); Assert.assertFalse(this.testObj.equals(other)); Assert.assertFalse(other.equals(this.testObj)); other.putAll(MutableMap.of("B", MutableList.of(10, 10))); Verify.assertEqualsAndHashCode(this.testObj, this.testObj); Verify.assertEqualsAndHashCode(this.testObj, other); Verify.assertEqualsAndHashCode(other, this.testObj); }
### Question: CustomCollectionsDeckOfCardsAsList { public MutableList<Card> getCards() { return this.cards; } CustomCollectionsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); MutableSet<Card> deal(Deque<Card> deque, int count); MutableList<MutableSet<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); MutableList<MutableSet<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); MutableList<Card> diamonds(); MutableList<Card> hearts(); MutableList<Card> spades(); MutableList<Card> clubs(); MutableBag<Suit> countsBySuit(); MutableBag<Rank> countsByRank(); MutableList<Card> getCards(); MutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void allCards() { Assert.assertEquals(this.jdkDeck.getCards(), this.customDeck.getCards()); } @Test public void cardsAreImmutable() { var jdk2Cards = this.customDeck.getCards(); Verify.assertThrows( UnsupportedOperationException.class, () -> jdk2Cards.remove(0)); Verify.assertThrows( UnsupportedOperationException.class, jdk2Cards::clear); Verify.assertThrows( UnsupportedOperationException.class, () -> jdk2Cards.add(null)); }
### Question: CustomCollectionsDeckOfCardsAsList { public MutableList<Card> diamonds() { return this.cardsBySuit.get(Suit.DIAMONDS); } CustomCollectionsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); MutableSet<Card> deal(Deque<Card> deque, int count); MutableList<MutableSet<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); MutableList<MutableSet<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); MutableList<Card> diamonds(); MutableList<Card> hearts(); MutableList<Card> spades(); MutableList<Card> clubs(); MutableBag<Suit> countsBySuit(); MutableBag<Rank> countsByRank(); MutableList<Card> getCards(); MutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void diamonds() { Assert.assertEquals(this.jdkDeck.diamonds(), this.customDeck.diamonds()); }
### Question: CustomCollectionsDeckOfCardsAsList { public MutableList<Card> hearts() { return this.cardsBySuit.get(Suit.HEARTS); } CustomCollectionsDeckOfCardsAsList(); Deque<Card> shuffle(Random random); MutableSet<Card> deal(Deque<Card> deque, int count); MutableList<MutableSet<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand); MutableList<MutableSet<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand); MutableList<Card> diamonds(); MutableList<Card> hearts(); MutableList<Card> spades(); MutableList<Card> clubs(); MutableBag<Suit> countsBySuit(); MutableBag<Rank> countsByRank(); MutableList<Card> getCards(); MutableListMultimap<Suit, Card> getCardsBySuit(); }### Answer: @Test public void hearts() { Assert.assertEquals(this.jdkDeck.hearts(), this.customDeck.hearts()); }