From c6f3d596e3c8d7e7785b1175f70c1639b80e3eed Mon Sep 17 00:00:00 2001 From: saschrad <saschrad@stud.ntnu.no> Date: Sun, 11 Apr 2021 20:57:28 +0200 Subject: [PATCH] Added more lambda functions --- .../java/no/ntnu/idatt2001/cardgame/CardHandTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/no/ntnu/idatt2001/cardgame/CardHandTest.java b/src/test/java/no/ntnu/idatt2001/cardgame/CardHandTest.java index 1e1fe7d..f6441c5 100644 --- a/src/test/java/no/ntnu/idatt2001/cardgame/CardHandTest.java +++ b/src/test/java/no/ntnu/idatt2001/cardgame/CardHandTest.java @@ -22,12 +22,12 @@ class CardHandTest { public void isFlushTest() { // Flush 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()); // Not Flush 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)); assertFalse(hand2.flush()); } @@ -40,7 +40,7 @@ class CardHandTest { assertEquals(0, hand.getCardSum()); // 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; assertEquals(total, hand.getCardSum()); } @@ -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 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("")); // Check if strings are equal. This means equal length and same characters. E.g "DDDD" === "DDDD" -> true -- GitLab