Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
oop
project
Commits
5f36e98e
Commit
5f36e98e
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: adding tests for Card class
parent
18c49164
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/hepia/CardTest.java
+77
-7
77 additions, 7 deletions
src/test/java/hepia/CardTest.java
with
77 additions
and
7 deletions
src/test/java/hepia/CardTest.java
+
77
−
7
View file @
5f36e98e
package
hepia
;
import
org.junit.jupiter.api.Test
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotEquals
;
public
class
CardTest
{
@Test
public
void
testCardCreation
()
{
ISuit
suit
=
ColourSuit
.
SPADE
;
int
rank
=
2
;
int
weight
=
5
;
Card
card
=
new
Card
(
suit
,
rank
,
weight
);
assertEquals
(
suit
,
card
.
getSuit
());
assertEquals
(
rank
,
card
.
getRank
());
assertEquals
(
weight
,
card
.
getWeight
());
}
@Test
public
void
random
()
{
assertEquals
(
2
,
1
+
1
);
public
void
testCardEquality
()
{
ISuit
suit1
=
ColourSuit
.
HEART
;
int
rank1
=
2
;
int
weight1
=
5
;
Card
card1
=
new
Card
(
suit1
,
rank1
,
weight1
);
ISuit
suit2
=
ColourSuit
.
HEART
;
int
rank2
=
2
;
int
weight2
=
5
;
Card
card2
=
new
Card
(
suit2
,
rank2
,
weight2
);
assertEquals
(
card1
,
card2
);
}
@Test
public
void
testCardInequality
()
{
ISuit
suit1
=
ColourSuit
.
DIAMOND
;
int
rank1
=
4
;
int
weight1
=
2
;
Card
card1
=
new
Card
(
suit1
,
rank1
,
weight1
);
ISuit
suit2
=
ColourSuit
.
CLUB
;
int
rank2
=
3
;
int
weight2
=
6
;
Card
card2
=
new
Card
(
suit2
,
rank2
,
weight2
);
assertNotEquals
(
card1
,
card2
);
}
@Test
public
void
testInvalidToString
()
{
ISuit
suit
=
ColourSuit
.
DIAMOND
;
int
rank
=
2
;
Card
card
=
new
Card
(
suit
,
rank
);
assertNotEquals
(
"2 de Trèfle"
,
card
.
toString
());
}
@Test
public
void
testValidToString
()
{
ISuit
suit
=
ColourSuit
.
SPADE
;
int
rank
=
14
;
Card
card
=
new
Card
(
suit
,
rank
);
assertEquals
(
"Roi de Pique"
,
card
.
toString
());
}
@Test
public
void
testInvalidCardCreationWithInvalidRank
()
{
ISuit
suit
=
ColourSuit
.
HEART
;
int
invalidRank
=
20
;
assertThrows
(
RuntimeException
.
class
,
()
->
new
Card
(
suit
,
invalidRank
));
}
@Test
public
void
testInvalidCardCreationWithMismatchedRankAndSpecialSuit
()
{
ISuit
suit
=
SpecialSuit
.
EXCUSE
;
int
rank
=
2
;
assertThrows
(
RuntimeException
.
class
,
()
->
new
Card
(
suit
,
rank
));
}
@Test
public
void
InvalidCardCreation
()
{
assertThrows
(
RuntimeException
.
class
,
()
->
new
Card
(
SpecialSuit
.
JOKER
,
2
));
public
void
testInvalidCardCreationWithMismatchedRankAndColourSuit
()
{
ISuit
suit
=
ColourSuit
.
HEART
;
int
rank
=
0
;
assertThrows
(
RuntimeException
.
class
,
()
->
new
Card
(
suit
,
rank
));
}
}
\ No newline at end of file
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