method2testcases
stringlengths 118
3.08k
|
---|
### 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 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, 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 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:
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, 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:
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, 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()); } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableList<Card> spades() { return this.cardsBySuit.get(Suit.SPADES); } 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 spades() { Assert.assertEquals(this.jdkDeck.spades(), this.customDeck.spades()); } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableList<Card> clubs() { return this.cardsBySuit.get(Suit.CLUBS); } 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 clubs() { Assert.assertEquals(this.jdkDeck.clubs(), this.customDeck.clubs()); } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableSet<Card> deal(Deque<Card> deque, int count) { var hand = MutableSet.<Card>empty(); IntStream.range(0, count).forEach(i -> hand.add(deque.pop())); return hand; } 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 deal() { var jdk1Shuffle = this.jdkDeck.shuffle(new Random(1)); var jdk2Shuffle = this.customDeck.shuffle(new Random(1)); var jdk1Hand = this.jdkDeck.deal(jdk1Shuffle, 5); var jdk2Hand = this.customDeck.deal(jdk2Shuffle, 5); Assert.assertEquals(jdk1Hand, jdk2Hand); } |
### Question:
EclipseCollectionsDeckOfCardsAsList { public ImmutableList<Set<Card>> dealHands( MutableStack<Card> shuffled, int hands, int cardsPerHand) { 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 dealHands() { var ecShuffled = this.ecDeck.shuffle(new Random(1)); var jdkShuffled = this.jdkDeck.shuffle(new Random(1)); var ecHands = this.ecDeck.dealHands(ecShuffled, 5, 5); var jdkHands = this.jdkDeck.dealHands(jdkShuffled, 5, 5); Assert.assertEquals(jdkHands, ecHands); } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableList<MutableSet<Card>> shuffleAndDeal(Random random, int hands, int cardsPerHand) { var shuffled = this.shuffle(random); return this.dealHands(shuffled, hands, cardsPerHand); } 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 shuffleAndDealHands() { var jdk1Hands = this.jdkDeck.shuffleAndDeal(new Random(1), 5, 5); var jdk2Hands = this.customDeck.shuffleAndDeal(new Random(1), 5, 5); Assert.assertEquals(jdk1Hands, jdk2Hands); } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableList<MutableSet<Card>> dealHands(Deque<Card> shuffled, int hands, int cardsPerHand) { return MutableList.fromStream(IntStream.range(0, hands) .mapToObj(each -> this.deal(shuffled, cardsPerHand))) .asUnmodifiable(); } 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 dealHands() { var jdk1Shuffled = this.jdkDeck.shuffle(new Random(1)); var jdk2Shuffled = this.customDeck.shuffle(new Random(1)); var jdk1Hands = this.jdkDeck.dealHands(jdk1Shuffled, 5, 5); var jdk2Hands = this.customDeck.dealHands(jdk2Shuffled, 5, 5); Assert.assertEquals(jdk1Hands, jdk2Hands); } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableBag<Suit> countsBySuit() { return this.cards.countBy(Card::suit); } 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 countsBySuit() { for (Suit suit : Suit.values()) { Assert.assertEquals( this.jdkDeck.countsBySuit().get(suit).intValue(), this.customDeck.countsBySuit().getOccurrences(suit)); } } |
### Question:
CustomCollectionsDeckOfCardsAsList { public MutableBag<Rank> countsByRank() { return this.cards.countBy(Card::rank); } 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 countsByRank() { for (Rank rank : Rank.values()) { Assert.assertEquals( this.jdkDeck.countsByRank().get(rank).intValue(), this.customDeck.countsByRank().getOccurrences(rank)); } } |
### Question:
HashBag implements MutableBag<T> { HashBag<T> withAll(T... elements) { for (T element : elements) { this.backingMap.merge(element, 1, (existingValue, newValue) -> existingValue + 1); this.size++; } return this; } @Override int sizeDistinct(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); void forEachWithIndex(BiConsumer<? super T, Integer> biConsumer); @Override T1[] toArray(T1[] array); @Override boolean add(T element); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override void clear(); @Override Iterator<T> iterator(); @Override int getOccurrences(T element); @Override boolean addOccurrence(T element); @Override boolean addOccurrences(T element, int occurrences); @Override boolean removeOccurrence(T element); @Override boolean removeOccurrences(T element, int occurrences); @Override void forEachWithOccurrences(BiConsumer<? super T, Integer> biConsumer); @Override void forEach(Consumer<? super T> consumer); @Override int hashCode(); @Override boolean equals(Object other); }### Answer:
@Test public void withAll() { HashBag<String> bag = this.testObj.withAll("1", "2", "3", "2", "3", "3"); Assert.assertEquals(1, bag.getOccurrences("1")); Assert.assertEquals(2, bag.getOccurrences("2")); Assert.assertEquals(3, bag.getOccurrences("3")); } |
### Question:
HashBag implements MutableBag<T> { @Override public boolean isEmpty() { return this.size == 0; } @Override int sizeDistinct(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); void forEachWithIndex(BiConsumer<? super T, Integer> biConsumer); @Override T1[] toArray(T1[] array); @Override boolean add(T element); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override void clear(); @Override Iterator<T> iterator(); @Override int getOccurrences(T element); @Override boolean addOccurrence(T element); @Override boolean addOccurrences(T element, int occurrences); @Override boolean removeOccurrence(T element); @Override boolean removeOccurrences(T element, int occurrences); @Override void forEachWithOccurrences(BiConsumer<? super T, Integer> biConsumer); @Override void forEach(Consumer<? super T> consumer); @Override int hashCode(); @Override boolean equals(Object other); }### Answer:
@Test public void isEmpty() { Assert.assertTrue(this.testObj.isEmpty()); this.testObj.withAll("1", "2", "3", "2", "3", "3"); Assert.assertFalse(this.testObj.isEmpty()); } |
### Question:
HashBag implements MutableBag<T> { @Override public boolean contains(Object o) { return this.backingMap.containsKey(o); } @Override int sizeDistinct(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); void forEachWithIndex(BiConsumer<? super T, Integer> biConsumer); @Override T1[] toArray(T1[] array); @Override boolean add(T element); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override void clear(); @Override Iterator<T> iterator(); @Override int getOccurrences(T element); @Override boolean addOccurrence(T element); @Override boolean addOccurrences(T element, int occurrences); @Override boolean removeOccurrence(T element); @Override boolean removeOccurrences(T element, int occurrences); @Override void forEachWithOccurrences(BiConsumer<? super T, Integer> biConsumer); @Override void forEach(Consumer<? super T> consumer); @Override int hashCode(); @Override boolean equals(Object other); }### Answer:
@Test public void contains() { Assert.assertFalse(this.testObj.contains("1")); this.testObj.withAll("1", "2", "3", "2", "3", "3"); Assert.assertTrue(this.testObj.contains("1")); Assert.assertFalse(this.testObj.contains("4")); } |
### Question:
HashBag implements MutableBag<T> { @Override public Object[] toArray() { Object[] result = new Object[this.size()]; this.forEachWithIndex((each, index) -> result[index] = each); return result; } @Override int sizeDistinct(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); void forEachWithIndex(BiConsumer<? super T, Integer> biConsumer); @Override T1[] toArray(T1[] array); @Override boolean add(T element); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override void clear(); @Override Iterator<T> iterator(); @Override int getOccurrences(T element); @Override boolean addOccurrence(T element); @Override boolean addOccurrences(T element, int occurrences); @Override boolean removeOccurrence(T element); @Override boolean removeOccurrences(T element, int occurrences); @Override void forEachWithOccurrences(BiConsumer<? super T, Integer> biConsumer); @Override void forEach(Consumer<? super T> consumer); @Override int hashCode(); @Override boolean equals(Object other); }### Answer:
@Test public void toArray() { Assert.assertArrayEquals(new String[]{}, this.testObj.toArray()); this.testObj.withAll("1", "2", "3", "2", "3", "3"); Assert.assertArrayEquals(new String[]{"1", "2", "2", "3", "3", "3"}, this.testObj.toArray()); } |
### Question:
DimeServiceAdapter extends ServiceAdapterBase implements InternalServiceAdapter { @Override public String getAdapterName() { return DimeServiceAdapter.NAME; } DimeServiceAdapter(String identifier); void setProxyFactory(ProxyFactory proxyFactory); void setAccountRegistrar(AccountRegistrar accountRegistrar); void setPublicResolverService(HttpRestProxy publicResolverService); void setCredentialStore(CredentialStore credentialStore); void setPolicyManager(PolicyManager policyManager); @Override String getAdapterName(); Collection<T> get(String receiverSAID, String senderSAID,
String attribute, Class<T> returnType, Tenant tenant); BinaryFile getBinary(String receiverSAID, String senderSAID,
String resourceId, Tenant tenant); @Override void _set(String attribute, Object value); @Override Collection<T> search(String attribute,
Resource values, Class<T> returnType); @Override Collection<T> search(Resource values,
Class<T> returnType); PersonContact getProfile(String targetSaidName, Token token); Token getUserToken(String username, Tenant tenant); boolean confirmToken(Token token, Tenant tenant); @Override Boolean isConnected(); ServiceResponse[] getRaw(String attribute); @Override Collection<T> get(String attribute, Class<T> returnType); @Override void response(String attribute, Resource value); @Override void delete(String attribute); static final String NAME; }### Answer:
@Test public void testGetAdapterName() throws Exception { DimeServiceAdapter adapter = new DimeServiceAdapter("test"); assertEquals("di.me", adapter.getAdapterName()); } |
### Question:
AttributeMap { public String getAttribute (String input) { Iterator<String> iterator = this.attributes.iterator(); while (iterator.hasNext()) { String candidate = iterator.next(); String attr = candidate.replaceAll("\\{\\w+\\}", "([^/]+)"); if (input.matches(attr)) { return candidate; } } return null; } AttributeMap(); String getAttribute(String input); Map<String, String> extractIds(String attribute, String input); static final String EVENT_ID; static final String USER_ID; static final String EVENT_ALL; static final String EVENT_ALLMINE; static final String EVENT_DETAILS; static final String EVENT_ATTENDEES; static final String EVENT_ATTENDEEDETAILS; static final String PROFILE_ME; static final String PROFILE_MYDETAILS; static final String PROFILE_DETAILS; static final String PROFILEATTRIBUTE_MYDETAILS; static final String PROFILEATTRIBUTE_DETAILS; static final String FRIEND_ALL; static final String FRIEND_DETAILS; static final String GROUP_ALL; static final String LIVEPOST_ALL; static final String LIVEPOST_ALLMINE; static final String LIVEPOST_ALLUSER; static final String NOTIFICATION; static final String PLACE_ALL; static final String ACTIVITY_ALL; static final String ACTIVITY_DETAILS; }### Answer:
@Test public void testGetAttribute() { AttributeMap attributeMap = new AttributeMap(); assertTrue("Wrong mapping found for getAttribute(/event/@all).", attributeMap.getAttribute("/event/@all").equals(AttributeMap.EVENT_ALL)); assertTrue("Wrong mapping found for getAttribute(/event/@me/123).", attributeMap.getAttribute("/event/@me/123").equals(AttributeMap.EVENT_DETAILS)); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.