Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Test Betclic
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
Container 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
Clément CORNU
Test Betclic
Commits
8fea5840
Commit
8fea5840
authored
3 months ago
by
Clément CORNU
Browse files
Options
Downloads
Patches
Plain Diff
feat: handle same points number edge case
parent
1e7638f6
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/kotlin/player/services/PlayerServiceImpl.kt
+7
-1
7 additions, 1 deletion
src/main/kotlin/player/services/PlayerServiceImpl.kt
src/test/kotlin/player/PlayerServiceTest.kt
+10
-0
10 additions, 0 deletions
src/test/kotlin/player/PlayerServiceTest.kt
with
17 additions
and
1 deletion
src/main/kotlin/player/services/PlayerServiceImpl.kt
+
7
−
1
View file @
8fea5840
...
...
@@ -37,11 +37,17 @@ class PlayerServiceImpl(private val playerRepository: PlayerRepository) : Player
override
suspend
fun
getPlayersRanked
():
List
<
PlayerInfoDTO
>
{
val
allPlayers
=
playerRepository
.
findAll
()
var
currentRank
=
1
var
previousPoints
=
0
return
allPlayers
.
sortedByDescending
{
it
.
pointsNumber
}.
mapIndexed
{
index
,
player
->
if
(
previousPoints
!=
player
.
pointsNumber
)
{
currentRank
=
index
+
1
}
previousPoints
=
player
.
pointsNumber
PlayerInfoDTO
(
pseudo
=
player
.
pseudo
,
pointsNumber
=
player
.
pointsNumber
,
ranking
=
index
+
1
ranking
=
currentRank
,
)
}
...
...
This diff is collapsed.
Click to expand it.
src/test/kotlin/player/PlayerServiceTest.kt
+
10
−
0
View file @
8fea5840
...
...
@@ -102,6 +102,16 @@ class PlayerServiceTest {
assertThat
(
result
.
last
().
ranking
).
isEqualTo
(
2
)
}
@Test
fun
`when
getting
all
players
with
two
players
with
the
same
points
number
,
should
return
the
same
rank`
()
{
val
player2WithSamePoints
=
player2
.
copy
(
pointsNumber
=
30
)
val
player3WithSamePoints
=
Player
(
pseudo
=
"Charlie"
,
pointsNumber
=
30
)
coEvery
{
playerRepository
.
findAll
()
}
returns
listOf
(
player1
,
player2WithSamePoints
,
player3WithSamePoints
)
val
result
=
runBlocking
{
playerService
.
getPlayersRanked
()
}
assertThat
(
result
.
first
().
ranking
).
isEqualTo
(
result
[
1
].
ranking
)
assertThat
(
result
.
last
().
ranking
).
isNotEqualTo
(
2
)
}
@Test
fun
`when
deleting
all
players
,
should
call
the
repository
once`
()
{
coEvery
{
playerRepository
.
deleteAllPlayers
()
}
just
runs
...
...
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