WIP: unit tests
This commit is contained in:
parent
ff2e163983
commit
89e16fb805
3 changed files with 288 additions and 0 deletions
|
@ -46,6 +46,7 @@ dependencies {
|
|||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||
testImplementation 'org.assertj:assertj-core:3.24.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
|
|
279
app/src/test/java/eu/ztsh/garmin/data/GarminMapperTest.kt
Normal file
279
app/src/test/java/eu/ztsh/garmin/data/GarminMapperTest.kt
Normal 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())
|
||||
}
|
||||
|
||||
}
|
|
@ -11,9 +11,11 @@ def suite(controller: Controller):
|
|||
speed(controller)
|
||||
time(controller)
|
||||
control(controller)
|
||||
compass(controller)
|
||||
|
||||
|
||||
def lines(controller: Controller):
|
||||
print("Lines")
|
||||
controller.set_lines([Lane.DotsLeft], [])
|
||||
controller.set_lines([Lane.OuterRight], [Lane.OuterLeft])
|
||||
controller.set_lines([Lane.MiddleRight], [Lane.MiddleLeft])
|
||||
|
@ -29,6 +31,7 @@ def lines(controller: Controller):
|
|||
|
||||
|
||||
def direction(controller: Controller):
|
||||
print("Direction")
|
||||
controller.set_direction(OutAngle.RightDown)
|
||||
controller.set_direction(OutAngle.SharpRight)
|
||||
controller.set_direction(OutAngle.Right)
|
||||
|
@ -58,6 +61,7 @@ def direction(controller: Controller):
|
|||
|
||||
|
||||
def distance(controller: Controller):
|
||||
print("Distance")
|
||||
controller.set_distance(999)
|
||||
controller.set_distance(999, Unit.Kilometres)
|
||||
controller.set_distance(999, Unit.Metres)
|
||||
|
@ -67,6 +71,7 @@ def distance(controller: Controller):
|
|||
|
||||
|
||||
def speed(controller: Controller):
|
||||
print("Speed")
|
||||
controller.set_gps(True)
|
||||
controller.set_speed(50)
|
||||
controller.set_speed(50, 100)
|
||||
|
@ -76,6 +81,7 @@ def speed(controller: Controller):
|
|||
|
||||
|
||||
def time(controller: Controller):
|
||||
print("Time")
|
||||
controller.set_time(22, 22)
|
||||
controller.set_time(22, 22, traffic=True)
|
||||
controller.set_time(22, 22, flag=True)
|
||||
|
@ -83,11 +89,13 @@ def time(controller: Controller):
|
|||
|
||||
|
||||
def control(controller: Controller):
|
||||
print("Speed Control")
|
||||
controller.set_speed_control()
|
||||
controller.set_speed_control(False)
|
||||
|
||||
|
||||
def compass(controller: Controller):
|
||||
print("Compass")
|
||||
controller.set_compass(22.5)
|
||||
controller.set_compass(67.5)
|
||||
controller.set_compass(112.5)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue