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:
@@ -1,6 +1,5 @@
|
||||
using FluentAssertions;
|
||||
using PowerMonitorManager;
|
||||
using PowerMonitorManager.Models;
|
||||
using PowerMonitorManager.Models.Consts;
|
||||
|
||||
namespace PowerMonitor.Manager.Tests;
|
||||
@@ -17,18 +16,18 @@ public class PowerCostCalculationServiceTests
|
||||
|
||||
#region CalculateCostIncrement
|
||||
|
||||
public static IEnumerable<object[]> CostIncrementCases =>
|
||||
[
|
||||
["default polling interval", 341.97, 0.1791, 15, 0.0002551951125],
|
||||
["one kilowatt for one hour", 1000.0, 1.0, PowerMonitorConsts.SecondsPerHour, 1.0],
|
||||
["limit load for one minute", 5500.0, 0.25, 60, 0.0229166666666667],
|
||||
["very large load", 1_000_000.0, 0.5, 900, 125.0],
|
||||
["negative power", -500.0, 0.2, PowerMonitorConsts.SecondsPerHour, -0.1],
|
||||
["zero power", 0.0, 0.1791, 15, 0.0],
|
||||
["zero price", 341.97, 0.0, 15, 0.0],
|
||||
["zero interval", 1000.0, 0.2, 0, 0.0],
|
||||
["tiny values", 0.001, 0.0001, 1, 2.77777777777778e-14]
|
||||
];
|
||||
public static TheoryData<string, double, double, int, double> CostIncrementCases => new()
|
||||
{
|
||||
{ "default polling interval", 341.97, 0.1791, 15, 0.0002551951125 },
|
||||
{ "one kilowatt for one hour", 1000.0, 1.0, PowerMonitorConsts.SecondsPerHour, 1.0 },
|
||||
{ "limit load for one minute", 5500.0, 0.25, 60, 0.0229166666666667 },
|
||||
{ "very large load", 1_000_000.0, 0.5, 900, 125.0 },
|
||||
{ "negative power", -500.0, 0.2, PowerMonitorConsts.SecondsPerHour, -0.1 },
|
||||
{ "zero power", 0.0, 0.1791, 15, 0.0 },
|
||||
{ "zero price", 341.97, 0.0, 15, 0.0 },
|
||||
{ "zero interval", 1000.0, 0.2, 0, 0.0 },
|
||||
{ "tiny values", 0.001, 0.0001, 1, 2.77777777777778e-14 }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CostIncrementCases))]
|
||||
@@ -315,7 +314,7 @@ public class PowerCostCalculationServiceTests
|
||||
var timestamps = PowerMonitorTestData.CreateSampleTimestamps(PowerMonitorTestData.FixedDayStart, 96);
|
||||
var wattSamples = PowerMonitorTestData.CreatePowerSampleSeries(96);
|
||||
var expectedPerSlot = timestamps
|
||||
.Select((_, index) => ExpectedCost(wattSamples[index], pricePerKwh, PowerMonitorConsts.DefaultPollIntervalSeconds))
|
||||
.Select((_, index) => ExpectedCost(wattSamples[index], pricePerKwh))
|
||||
.ToArray();
|
||||
|
||||
// Act
|
||||
@@ -347,7 +346,7 @@ public class PowerCostCalculationServiceTests
|
||||
// Act
|
||||
foreach (var (start, pricePerKwh) in windows)
|
||||
{
|
||||
var watts = 500.0 + (start.Hour * 125.0);
|
||||
var watts = 500.0 + start.Hour * 125.0;
|
||||
var result = PowerMonitorTestData.CreateCalculation(
|
||||
totalWatts: watts,
|
||||
smoothedOtherWatts: watts / 4,
|
||||
|
||||
Reference in New Issue
Block a user