Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arbeidskrav 4 prog2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Scott Langum Du Plessis
Arbeidskrav 4 prog2
Commits
5f44deb5
Commit
5f44deb5
authored
1 year ago
by
Scott Langum Du Plessis
Browse files
Options
Downloads
Patches
Plain Diff
Finished all unit tests
parent
19d7a07e
No related branches found
No related tags found
1 merge request
!4
Add unit tests
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/edu/ntnu/stud/cardgame/HandOfCards.java
+5
-7
5 additions, 7 deletions
src/main/java/edu/ntnu/stud/cardgame/HandOfCards.java
src/test/java/edu/ntnu/stud/cardgame/HandOfCardsTest.java
+65
-0
65 additions, 0 deletions
src/test/java/edu/ntnu/stud/cardgame/HandOfCardsTest.java
with
70 additions
and
7 deletions
src/main/java/edu/ntnu/stud/cardgame/HandOfCards.java
+
5
−
7
View file @
5f44deb5
...
...
@@ -23,21 +23,19 @@ public class HandOfCards {
public
int
getSum
()
{
return
hand
.
stream
()
.
mapToInt
(
PlayingCard:
:
getFace
)
.
sum
(
);
.
reduce
(
0
,
Integer:
:
sum
);
}
public
String
findHearts
()
{
StringBuilder
sb
=
new
StringBuilder
();
hand
.
stream
()
String
hearts
=
hand
.
stream
()
.
map
(
PlayingCard:
:
getAsString
)
.
filter
(
s
->
s
.
charAt
(
0
)
==
'H'
)
.
forEach
(
sb:
:
append
);
.
collect
(
Collectors
.
joining
(
" "
)
);
if
(
s
b
.
isEmpty
())
{
if
(
heart
s
.
isEmpty
())
{
return
"No hearts"
;
}
return
sb
.
toString
();
return
hearts
.
trim
();
}
public
boolean
containsQueenOfSpades
()
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/edu/ntnu/stud/cardgame/HandOfCardsTest.java
0 → 100644
+
65
−
0
View file @
5f44deb5
package
edu.ntnu.stud.cardgame
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
public
class
HandOfCardsTest
{
HandOfCards
hand
;
PlayingCard
card1
;
PlayingCard
card2
;
PlayingCard
card3
;
PlayingCard
card4
;
@BeforeEach
void
setHand
()
{
hand
=
new
HandOfCards
();
card1
=
new
PlayingCard
(
'H'
,
12
);
card2
=
new
PlayingCard
(
'D'
,
2
);
card3
=
new
PlayingCard
(
'C'
,
7
);
card4
=
new
PlayingCard
(
'S'
,
12
);
}
@Nested
class
PositiveTests
{
@Test
void
testAddCard
()
{
hand
.
addCard
(
card1
);
assertTrue
(
hand
.
getHand
().
contains
(
card1
));
}
@Test
void
testGetSum
()
{
hand
.
addCard
(
card1
);
hand
.
addCard
(
card2
);
hand
.
addCard
(
card3
);
assertEquals
(
hand
.
getSum
(),
21
);
}
@Test
void
testFindHearts
()
{
hand
.
addCard
(
card1
);
assertEquals
(
hand
.
findHearts
(),
card1
.
getAsString
());
}
@Test
void
testContainsQueenOfSpades
(){
assertFalse
(
hand
.
containsQueenOfSpades
());
hand
.
addCard
(
card4
);
assertTrue
(
hand
.
containsQueenOfSpades
());
}
@Test
void
testContains5Flush
()
{
assertFalse
(
hand
.
contains5Flush
());
for
(
int
i
=
0
;
i
<
5
;
i
++){
hand
.
addCard
(
card2
);
}
assertTrue
(
hand
.
contains5Flush
());
}
}
}
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