1
+ package rules
2
+
3
+ import dev.robocode.tankroyale.server.rules.calcNewBotSpeed
4
+ import io.kotest.core.spec.style.FunSpec
5
+ import io.kotest.datatest.withData
6
+ import io.kotest.matchers.shouldBe
7
+
8
+
9
+ class mathTest : FunSpec ({
10
+
11
+ context("calcNewBotSpeed") {
12
+ withData(
13
+ mapOf(
14
+ // When starting speed is 0 with various positive target speeds, the new speed should not exceed the
15
+ // positive acceleration of 1
16
+ "current speed = 0, target speed = 0 => new speed = 0" to arrayOf(0.0, 0.0, 0.0),
17
+ "current speed = 0, target speed = 0.5 => new speed = 0.5" to arrayOf(0.0, 0.5, 0.5),
18
+ "current speed = 0, target speed = 1 => new speed = 1" to arrayOf(0.0, 1.0, 1.0),
19
+ // New speed cannot pass the acceleration of 1
20
+ "current speed = 0, target speed = 2 => new speed = 1" to arrayOf(0.0, 2.0, 1.0),
21
+ "current speed = 0, target speed = 8 => new speed = 1" to arrayOf(0.0, 8.0, 1.0),
22
+ "current speed = 0, target speed = 9 => new speed = 1" to arrayOf(0.0, 9.0, 1.0),
23
+
24
+ // When starting speed is 0 with various negative target speeds, the new speed should not exceed the
25
+ // negative acceleration of 1
26
+ "current speed = 0, target speed = -0.5 => new speed = -0.5" to arrayOf(0.0, -0.5, -0.5),
27
+ "current speed = 0, target speed = -1 => new speed = -1" to arrayOf(0.0, -1.0, -1.0),
28
+ "current speed = 0, target speed = -2 => new speed = -1" to arrayOf(0.0, -2.0, -1.0),
29
+ // New speed cannot pass the acceleration of -1
30
+ "current speed = 0, target speed = -8 => new speed = -1" to arrayOf(0.0, -8.0, -1.0),
31
+ "current speed = 0, target speed = -9 => new speed = -1" to arrayOf(0.0, -9.0, -1.0),
32
+
33
+ // Decelerating from max speed should allow deceleration of down to -2
34
+ "current speed = 8, target speed = 7 => new speed = 7" to arrayOf(8.0, 7.0, 7.0),
35
+ "current speed = 8, target speed = 6 => new speed = 6" to arrayOf(8.0, 6.0, 6.0),
36
+ // new speed cannot pass the deceleration of -2
37
+ "current speed = 8, target speed = 5 => new speed = 6" to arrayOf(8.0, 5.0, 6.0),
38
+
39
+ // Decelerating from min speed should allow deceleration of up to 2
40
+ "current speed = -8, target speed = -7 => new speed = -7" to arrayOf(-8.0, -7.0, -7.0),
41
+ "current speed = -8, target speed = -6 => new speed = -6" to arrayOf(-8.0, -6.0, -6.0),
42
+ // new speed cannot pass the deceleration of -2
43
+ "current speed = -8, target speed = -5 => new speed = -6" to arrayOf(-8.0, -5.0, -6.0),
44
+
45
+ // Speed crossing a positive to negative speed (original Robocode )
46
+ "current speed = 1, target speed = -8 => new speed = -0.5" to arrayOf(1.0, -8.0, -0.5),
47
+ "current speed = 0.5, target speed = -8 => new speed = -0.75" to arrayOf(0.5, -8.0, -0.75),
48
+
49
+ // Speed crossing a negative to positive speed (original Robocode )
50
+ "current speed = -1, target speed = 8 => new speed = 0.5" to arrayOf(-1.0, 8.0, 0.5),
51
+ "current speed = -0.5, target speed = 8 => new speed = 0.75" to arrayOf(-0.5, 8.0, 0.75),
52
+ )
53
+ )
54
+ { (currentSpeed, targetSpeed, newSpeed) ->
55
+ calcNewBotSpeed(currentSpeed, targetSpeed) shouldBe newSpeed
56
+ }
57
+ }
58
+ })
0 commit comments