Convert test data sources to typed TheoryData

Replace untyped MemberData sources with TheoryData<...>, use collection
expressions for array and list literals, drop redundant casts and null
suppressions, and give log-assertion helpers an IsEnabled setup so guarded
log calls stay verifiable.
This commit is contained in:
2026-11-29 21:42:41 +02:00
parent ada3c77778
commit 17774b40b8
31 changed files with 649 additions and 693 deletions
@@ -13,28 +13,28 @@ public class HumidityRateCalculatorTests
private DateTimeOffset Now => _timeProvider.GetUtcNow();
public static IEnumerable<object[]> RateCases =>
[
["no readings", 5, Array.Empty<double>(), Array.Empty<int>(), 0.0],
["single reading", 5, new[] { 52.9 }, new[] { 0 }, 0.0],
["rising humidity", 5, new[] { 52.9, 62.9 }, new[] { 0, 60 }, 10.0],
["falling humidity", 5, new[] { 62.9, 52.9 }, new[] { 0, 120 }, -5.0],
["same timestamp", 5, new[] { 52.9, 62.9 }, new[] { 0, 0 }, 0.0],
["flat humidity", 5, new[] { 55.0, 55.0, 55.0 }, new[] { 0, 60, 120 }, 0.0],
["linear three readings", 5, new[] { 50.0, 55.0, 60.0 }, new[] { 0, 60, 120 }, 5.0],
["window drops stalest reading", 3, new[] { 52.9, 57.9, 62.9, 64.9 }, new[] { 0, 60, 120, 180 }, 3.5],
["window keeps only last two readings", 2, new[] { 50.0, 55.0, 60.0 }, new[] { 0, 60, 120 }, 5.0],
["single-sample window always returns zero", 1, new[] { 50.0, 55.0, 60.0 }, new[] { 0, 60, 120 }, 0.0],
["zero-sized window always returns zero", 0, new[] { 50.0, 55.0, 60.0 }, new[] { 0, 60, 120 }, 0.0],
["gap larger than window", 5, new[] { 20.0, 26.0 }, new[] { 0, 3_600 }, 0.1],
["out of order timestamps", 5, new[] { 60.0, 50.0 }, new[] { 120, 0 }, 0.0],
["very large rise", 5, new[] { 0.0, 10_000.0 }, new[] { 0, 60 }, 10_000.0],
["negative humidity values", 5, new[] { -20.0, 0.0 }, new[] { 0, 60 }, 20.0],
["tiny rise", 5, new[] { 50.0, 50.001 }, new[] { 0, 60 }, 0.001],
["shower spike over sixty seconds", 5, new[] { 52.9, 59.9, 64.9 }, new[] { 0, 30, 60 }, 12.0],
["middle readings do not affect the window endpoints", 3, new[] { 40.0, 80.0, 60.0, 45.0 }, new[] { 0, 30, 60, 90 }, -35.0],
["small change over fifteen minutes", 5, new[] { 50.0, 50.6 }, new[] { 0, 900 }, 0.04]
];
public static TheoryData<string, int, double[], int[], double> RateCases => new()
{
{ "no readings", 5, Array.Empty<double>(), Array.Empty<int>(), 0.0 },
{ "single reading", 5, [52.9], [0], 0.0 },
{ "rising humidity", 5, [52.9, 62.9], [0, 60], 10.0 },
{ "falling humidity", 5, [62.9, 52.9], [0, 120], -5.0 },
{ "same timestamp", 5, [52.9, 62.9], [0, 0], 0.0 },
{ "flat humidity", 5, [55.0, 55.0, 55.0], [0, 60, 120], 0.0 },
{ "linear three readings", 5, [50.0, 55.0, 60.0], [0, 60, 120], 5.0 },
{ "window drops stalest reading", 3, [52.9, 57.9, 62.9, 64.9], [0, 60, 120, 180], 3.5 },
{ "window keeps only last two readings", 2, [50.0, 55.0, 60.0], [0, 60, 120], 5.0 },
{ "single-sample window always returns zero", 1, [50.0, 55.0, 60.0], [0, 60, 120], 0.0 },
{ "zero-sized window always returns zero", 0, [50.0, 55.0, 60.0], [0, 60, 120], 0.0 },
{ "gap larger than window", 5, [20.0, 26.0], [0, 3_600], 0.1 },
{ "out of order timestamps", 5, [60.0, 50.0], [120, 0], 0.0 },
{ "very large rise", 5, [0.0, 10_000.0], [0, 60], 10_000.0 },
{ "negative humidity values", 5, [-20.0, 0.0], [0, 60], 20.0 },
{ "tiny rise", 5, [50.0, 50.001], [0, 60], 0.001 },
{ "shower spike over sixty seconds", 5, [52.9, 59.9, 64.9], [0, 30, 60], 12.0 },
{ "middle readings do not affect the window endpoints", 3, [40.0, 80.0, 60.0, 45.0], [0, 30, 60, 90], -35.0 },
{ "small change over fifteen minutes", 5, [50.0, 50.6], [0, 900], 0.04 }
};
[Theory]
[MemberData(nameof(RateCases))]