using MeterVault.Core.Domain; using MeterVault.Core.Normalization; using static MeterVault.Core.Tests.TestData; namespace MeterVault.Core.Tests; public sealed class RuntimeAndTankTests { private readonly INormalizationEngine _engine = NormalizationEngine.CreateDefault(); [Fact] public void Runtime_counter_multiplies_delta_hours_by_fixed_rate() { var ctx = new NormalizationContext { Meter = new MeterConfig { MeterId = 20, Mode = MeterMode.RuntimeCounter, Unit = "L", InitialBaseline = 7785, Tank = new TankConfig { Capacity = 7000, RateMode = TankRateMode.Fixed, FixedRate = 2.0 }, }, Readings = [Reading(20, Month(2023, 1), 7785), Reading(20, Month(2023, 2), 7952)], }; var result = _engine.Normalize(ctx); // Δhours: 0, then 167 × 2.0 L/h = 334 L. Assert.Equal([0d, 334d], result.Select(c => c.Amount)); } [Fact] public void Tank_consumption_is_level_delta_between_dipsticks() { // Linear calibration 7000 L / 150 cm ≈ 46.667 L/cm (SDD §2.4). var calibration = new CalibrationCurve(7000d / 150d); var ctx = new NormalizationContext { Meter = new MeterConfig { MeterId = 30, Mode = MeterMode.ConsumableBalance, Unit = "L", Tank = new TankConfig { Capacity = 7000, Calibration = calibration }, }, Events = [ Delivery(30, Month(2020, 9), 3500), // pre-first-level delivery: absorbed TankLevelCm(30, Month(2022, 9), 35), // first level: no consumption emitted TankLevelCm(30, Month(2022, 10), 34), // ~46.7 L drawn TankLevelCm(30, Month(2022, 11), 27), // ~326.7 L drawn ], }; var result = _engine.Normalize(ctx); Assert.Equal(2, result.Count); Assert.Equal(46.7, result[0].Amount, 1); Assert.Equal(326.7, result[1].Amount, 1); } [Fact] public void Delivery_between_dipsticks_reconciles_into_the_balance() { var calibration = new CalibrationCurve(7000d / 150d); var ctx = new NormalizationContext { Meter = new MeterConfig { MeterId = 30, Mode = MeterMode.ConsumableBalance, Unit = "L", Tank = new TankConfig { Capacity = 7000, Calibration = calibration }, }, Events = [ TankLevelCm(30, Month(2022, 9), 20), // 933.3 L Delivery(30, Month(2022, 10), 2000), TankLevelCm(30, Month(2022, 11), 50), // 2333.3 L ], }; var result = _engine.Normalize(ctx); // consumption = 933.3 + 2000 − 2333.3 = 600. Assert.Single(result); Assert.Equal(600d, result[0].Amount, 1); } }