Skip to content

Commit

Permalink
Fix possible exception in scheduler test
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Nov 16, 2023
1 parent 47f97c6 commit 2677097
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/test/kotlin/net/mcbrawls/scheduler/test/SchedulerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mcbrawls.scheduler.test
import net.mcbrawls.scheduler.AbsoluteScheduler
import java.time.Duration
import kotlin.math.abs
import kotlin.math.min
import kotlin.test.Test

object SchedulerTest {
Expand Down Expand Up @@ -43,7 +44,8 @@ object SchedulerTest {
// assert
val deltaTimeMs = milliTime - timeMs
val percentageDiff = abs(deltaTimeMs - expectedMillis) / ((deltaTimeMs + expectedMillis) / 2.0) * 100
val roundedPercentageDiff = percentageDiff.toString().substring(0, 5)
val percentageDiffString = percentageDiff.toString()
val roundedPercentageDiff = percentageDiffString.substring(0, min(5, percentageDiffString.length))

println("Delta time $deltaTimeMs ms, expected time $expectedMillis, diff $roundedPercentageDiff%")
assert(percentageDiff < 0.1)
Expand Down

0 comments on commit 2677097

Please sign in to comment.