-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update project's best execution in a contest when execution is finished #1162
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6ef339
Update project's best execution in a contest when execution is finished
petertrr a7cd0bf
Merge remote-tracking branch 'origin/master' into feature/best-score#…
petertrr 07aef87
Code style
petertrr a664ec7
Fix test context initialization; move some beans from `@Import` to `@…
petertrr bcaef7a
Merge remote-tracking branch 'origin/master' into feature/best-score#…
petertrr 2d49194
Code style
petertrr c4ffdf5
Merge branch 'master' into feature/best-score#1115
petertrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...kend/src/test/kotlin/com/saveourtool/save/backend/service/LnkContestProjectServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.saveourtool.save.backend.service | ||
|
||
import com.saveourtool.save.backend.repository.LnkContestProjectRepository | ||
import com.saveourtool.save.entities.Contest | ||
import com.saveourtool.save.entities.Execution | ||
import com.saveourtool.save.entities.LnkContestProject | ||
import com.saveourtool.save.entities.Project | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.kotlin.* | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.context.annotation.Import | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import java.util.Optional | ||
import kotlin.math.abs | ||
|
||
@ExtendWith(SpringExtension::class) | ||
@Import(LnkContestProjectService::class) | ||
@Suppress("UnsafeCallOnNullableType") | ||
class LnkContestProjectServiceTest { | ||
@Autowired private lateinit var lnkContestProjectService: LnkContestProjectService | ||
@MockBean private lateinit var lnkContestProjectRepository: LnkContestProjectRepository | ||
@MockBean private lateinit var lnkContestExecutionService: LnkContestExecutionService | ||
|
||
@Test | ||
fun `should update best score if it is empty`() { | ||
givenOldBestExecution(null) | ||
|
||
lnkContestProjectService.updateBestExecution(Execution.stub(Project.stub(99)).apply { score = 4.0 }) | ||
|
||
then(lnkContestProjectRepository) | ||
.should(times(1)) | ||
.save(argWhere { | ||
abs(it.bestScore!! - 4.0) < 1e-4 | ||
|
||
}) | ||
} | ||
|
||
@Test | ||
fun `should update best score if the new one is greater`() { | ||
givenOldBestExecution( | ||
Execution.stub(Project.stub(99)).apply { | ||
id = 99 | ||
score = 3.3 | ||
} | ||
) | ||
|
||
lnkContestProjectService.updateBestExecution(Execution.stub(Project.stub(99)).apply { score = 4.0 }) | ||
|
||
then(lnkContestProjectRepository) | ||
.should(times(1)) | ||
.save(argWhere { | ||
abs(it.bestScore!! - 4.0) < 1e-4 | ||
|
||
}) | ||
} | ||
|
||
@Test | ||
fun `should not update best score if the new one is smaller`() { | ||
givenOldBestExecution( | ||
Execution.stub(Project.stub(99)).apply { | ||
id = 99 | ||
score = 5.0 | ||
} | ||
) | ||
|
||
lnkContestProjectService.updateBestExecution(Execution.stub(Project.stub(99)).apply { score = 4.4 }) | ||
|
||
then(lnkContestProjectRepository) | ||
.should(never()) | ||
.save(any()) | ||
} | ||
|
||
private fun givenOldBestExecution(oldBestExecution: Execution?) { | ||
given(lnkContestExecutionService.findContestByExecution(any())) | ||
.willReturn(Contest.stub(99)) | ||
given(lnkContestProjectRepository.findByContestAndProject(any(), any())) | ||
.willAnswer { | ||
LnkContestProject(it.arguments[1] as Project, it.arguments[0] as Contest, oldBestExecution, oldBestExecution?.score) | ||
.let { Optional.of(it) } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need
bestScore
as separate field onlnkContestProject
now? it can be replaced tobestExecution?.score