61 lines
2.3 KiB
Kotlin
61 lines
2.3 KiB
Kotlin
package com.hawhamburg.micr0bu
|
|||
|
|
|
||
|
|
import com.hawhamburg.micr0bu.domain.vam.VamGenerationRules
|
||
|
|
import com.hawhamburg.micr0bu.domain.vam.VamGenerationRules.Kinematics
|
||
|
|
import org.junit.Assert.assertFalse
|
||
|
|
import org.junit.Assert.assertTrue
|
||
|
|
import org.junit.Test
|
||
|
|
|
||
|
|
/** TS 103 300-3 clause 6.4 items 1 to 4, with the Table 16/17 values. */
|
||
|
|
class VamGenerationRulesTest {
|
||
|
|
|
||
|
|
private val here = Kinematics(53.5546667, 10.0223889, speedMps = 3.0, headingDeg = 90.0)
|
||
|
|
|
||
|
|
private fun sentAt(ms: Long, k: Kinematics = here) = VamGenerationRules().apply { onSent(ms, k, withLowFrequency = true) }
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `the first VAM is always due`() {
|
||
|
|
assertTrue(VamGenerationRules().due(0, here))
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `nothing is due within T_GenVamMin even after a big jump`() {
|
||
|
|
assertFalse(sentAt(1_000).due(1_050, here.copy(latitude = here.latitude + 0.001)))
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `a stationary VRU gets one VAM every T_GenVamMax`() {
|
||
|
|
val rules = sentAt(1_000)
|
||
|
|
assertFalse(rules.due(5_900, here))
|
||
|
|
assertTrue(rules.due(6_001, here))
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `position, speed and heading changes trigger past their thresholds only`() {
|
||
|
|
val rules = sentAt(1_000)
|
||
|
|
// ~3.3 m north: under 4 m. ~5.6 m: over.
|
||
|
|
assertFalse(rules.due(2_000, here.copy(latitude = here.latitude + 0.00003)))
|
||
|
|
assertTrue(rules.due(2_000, here.copy(latitude = here.latitude + 0.00005)))
|
||
|
|
assertFalse(rules.due(2_000, here.copy(speedMps = 3.4)))
|
||
|
|
assertTrue(rules.due(2_000, here.copy(speedMps = 3.6)))
|
||
|
|
assertFalse(rules.due(2_000, here.copy(headingDeg = 93.0)))
|
||
|
|
assertTrue(rules.due(2_000, here.copy(headingDeg = 95.0)))
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `heading change is measured the short way round north`() {
|
||
|
|
val rules = sentAt(1_000, here.copy(headingDeg = 358.0))
|
||
|
|
assertFalse(rules.due(2_000, here.copy(headingDeg = 1.0))) // 3 degrees across north
|
||
|
|
assertTrue(rules.due(2_000, here.copy(headingDeg = 3.0))) // 5 degrees
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `the low-frequency container goes with the first VAM, then every T_GenVamLFMin`() {
|
||
|
|
val rules = VamGenerationRules()
|
||
|
|
assertTrue(rules.includeLowFrequency(0))
|
||
|
|
rules.onSent(0, here, withLowFrequency = true)
|
||
|
|
assertFalse(rules.includeLowFrequency(1_999))
|
||
|
|
assertTrue(rules.includeLowFrequency(2_000))
|
||
|
|
}
|
||
|
|
}
|