Skip to content
Snippets Groups Projects
Commit 39a2e7fe authored by Thomas FABRE's avatar Thomas FABRE
Browse files

Refactor threes with Roll

parent 66528a3e
Branches
No related tags found
No related merge requests found
......@@ -20,31 +20,15 @@ public final class Yatzy {
}
public static int ones(Roll roll) {
return roll.toStream().filter(i -> i == 1).sum();
return roll.toStream().filter(dice -> dice == 1).sum();
}
public static int twos(Roll roll) {
return roll.toStream().filter(i -> i == 2).sum();
return roll.toStream().filter(dice -> dice == 2).sum();
}
public static int threes(int d1, int d2, int d3, int d4, int d5) {
int s = 0;
if (d1 == 3) {
s += 3;
}
if (d2 == 3) {
s += 3;
}
if (d3 == 3) {
s += 3;
}
if (d4 == 3) {
s += 3;
}
if (d5 == 3) {
s += 3;
}
return s;
public static int threes(Roll roll) {
return roll.toStream().filter(dice -> dice == 3).sum();
}
public static int pair(int d1, int d2, int d3, int d4, int d5) {
......
......@@ -49,8 +49,8 @@ class YatzyTest {
@Test
void threesShouldSumAllThreeDices() {
assertAll(
() -> assertEquals(6, Yatzy.threes(1, 2, 3, 2, 3)),
() -> assertEquals(12, Yatzy.threes(2, 3, 3, 3, 3))
() -> assertEquals(6, Yatzy.threes(roll(1, 2, 3, 2, 3))),
() -> assertEquals(12, Yatzy.threes(roll(2, 3, 3, 3, 3)))
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment