Skip to content
Snippets Groups Projects
Commit c6f3d596 authored by Sander August Heggland Schrader's avatar Sander August Heggland Schrader
Browse files

Added more lambda functions

parent c1a78434
No related branches found
No related tags found
No related merge requests found
...@@ -22,12 +22,12 @@ class CardHandTest { ...@@ -22,12 +22,12 @@ class CardHandTest {
public void isFlushTest() { public void isFlushTest() {
// Flush // Flush
CardHand hand = new CardHand(); CardHand hand = new CardHand();
IntStream.range(0,5).mapToObj(i -> new PlayingCard('D', i +1 )).forEach(e -> hand.addCard(e)); IntStream.range(0,5).mapToObj(i -> new PlayingCard('D', i +1 )).forEach(hand::addCard);
assertTrue(hand.flush()); assertTrue(hand.flush());
// Not Flush // Not Flush
CardHand hand2 = new CardHand(); CardHand hand2 = new CardHand();
IntStream.range(0,4).mapToObj(i -> new PlayingCard('D', i +1 )).forEach(e -> hand2.addCard(e)); IntStream.range(0,4).mapToObj(i -> new PlayingCard('D', i +1 )).forEach(hand2::addCard);
hand.addCard(new PlayingCard('S', 5)); hand.addCard(new PlayingCard('S', 5));
assertFalse(hand2.flush()); assertFalse(hand2.flush());
} }
...@@ -40,7 +40,7 @@ class CardHandTest { ...@@ -40,7 +40,7 @@ class CardHandTest {
assertEquals(0, hand.getCardSum()); assertEquals(0, hand.getCardSum());
// Ace - King => 1+2+3+...+13 // Ace - King => 1+2+3+...+13
IntStream.range(0,13).mapToObj(i -> new PlayingCard('D', i +1 )).forEach(e -> hand.addCard(e)); IntStream.range(0,13).mapToObj(i -> new PlayingCard('D', i +1 )).forEach(hand::addCard);
int total = 1+2+3+4+5+6+7+8+9+10+11+12+13; int total = 1+2+3+4+5+6+7+8+9+10+11+12+13;
assertEquals(total, hand.getCardSum()); assertEquals(total, hand.getCardSum());
} }
...@@ -71,7 +71,7 @@ class CardHandTest { ...@@ -71,7 +71,7 @@ class CardHandTest {
// Filter the card arraylist and get all diamonds. Then map it into an list of strings then collect it and make a string from the list // Filter the card arraylist and get all diamonds. Then map it into an list of strings then collect it and make a string from the list
String diamonds = cards.stream().filter(c -> c.getSuit() == 'D').map(c -> c.getSuit() + "").collect(Collectors.joining("")); String diamonds = cards.stream().filter(c -> c.getSuit() == 'D').map(c -> c.getSuit() + "").collect(Collectors.joining(""));
// Get filtered arraylist with just diamond cards from hand. Then map so we get a list of just the suits in string and then make it into a string // Get filtered arraylist with just diamond cards from hand. Then use map so we get a list of just the suits in list of strings. Then make it into a string
String diamondsFromHand = hand.getAllWithSuit("D").stream().map(c -> c.getSuit() + "").collect(Collectors.joining("")); String diamondsFromHand = hand.getAllWithSuit("D").stream().map(c -> c.getSuit() + "").collect(Collectors.joining(""));
// Check if strings are equal. This means equal length and same characters. E.g "DDDD" === "DDDD" -> true // Check if strings are equal. This means equal length and same characters. E.g "DDDD" === "DDDD" -> true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment