WIP: unit tests

This commit is contained in:
Piotr Dec 2023-08-24 14:01:44 +02:00
parent ff2e163983
commit 89e16fb805
No known key found for this signature in database
GPG key ID: ABD6CB83D6110D27
3 changed files with 288 additions and 0 deletions

View file

@ -0,0 +1,279 @@
package eu.ztsh.garmin.data
import eu.ztsh.garmin.Garmin
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
class GarminMapperTest {
@Test
fun linesTest() {
linesTest(
listOf(Lane.DotsLeft),
listOf(),
intArrayOf(2, 128, 0),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 128, 0, 141, 16, 3)
)
linesTest(
Lane.OuterRight,
Lane.OuterLeft,
intArrayOf(2, 2, 64),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 2, 64, 203, 16, 3)
)
linesTest(
Lane.MiddleRight,
Lane.MiddleLeft,
intArrayOf(2, 4, 32),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 4, 32, 233, 16, 3)
)
linesTest(
Lane.InnerRight,
Lane.InnerLeft,
intArrayOf(2, 8, 16),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 8, 16, 16, 245, 16, 3)
)
linesTest(
Lane.InnerLeft,
Lane.InnerRight,
intArrayOf(2, 16, 8),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 16, 16, 8, 245, 16, 3)
)
linesTest(
Lane.MiddleLeft,
Lane.MiddleRight,
intArrayOf(2, 32, 4),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 32, 4, 233, 16, 3)
)
linesTest(
Lane.OuterLeft,
Lane.OuterRight,
intArrayOf(2, 64, 2),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 64, 2, 203, 16, 3)
)
linesTest(
listOf(Lane.DotsRight),
listOf(Lane.OuterRight, Lane.MiddleRight, Lane.InnerRight, Lane.InnerLeft, Lane.MiddleLeft, Lane.OuterLeft),
intArrayOf(2, 1, 126),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 1, 126, 142, 16, 3)
)
linesTest(
listOf(),
listOf(),
intArrayOf(2, 0, 0),
intArrayOf(16, 123, 9, 3, 0, 0, 0, 85, 21, 2, 0, 0, 13, 16, 3)
)
}
@Test
fun directionTest() {
directionTest(
OutAngle.RightDown,
intArrayOf(1, 32, 0, 0),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 32, 0, 0, 236, 16, 3)
)
directionTest(
OutAngle.SharpRight,
intArrayOf(1, 1, 0, 2),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 2, 9, 16, 3)
)
directionTest(
OutAngle.Right,
intArrayOf(1, 1, 0, 4),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 4, 7, 16, 3)
)
directionTest(
OutAngle.EasyRight,
intArrayOf(1, 1, 0, 8),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 8, 3, 16, 3)
)
directionTest(
OutAngle.Straight,
intArrayOf(1, 1, 0, 16),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 16, 16, 251, 16, 3)
)
directionTest(
OutAngle.EasyLeft,
intArrayOf(1, 1, 0, 32),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 32, 235, 16, 3)
)
directionTest(
OutAngle.Left,
intArrayOf(1, 1, 0, 64),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 64, 203, 16, 3)
)
directionTest(
OutAngle.SharpLeft,
intArrayOf(1, 1, 0, 128),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 128, 139, 16, 3)
)
directionTest(
OutAngle.LeftDown,
intArrayOf(1, 16, 0, 0),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 16, 16, 0, 0, 252, 16, 3)
)
directionTest(
OutAngle.Down,
intArrayOf(1, 1, 0, 1),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 1, 0, 1, 10, 16, 3)
)
directionTest(
OutAngle.SharpRight, OutType.LongerLane,
intArrayOf(1, 2, 0, 2),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 2, 8, 16, 3)
)
directionTest(
OutAngle.Right, OutType.LongerLane,
intArrayOf(1, 2, 0, 4),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 4, 6, 16, 3)
)
directionTest(
OutAngle.EasyRight, OutType.LongerLane,
intArrayOf(1, 2, 0, 8),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 8, 2, 16, 3)
)
directionTest(
OutAngle.Straight, OutType.LongerLane,
intArrayOf(1, 2, 0, 16),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 16, 16, 250, 16, 3)
)
directionTest(
OutAngle.EasyLeft, OutType.LongerLane,
intArrayOf(1, 2, 0, 32),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 32, 234, 16, 3)
)
directionTest(
OutAngle.Left, OutType.LongerLane,
intArrayOf(1, 2, 0, 64),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 64, 202, 16, 3)
)
directionTest(
OutAngle.SharpLeft, OutType.LongerLane,
intArrayOf(1, 2, 0, 128),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 2, 0, 128, 138, 16, 3)
)
directionTest(
OutAngle.SharpRight, OutType.RightRoundabout,
intArrayOf(1, 8, 2, 2),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 2, 2, 0, 16, 3)
)
directionTest(
OutAngle.Right, OutType.RightRoundabout,
intArrayOf(1, 8, 4, 4),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 4, 4, 252, 16, 3)
)
directionTest(
OutAngle.EasyRight, OutType.RightRoundabout,
intArrayOf(1, 8, 8, 8),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 8, 8, 244, 16, 3)
)
directionTest(
OutAngle.Straight, OutType.RightRoundabout,
intArrayOf(1, 8, 16, 16),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 16, 16, 16, 16, 228, 16, 3)
)
directionTest(
OutAngle.EasyLeft, OutType.RightRoundabout,
intArrayOf(1, 8, 32, 32),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 32, 32, 196, 16, 3)
)
directionTest(
OutAngle.Left, OutType.RightRoundabout,
intArrayOf(1, 8, 64, 64),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 64, 64, 132, 16, 3)
)
directionTest(
OutAngle.SharpLeft, OutType.RightRoundabout,
intArrayOf(1, 8, 128, 128),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 8, 128, 128, 4, 16, 3)
)
directionTest(
OutAngle.Left, OutType.Flag,
intArrayOf(1, 64, 0, 64),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 64, 0, 64, 140, 16, 3)
)
directionTest(
OutAngle.Right, OutType.Flag,
intArrayOf(1, 64, 0, 4),
intArrayOf(16, 123, 10, 4, 0, 0, 0, 85, 21, 1, 64, 0, 4, 200, 16, 3)
)
}
@Test
fun distanceTest() {
// TODO
intArrayOf(3, 0, 9, 9, 0, 9, 0)
intArrayOf(16, 123, 13, 7, 0, 0, 0, 85, 21, 3, 0, 9, 9, 0, 9, 0, 233, 16, 3)
intArrayOf(3, 0, 9, 9, 0, 9, 3)
intArrayOf(16, 123, 13, 7, 0, 0, 0, 85, 21, 3, 0, 9, 9, 0, 9, 3, 230, 16, 3)
intArrayOf(3, 0, 9, 9, 0, 9, 1)
intArrayOf(16, 123, 13, 7, 0, 0, 0, 85, 21, 3, 0, 9, 9, 0, 9, 1, 232, 16, 3)
intArrayOf(3, 0, 9, 9, 0, 9, 8)
intArrayOf(16, 123, 13, 7, 0, 0, 0, 85, 21, 3, 0, 9, 9, 0, 9, 8, 225, 16, 3)
intArrayOf(3, 0, 9, 9, 0, 9, 5)
intArrayOf(16, 123, 13, 7, 0, 0, 0, 85, 21, 3, 0, 9, 9, 0, 9, 5, 228, 16, 3)
}
@Test
fun speedTest() {
// TODO
intArrayOf(7, 1)
intArrayOf(16, 123, 8, 2, 0, 0, 0, 85, 21, 7, 1, 9, 16, 3)
intArrayOf(6, 0, 0, 0, 0, 0, 5, 10, 0, 0)
intArrayOf(16, 123, 16, 16, 10, 0, 0, 0, 85, 21, 6, 0, 0, 0, 0, 0, 5, 10, 0, 0, 236, 16, 3)
intArrayOf(6, 0, 5, 10, 255, 1, 10, 10, 0, 0)
intArrayOf(16, 123, 16, 16, 10, 0, 0, 0, 85, 21, 6, 0, 5, 10, 255, 1, 10, 10, 0, 0, 216, 16, 3)
intArrayOf(6, 1, 5, 10, 255, 1, 10, 10, 255, 0)
intArrayOf(16, 123, 16, 16, 10, 0, 0, 0, 85, 21, 6, 1, 5, 10, 255, 1, 10, 10, 255, 0, 216, 16, 3)
intArrayOf(6, 0, 5, 10, 255, 1, 10, 10, 0, 255)
intArrayOf(16, 123, 16, 16, 10, 0, 0, 0, 85, 21, 6, 0, 5, 10, 255, 1, 10, 10, 0, 255, 217, 16, 3)
}
@Test
fun timeTest() {
// TODO
intArrayOf(5, 0, 2, 2, 255, 2, 2, 0, 0)
intArrayOf(16, 123, 15, 9, 0, 0, 0, 85, 21, 5, 0, 2, 2, 255, 2, 2, 0, 0, 247, 16, 3)
intArrayOf(5, 255, 2, 2, 255, 2, 2, 0, 0)
intArrayOf(16, 123, 15, 9, 0, 0, 0, 85, 21, 5, 255, 2, 2, 255, 2, 2, 0, 0, 248, 16, 3)
intArrayOf(5, 0, 2, 2, 255, 2, 2, 0, 255)
intArrayOf(16, 123, 15, 9, 0, 0, 0, 85, 21, 5, 0, 2, 2, 255, 2, 2, 0, 255, 248, 16, 3)
}
@Test
fun controlTest() {
// TODO
intArrayOf(4, 1)
intArrayOf(16, 123, 8, 2, 0, 0, 0, 85, 21, 4, 1, 12, 16, 3)
intArrayOf(4, 0)
intArrayOf(16, 123, 8, 2, 0, 0, 0, 85, 21, 4, 0, 13, 16, 3)
}
private fun linesTest(outlines: Lane, arrows: Lane, expectedRaw: IntArray, expectedBoxed: IntArray) {
linesTest(listOf(outlines), listOf(arrows), expectedRaw, expectedBoxed)
}
private fun linesTest(outlines: List<Lane>, arrows: List<Lane>, expectedRaw: IntArray, expectedBoxed: IntArray) {
val state = State()
state.lineOutlines = outlines
state.lineArrows = arrows
makeAssertions(GarminMapper.setLines(state), expectedRaw, expectedBoxed)
}
private fun directionTest(outAngle: OutAngle, expectedRaw: IntArray, expectedBoxed: IntArray) {
directionTest(outAngle, OutType.Lane, expectedRaw, expectedBoxed)
}
private fun directionTest(outAngle: OutAngle, outType: OutType, expectedRaw: IntArray, expectedBoxed: IntArray) {
val state = State()
state.direction.angle = outAngle
state.direction.out = outType
makeAssertions(GarminMapper.setDirection(state), expectedRaw, expectedBoxed)
}
private fun makeAssertions(resultRaw: IntArray, expectedRaw: IntArray, expectedBoxed: IntArray) {
assertThat(resultRaw).containsExactly(expectedRaw.toTypedArray())
val resultBoxed = Garmin.prepareData(resultRaw)
assertThat(resultBoxed).containsExactly(expectedBoxed.toTypedArray())
}
}