Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
student-tournament-hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Schneider Stefan
student-tournament-hub
Commits
ea53935b
Commit
ea53935b
authored
1 year ago
by
Häderle Marius
Browse files
Options
Downloads
Patches
Plain Diff
14.01.2024 - added test for Bracket´s
#27
parent
539089fe
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Dev in Main Merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java
+61
-10
61 additions, 10 deletions
...hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java
with
61 additions
and
10 deletions
sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java
+
61
−
10
View file @
ea53935b
...
...
@@ -19,6 +19,7 @@ import java.util.Optional;
import
java.util.UUID
;
import
static
hdm
.
mi
.
sthbackend
.
dummyObjects
.
dummyTournaments
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
when
;
@ExtendWith
(
MockitoExtension
.
class
)
...
...
@@ -31,22 +32,72 @@ public class FillBracketRandomTest {
TournamentService
tournamentService
;
private
Tournament
createDummyBracketAndMatches
(
int
rounds
,
Tournament
tournament
){
tournament
.
setBracket
(
new
ArrayList
<>());
for
(
int
i
=
0
;
i
<
rounds
;
i
++)
{
tournament
.
getBracket
().
add
(
new
BracketRound
(
i
));
for
(
int
j
=
0
;
j
<
(
Math
.
pow
(
2
,
rounds
)
/
Math
.
pow
(
2
,
i
+
1
));
j
++)
{
UUID
matchId
=
UUID
.
randomUUID
();
tournament
.
getBracket
().
get
(
i
).
getMatches
().
put
(
matchId
,
new
Match
(
matchId
));
}
}
return
tournament
;
}
private
int
calculateTeamSum
(
Tournament
tournament
){
return
tournament
.
getBracket
()
.
stream
()
.
flatMap
(
bracketRound
->
bracketRound
.
getMatches
().
values
().
stream
())
.
map
(
match
->
match
.
getTeamScores
().
size
())
.
reduce
(
0
,
Integer:
:
sum
);
}
@Test
public
void
fill2TeamBracketRandomTest
()
throws
TournamentIdNotFoundException
{
Tournament
t1withMatches
=
t1
;
t1withMatches
.
setBracket
(
new
ArrayList
<>());
t1withMatches
.
getBracket
().
add
(
new
BracketRound
(
0
));
UUID
matchId
=
UUID
.
randomUUID
();
t1withMatches
.
getBracket
().
get
(
0
).
getMatches
().
put
(
matchId
,
new
Match
(
matchId
));
Tournament
t1withMatches
=
createDummyBracketAndMatches
(
1
,
t1
);
when
(
tournamentRepository
.
findById
(
dummyTournamentId
)).
thenReturn
(
Optional
.
of
(
t1withMatches
));
Tournament
t1Filled
=
tournamentService
.
fillBracketRandom
(
dummyTournamentId
);
int
teamSum
=
t1Filled
.
getBracket
()
.
stream
()
.
flatMap
(
bracketRound
->
bracketRound
.
getMatches
().
values
().
stream
())
.
map
(
match
->
match
.
getTeamScores
().
size
())
.
reduce
(
0
,
Integer:
:
sum
);
int
teamSum
=
calculateTeamSum
(
t1Filled
);
assertEquals
(
2
,
teamSum
);
}
@Test
public
void
fill4TeamBracketRandomTest
()
throws
TournamentIdNotFoundException
{
Tournament
t2withMatches
=
createDummyBracketAndMatches
(
2
,
t2
);
when
(
tournamentRepository
.
findById
(
dummyTournamentId
)).
thenReturn
(
Optional
.
of
(
t2withMatches
));
Tournament
t2Filled
=
tournamentService
.
fillBracketRandom
(
dummyTournamentId
);
int
teamSum
=
calculateTeamSum
(
t2Filled
);
assertEquals
(
4
,
teamSum
);
}
@Test
public
void
fill8TeamBracketRandomTest
()
throws
TournamentIdNotFoundException
{
Tournament
t3withMatches
=
createDummyBracketAndMatches
(
3
,
t3
);
when
(
tournamentRepository
.
findById
(
dummyTournamentId
)).
thenReturn
(
Optional
.
of
(
t3withMatches
));
Tournament
t3Filled
=
tournamentService
.
fillBracketRandom
(
dummyTournamentId
);
int
teamSum
=
calculateTeamSum
(
t3Filled
);
assertEquals
(
8
,
teamSum
);
}
@Test
public
void
fill16TeamBracketRandomTest
()
throws
TournamentIdNotFoundException
{
Tournament
t4withMatches
=
createDummyBracketAndMatches
(
4
,
t4
);
when
(
tournamentRepository
.
findById
(
dummyTournamentId
)).
thenReturn
(
Optional
.
of
(
t4withMatches
));
Tournament
t4Filled
=
tournamentService
.
fillBracketRandom
(
dummyTournamentId
);
int
teamSum
=
calculateTeamSum
(
t4Filled
);
assertEquals
(
16
,
teamSum
);
}
}
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