38 lines
1.6 KiB
Kotlin
38 lines
1.6 KiB
Kotlin
package com.hawhamburg.micr0bu
|
|||
|
|
|
||
|
|
import com.hawhamburg.micr0bu.domain.cam.CamParser
|
||
|
|
import com.hawhamburg.micr0bu.domain.cam.ObuGnssParser
|
||
|
|
import org.junit.Assert.assertEquals
|
||
|
|
import org.junit.Assert.assertNull
|
||
|
|
import org.junit.Test
|
||
|
|
|
||
|
|
/**
|
||
|
|
* [com.hawhamburg.micr0bu.domain.cam.Cam.yawRateDps] is positive clockwise. The CiT One's CAM topic
|
||
|
|
* is positive to the left (documented, and 316 of 316 turning samples in the logged runs), so
|
||
|
|
* [CamParser] flips it. Its `obu_gnss` topic is documented as left-positive too, but the logs show
|
||
|
|
* it positive to the right (27 of 27), so [ObuGnssParser] keeps it.
|
||
|
|
*/
|
||
|
|
class YawRateJsonSignTest {
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `CAM topic - positive is a left turn, so it becomes negative`() {
|
||
|
|
val json = """{"stationID": 42, "stationType": 5, "latitude": 53.55, "longitude": 10.02,
|
||
|
|
"yawRate_dps": 15.0}"""
|
||
|
|
assertEquals(-15.0, CamParser.parse(json, ownStationId = null)!!.yawRateDps!!, 1e-9)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `CAM topic - a missing yaw rate stays unavailable`() {
|
||
|
|
val json = """{"stationID": 42, "stationType": 5, "latitude": 53.55, "longitude": 10.02}"""
|
||
|
|
assertNull(CamParser.parse(json, ownStationId = null)!!.yawRateDps)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Test
|
||
|
|
fun `obu_gnss - yawRate_degps is read as it is, since the CiT One sends it right-positive`() {
|
||
|
|
// own_info as in Listing 2.1, with the position placed where this parser reads it.
|
||
|
|
val json = """{"own_info": {"stationID": 1345678, "stationType": 2,
|
||
|
|
"latitude": 53.55, "longitude": 10.02, "yawRate_degps": -7.5}}"""
|
||
|
|
assertEquals(-7.5, ObuGnssParser.parseEgo(json)!!.yawRateDps!!, 1e-9)
|
||
|
|
}
|
||
|
|
}
|