App 2.20.0: lease mileage allowance on the Overview

Vehicle info shows the km allowed by today (40,000 km over four years
from 2023-05-01, evenly per day) and the odometer against it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
2026-10-23 22:24:52 +02:00
co-authored by Claude Opus 5.5
parent 71aceaa626
commit 2931b1feed
9 changed files with 118 additions and 5 deletions
@@ -0,0 +1,36 @@
package com.evsuite.abrp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.time.LocalDate;
import org.junit.Test;
/** The lease mileage allowance — pure JVM. */
public class LeaseAllowanceTest {
@Test
public void accruesEvenlyPerDay() {
assertEquals(0d, LeaseAllowance.allowedKm(LocalDate.of(2023, 5, 1)), 1e-9);
// 731 of 1461 days (2024 is a leap year).
assertEquals(40_000d * 731 / 1461, LeaseAllowance.allowedKm(LocalDate.of(2025, 5, 1)), 1e-9);
assertEquals(40_000d, LeaseAllowance.allowedKm(LocalDate.of(2027, 5, 1)), 1e-9);
}
@Test
public void staysWithinTheLease() {
assertEquals(0d, LeaseAllowance.allowedKm(LocalDate.of(2023, 1, 1)), 1e-9);
assertEquals(40_000d, LeaseAllowance.allowedKm(LocalDate.of(2028, 1, 1)), 1e-9);
}
@Test
public void differenceIsOverPositiveUnderNegative() {
LocalDate day = LocalDate.of(2025, 5, 1);
double allowed = LeaseAllowance.allowedKm(day);
assertEquals(1000d, LeaseAllowance.differenceKm((float) (allowed + 1000), day), 0.01);
assertEquals(-500d, LeaseAllowance.differenceKm((float) (allowed - 500), day), 0.01);
assertNull(LeaseAllowance.differenceKm(null, day));
assertNull(LeaseAllowance.differenceKm(Float.NaN, day));
}
}