Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
scoreboard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
João Lino
scoreboard
Commits
78dbaf9b
Commit
78dbaf9b
authored
Aug 02, 2022
by
João Lino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove fails, use asserts
parent
cec5c367
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
34 deletions
+14
-34
src/test/java/org/example/scoreboard/reference/TestScoreboard.java
...java/org/example/scoreboard/reference/TestScoreboard.java
+14
-34
No files found.
src/test/java/org/example/scoreboard/reference/TestScoreboard.java
View file @
78dbaf9b
...
@@ -7,7 +7,6 @@ import org.junit.Before;
...
@@ -7,7 +7,6 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.junit.Test
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
java.util.stream.Stream
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.*;
...
@@ -70,45 +69,35 @@ public class TestScoreboard {
...
@@ -70,45 +69,35 @@ public class TestScoreboard {
@Test
@Test
public
void
shouldFinishAGame_whenGameHasBeenStarted
()
{
public
void
shouldFinishAGame_whenGameHasBeenStarted
()
{
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
if
(
match
!=
scoreboard
.
finishMatch
(
match
))
{
assertEquals
(
match
,
scoreboard
.
finishMatch
(
match
));
fail
(
"unable to finish game"
);
}
}
}
// should throw NoSuchElementException match is not ongoing
// should throw NoSuchElementException match is not ongoing
@Test
@Test
public
void
shouldThrowNoSuchElementException_whenMatchNotFound
()
{
public
void
shouldThrowNoSuchElementException_whenMatchNotFound
()
{
Match
match
=
new
Match
(
Mexico
,
Canada
);
Match
match
=
new
Match
(
Mexico
,
Canada
);
try
{
assertThrows
(
NoSuchElementException
.
class
,
()
->
scoreboard
.
finishMatch
(
match
));
scoreboard
.
finishMatch
(
match
);
fail
(
"exception was not thrown"
);
}
catch
(
NoSuchElementException
ignored
)
{}
}
}
// summary should be empty when no match has started
// summary should be empty when no match has started
@Test
@Test
public
void
shouldBeEmptySummary_whenNoMatchHasStarted
()
{
public
void
shouldBeEmptySummary_whenNoMatchHasStarted
()
{
if
(!
scoreboard
.
getGameSummary
().
isEmpty
())
{
assertTrue
(
scoreboard
.
getGameSummary
().
isEmpty
());
fail
(
"Summary was not empty on creation."
);
}
}
}
// should get game in summary when the game has been started before
// should get game in summary when the game has been started before
@Test
@Test
public
void
shouldGetGameInSummary_whenGameHasBeenStarted
()
{
public
void
shouldGetGameInSummary_whenGameHasBeenStarted
()
{
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
if
(
match
!=
scoreboard
.
getGameSummary
().
get
(
0
))
{
assertEquals
(
match
,
scoreboard
.
getGameSummary
().
get
(
0
));
fail
(
"unable to get single ongoing game"
);
}
}
}
// score for a match that just started should be 0-0
// score for a match that just started should be 0-0
@Test
@Test
public
void
scoreShouldBeZeroZero_whenMatchJustStarted
()
{
public
void
scoreShouldBeZeroZero_whenMatchJustStarted
()
{
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
if
(
match
.
getHomeTeamScore
().
getGoals
()
!=
0
||
match
.
getAwayTeamScore
().
getGoals
()
!=
0
)
{
assertEquals
(
Integer
.
valueOf
(
0
),
match
.
getHomeTeamScore
().
getGoals
());
fail
(
"initial score was not 0-0"
);
assertEquals
(
Integer
.
valueOf
(
0
),
match
.
getAwayTeamScore
().
getGoals
());
}
}
}
// score increase for home team when home team score is updated to + 1
// score increase for home team when home team score is updated to + 1
...
@@ -117,9 +106,8 @@ public class TestScoreboard {
...
@@ -117,9 +106,8 @@ public class TestScoreboard {
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
IMatch
match
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
IScore
updatedHomeTeamScore
=
new
Score
(
match
.
getHomeTeamScore
().
getGoals
()
+
1
);
IScore
updatedHomeTeamScore
=
new
Score
(
match
.
getHomeTeamScore
().
getGoals
()
+
1
);
scoreboard
.
updateScore
(
match
,
updatedHomeTeamScore
,
match
.
getAwayTeamScore
());
scoreboard
.
updateScore
(
match
,
updatedHomeTeamScore
,
match
.
getAwayTeamScore
());
if
(
match
.
getHomeTeamScore
().
getGoals
()
!=
1
||
match
.
getAwayTeamScore
().
getGoals
()
!=
0
)
{
assertEquals
(
Integer
.
valueOf
(
1
),
match
.
getHomeTeamScore
().
getGoals
());
fail
(
"updated score was not 1-0"
);
assertEquals
(
Integer
.
valueOf
(
0
),
match
.
getAwayTeamScore
().
getGoals
());
}
}
}
// should present matches ordered from newest to oldest when summary is requested
// should present matches ordered from newest to oldest when summary is requested
...
@@ -136,13 +124,9 @@ public class TestScoreboard {
...
@@ -136,13 +124,9 @@ public class TestScoreboard {
IMatch
match5
=
scoreboard
.
startMatch
(
Argentina
,
Australia
);
IMatch
match5
=
scoreboard
.
startMatch
(
Argentina
,
Australia
);
match5
=
scoreboard
.
updateScore
(
match5
,
new
Score
(
5
),
new
Score
(
5
));
match5
=
scoreboard
.
updateScore
(
match5
,
new
Score
(
5
),
new
Score
(
5
));
ArrayList
<
IMatch
>
expectedResult
=
Stream
.
of
(
match5
,
match4
,
match3
,
match2
,
match1
).
collect
(
Collectors
.
toCollection
(
ArrayList:
:
new
));
Object
[]
expectedResult
=
Stream
.
of
(
match5
,
match4
,
match3
,
match2
,
match1
).
toArray
();
ArrayList
<
IMatch
>
gameSummary
=
scoreboard
.
getGameSummary
();
Object
[]
gameSummary
=
scoreboard
.
getGameSummary
().
toArray
();
assertArrayEquals
(
expectedResult
,
gameSummary
);
if
(!
expectedResult
.
equals
(
gameSummary
))
{
gameSummary
.
forEach
(
System
.
out
::
println
);
fail
(
"failed to return expected ordered summary"
);
}
}
}
// should present matches ordered from highest combined score to lowest, newest to oldest on collision, when summary is requested
// should present matches ordered from highest combined score to lowest, newest to oldest on collision, when summary is requested
...
@@ -159,12 +143,8 @@ public class TestScoreboard {
...
@@ -159,12 +143,8 @@ public class TestScoreboard {
IMatch
match5
=
scoreboard
.
startMatch
(
Argentina
,
Australia
);
IMatch
match5
=
scoreboard
.
startMatch
(
Argentina
,
Australia
);
match5
=
scoreboard
.
updateScore
(
match5
,
new
Score
(
3
),
new
Score
(
1
));
match5
=
scoreboard
.
updateScore
(
match5
,
new
Score
(
3
),
new
Score
(
1
));
ArrayList
<
IMatch
>
expectedResult
=
Stream
.
of
(
match4
,
match2
,
match1
,
match5
,
match3
).
collect
(
Collectors
.
toCollection
(
ArrayList:
:
new
));
Object
[]
expectedResult
=
Stream
.
of
(
match4
,
match2
,
match1
,
match5
,
match3
).
toArray
();
ArrayList
<
IMatch
>
gameSummary
=
scoreboard
.
getGameSummary
();
Object
[]
gameSummary
=
scoreboard
.
getGameSummary
().
toArray
();
assertArrayEquals
(
expectedResult
,
gameSummary
);
if
(!
expectedResult
.
equals
(
gameSummary
))
{
gameSummary
.
forEach
(
System
.
out
::
println
);
fail
(
"failed to return expected ordered summary"
);
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment