|
| 1 | +package com.evsuite.hardware |
| 2 | + |
| 3 | +import org.junit.Assert.assertEquals |
| 4 | +import org.junit.Assert.assertFalse |
| 5 | +import org.junit.Assert.assertTrue |
| 6 | +import org.junit.Test |
| 7 | + |
| 8 | +class VehicleSpeedScaleTest { |
| 9 | + |
| 10 | + @Test fun `SWI68 reports km per hour and is not converted again`() { |
| 11 | + assertTrue(VehicleSpeedScale.reportsKmh(FirmwareInfo.Gen.SWI68)) |
| 12 | + assertEquals(34.4f, VehicleSpeedScale.toKmh(34.4f, FirmwareInfo.Gen.SWI68), 0.001f) |
| 13 | + } |
| 14 | + |
| 15 | + @Test fun `an unproven generation keeps the specified conversion`() { |
| 16 | + FirmwareInfo.Gen.entries |
| 17 | + .filterNot { it == FirmwareInfo.Gen.SWI68 } |
| 18 | + .forEach { generation -> |
| 19 | + assertFalse("$generation is not proven", VehicleSpeedScale.reportsKmh(generation)) |
| 20 | + assertEquals( |
| 21 | + "$generation must keep the AAOS conversion", |
| 22 | + 36.0f, |
| 23 | + VehicleSpeedScale.toKmh(10.0f, generation), |
| 24 | + 0.001f, |
| 25 | + ) |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + @Test fun `reverse is a speed, not a negative one`() { |
| 30 | + assertEquals(12.0f, VehicleSpeedScale.toKmh(-12.0f, FirmwareInfo.Gen.SWI68), 0.001f) |
| 31 | + assertEquals(36.0f, VehicleSpeedScale.toKmh(-10.0f, FirmwareInfo.Gen.SWI69), 0.001f) |
| 32 | + } |
| 33 | + |
| 34 | + @Test fun `the drive that proved it now integrates to the route it followed`() { |
| 35 | + // The recorded trip: 245836 ms at a steady 34.4 km/h reads as 2.35 km, not 8.46 km. |
| 36 | + val hours = 245_836L / 3_600_000.0 |
| 37 | + val kmh = VehicleSpeedScale.toKmh(34.4f, FirmwareInfo.Gen.SWI68) |
| 38 | + assertEquals(2.35, kmh * hours, 0.02) |
| 39 | + } |
| 40 | + |
| 41 | + @Test fun `standstill stays standstill in every generation`() { |
| 42 | + FirmwareInfo.Gen.entries.forEach { |
| 43 | + assertEquals(0.0f, VehicleSpeedScale.toKmh(0.0f, it), 0.0f) |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments