Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Y
yatzy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tfabre
yatzy
Commits
39a2e7fe
Commit
39a2e7fe
authored
2 years ago
by
Thomas FABRE
Browse files
Options
Downloads
Patches
Plain Diff
Refactor threes with Roll
parent
66528a3e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/io/takima/Yatzy.java
+4
-20
4 additions, 20 deletions
src/main/java/io/takima/Yatzy.java
src/test/java/io/takima/YatzyTest.java
+2
-2
2 additions, 2 deletions
src/test/java/io/takima/YatzyTest.java
with
6 additions
and
22 deletions
src/main/java/io/takima/Yatzy.java
+
4
−
20
View file @
39a2e7fe
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/io/takima/YatzyTest.java
+
2
−
2
View file @
39a2e7fe
...
...
@@ -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
))
)
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment