Apply code formatting cleanup across monitor projects
- Reindent appsettings.json and the MSBuild project files - Collapse single-statement guard blocks and tidy using and member order - Normalize XML doc indentation and file endings - Reorder BatteryMonitor test-data helpers and move the exclusion tests into their own region - Carry the same formatting through the boiler config, control, entity and test files
This commit is contained in:
@@ -6,21 +6,24 @@ using ShowerMonitorManager.Models;
|
||||
namespace ShowerMonitor.Manager.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Shared, deterministic fixtures for the shower monitor tests.
|
||||
/// Keeping options, fan states and sample series here avoids copy-pasted setup
|
||||
/// across test classes and keeps every timestamp independent of the wall clock.
|
||||
/// Shared, deterministic fixtures for the shower monitor tests.
|
||||
/// Keeping options, fan states and sample series here avoids copy-pasted setup
|
||||
/// across test classes and keeps every timestamp independent of the wall clock.
|
||||
/// </summary>
|
||||
internal static class ShowerMonitorTestData
|
||||
{
|
||||
/// <summary>Fixed base time used by all timestamp-sensitive tests.</summary>
|
||||
private static readonly DateTimeOffset BaseTimestamp = new(2026, 1, 15, 12, 0, 0, TimeSpan.Zero);
|
||||
|
||||
/// <summary>Creates a fake clock positioned at <see cref="BaseTimestamp"/> unless overridden.</summary>
|
||||
public static FakeTimeProvider CreateTimeProvider(DateTimeOffset? start = null) => new(start ?? BaseTimestamp);
|
||||
/// <summary>Creates a fake clock positioned at <see cref="BaseTimestamp" /> unless overridden.</summary>
|
||||
public static FakeTimeProvider CreateTimeProvider(DateTimeOffset? start = null)
|
||||
{
|
||||
return new FakeTimeProvider(start ?? BaseTimestamp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds monitor options from the production defaults, overriding only the
|
||||
/// values a test cares about.
|
||||
/// Builds monitor options from the production defaults, overriding only the
|
||||
/// values a test cares about.
|
||||
/// </summary>
|
||||
public static ShowerMonitorOptions CreateOptions(
|
||||
string exhaustFanEntityId = ShowerMonitorConsts.ExhaustFanEntityId,
|
||||
@@ -37,40 +40,53 @@ internal static class ShowerMonitorTestData
|
||||
{
|
||||
ExhaustFanEntityId = exhaustFanEntityId,
|
||||
FanRunAfterShowerMinutes = fanRunAfterShowerMinutes
|
||||
?? (int)ShowerMonitorConsts.DefaultFanRunAfterShower.TotalMinutes,
|
||||
?? (int)ShowerMonitorConsts.DefaultFanRunAfterShower.TotalMinutes,
|
||||
SpikeRateThreshold = spikeRateThreshold,
|
||||
MinDifferentialHumidity = minDifferentialHumidity,
|
||||
PeakHumidityThreshold = peakHumidityThreshold,
|
||||
ConfirmationWindowMinutes = confirmationWindowMinutes,
|
||||
RecoveryDifferentialThreshold = recoveryDifferentialThreshold,
|
||||
MaxShowerDurationMinutes = maxShowerDurationMinutes
|
||||
?? (int)ShowerMonitorConsts.DefaultMaxShowerDuration.TotalMinutes,
|
||||
?? (int)ShowerMonitorConsts.DefaultMaxShowerDuration.TotalMinutes,
|
||||
RateWindowSize = rateWindowSize
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Creates the HA state payload for the exhaust fan.</summary>
|
||||
public static EntityState FanState(string? state) => new() { State = state };
|
||||
|
||||
/// <summary>A humidity sample with its offset from a test's base timestamp.</summary>
|
||||
public readonly record struct HumiditySample(double Humidity, TimeSpan Offset);
|
||||
public static EntityState FanState(string? state)
|
||||
{
|
||||
return new EntityState { State = state };
|
||||
}
|
||||
|
||||
/// <summary>Builds a sample series from (humidity, offset-in-seconds) pairs.</summary>
|
||||
public static IReadOnlyList<HumiditySample> CreateHumiditySeries(
|
||||
params (double Humidity, int OffsetSeconds)[] samples) =>
|
||||
[.. samples.Select(sample => new HumiditySample(sample.Humidity, TimeSpan.FromSeconds(sample.OffsetSeconds)))];
|
||||
params (double Humidity, int OffsetSeconds)[] samples)
|
||||
{
|
||||
return
|
||||
[
|
||||
.. samples.Select(sample => new HumiditySample(sample.Humidity, TimeSpan.FromSeconds(sample.OffsetSeconds)))
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates evenly spaced samples along a constant humidity slope, useful for
|
||||
/// exercising every window size against a known rate.
|
||||
/// Generates evenly spaced samples along a constant humidity slope, useful for
|
||||
/// exercising every window size against a known rate.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<HumiditySample> CreateLinearHumiditySeries(
|
||||
double startHumidity,
|
||||
double ratePerMinute,
|
||||
int sampleCount,
|
||||
int intervalSeconds = 60) =>
|
||||
[.. Enumerable.Range(0, sampleCount)
|
||||
.Select(i => new HumiditySample(
|
||||
startHumidity + ratePerMinute * i * intervalSeconds / 60.0,
|
||||
TimeSpan.FromSeconds(i * intervalSeconds)))];
|
||||
}
|
||||
int intervalSeconds = 60)
|
||||
{
|
||||
return
|
||||
[
|
||||
.. Enumerable.Range(0, sampleCount)
|
||||
.Select(i => new HumiditySample(
|
||||
startHumidity + ratePerMinute * i * intervalSeconds / 60.0,
|
||||
TimeSpan.FromSeconds(i * intervalSeconds)))
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>A humidity sample with its offset from a test's base timestamp.</summary>
|
||||
public readonly record struct HumiditySample(double Humidity, TimeSpan Offset);
|
||||
}
|
||||
Reference in New Issue
Block a user