The car falls back to its own default mode at every start. With "Set at start" (on by default), the service sets the mode last chosen on Settings and confirmed by the car again, once, while the car is in P at 0 km/h, and gives up as soon as the car leaves P or after two minutes (DriveModeWrite.atStart, unit-tested). The buttons and the start share the write and read-back (DriveModeSetter). Not tried on the car. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
69 lines
3.2 KiB
Java
69 lines
3.2 KiB
Java
package com.evsuite.abrp;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import org.junit.Test;
|
|
|
|
/** The drive mode write's rules — pure JVM. */
|
|
public class DriveModeWriteTest {
|
|
|
|
@Test
|
|
public void onlyInPAtAStandstill() {
|
|
assertEquals(DriveModeWrite.Verdict.ALLOWED, DriveModeWrite.check(0f, 1));
|
|
assertEquals(DriveModeWrite.Verdict.NOT_IN_P, DriveModeWrite.check(0f, 4));
|
|
assertEquals(DriveModeWrite.Verdict.NOT_IN_P, DriveModeWrite.check(0f, 3));
|
|
assertEquals(DriveModeWrite.Verdict.NOT_IN_P, DriveModeWrite.check(30f, 2));
|
|
assertEquals(DriveModeWrite.Verdict.MOVING, DriveModeWrite.check(0.5f, 1));
|
|
}
|
|
|
|
@Test
|
|
public void unreadableIsRefused() {
|
|
assertEquals(DriveModeWrite.Verdict.UNREADABLE, DriveModeWrite.check(null, 1));
|
|
assertEquals(DriveModeWrite.Verdict.UNREADABLE, DriveModeWrite.check(0f, null));
|
|
assertEquals(DriveModeWrite.Verdict.UNREADABLE, DriveModeWrite.check(Float.NaN, 1));
|
|
assertEquals(DriveModeWrite.Verdict.UNREADABLE, DriveModeWrite.check(-1f, 1));
|
|
}
|
|
|
|
@Test
|
|
public void resultIsWhatTheCarReports() {
|
|
assertEquals(DriveModeWrite.Outcome.APPLIED, DriveModeWrite.outcome(4, 4));
|
|
assertEquals(DriveModeWrite.Outcome.NOT_APPLIED, DriveModeWrite.outcome(4, 2));
|
|
assertEquals(DriveModeWrite.Outcome.UNREAD, DriveModeWrite.outcome(4, null));
|
|
}
|
|
|
|
@Test
|
|
public void atStartWritesOnceTheChosenModeInP() {
|
|
assertEquals(DriveModeWrite.StartStep.WRITE, DriveModeWrite.atStart(4, true, 1, 0f, 2, 5_000));
|
|
assertEquals(DriveModeWrite.StartStep.ALREADY, DriveModeWrite.atStart(4, true, 1, 0f, 4, 5_000));
|
|
}
|
|
|
|
@Test
|
|
public void atStartWaitsForReadings() {
|
|
assertEquals(DriveModeWrite.StartStep.WAIT, DriveModeWrite.atStart(4, true, null, 0f, 2, 1_000));
|
|
assertEquals(DriveModeWrite.StartStep.WAIT, DriveModeWrite.atStart(4, true, 1, null, 2, 1_000));
|
|
assertEquals(DriveModeWrite.StartStep.WAIT, DriveModeWrite.atStart(4, true, 1, 0f, null, 1_000));
|
|
}
|
|
|
|
@Test
|
|
public void atStartGivesUp() {
|
|
// Nothing chosen (or a code not offered), switched off, too late.
|
|
assertEquals(DriveModeWrite.StartStep.GIVE_UP, DriveModeWrite.atStart(null, true, 1, 0f, 2, 1_000));
|
|
assertEquals(DriveModeWrite.StartStep.GIVE_UP, DriveModeWrite.atStart(5, true, 1, 0f, 2, 1_000));
|
|
assertEquals(DriveModeWrite.StartStep.GIVE_UP, DriveModeWrite.atStart(4, false, 1, 0f, 2, 1_000));
|
|
assertEquals(DriveModeWrite.StartStep.GIVE_UP,
|
|
DriveModeWrite.atStart(4, true, 1, 0f, 2, DriveModeWrite.START_WINDOW_MS + 1));
|
|
// Driven off: out of P, or moving.
|
|
assertEquals(DriveModeWrite.StartStep.GIVE_UP, DriveModeWrite.atStart(4, true, 4, 0f, 2, 1_000));
|
|
assertEquals(DriveModeWrite.StartStep.GIVE_UP, DriveModeWrite.atStart(4, true, 1, 3f, 2, 1_000));
|
|
}
|
|
|
|
@Test
|
|
public void buttonsByCode() {
|
|
assertEquals(0, DriveModeWrite.indexOf(2));
|
|
assertEquals(2, DriveModeWrite.indexOf(4));
|
|
assertEquals(4, DriveModeWrite.indexOf(7));
|
|
assertEquals(-1, DriveModeWrite.indexOf(5));
|
|
assertEquals(-1, DriveModeWrite.indexOf(null));
|
|
}
|
|
}
|