chore: modernize
This commit is contained in:
parent
f08fa0c6be
commit
0eca536c9e
1 changed files with 8 additions and 10 deletions
|
|
@ -36,8 +36,6 @@ func TestCollectorAddEnergy(t *testing.T) {
|
|||
require.Equal(t, 0.0, col.accu.Imported()) // accumulator reset after 15 minutes
|
||||
}
|
||||
|
||||
func f(v float64) *float64 { return &v }
|
||||
|
||||
func TestCollectorAddEnergyWithImportMeter(t *testing.T) {
|
||||
clock := clock.NewMock()
|
||||
|
||||
|
|
@ -49,17 +47,17 @@ func TestCollectorAddEnergyWithImportMeter(t *testing.T) {
|
|||
|
||||
// first call: seeds meter, no delta yet
|
||||
clock.Add(5 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(50000), nil, 1e3))
|
||||
require.NoError(t, col.AddEnergy(new(50000.0), nil, 1e3))
|
||||
require.Equal(t, 0.0, col.accu.Imported())
|
||||
|
||||
// second call: meter delta of 0.5 kWh, power ignored for import
|
||||
clock.Add(5 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(50000.5), nil, 1e3))
|
||||
require.NoError(t, col.AddEnergy(new(50000.5), nil, 1e3))
|
||||
require.Equal(t, 0.5, col.accu.Imported())
|
||||
|
||||
// implausible reading (decreased): ignored by guard
|
||||
clock.Add(5 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(49000), nil, 1e3))
|
||||
require.NoError(t, col.AddEnergy(new(49000.0), nil, 1e3))
|
||||
require.Equal(t, 0.0, col.accu.Imported()) // reset at slot boundary
|
||||
}
|
||||
|
||||
|
|
@ -74,17 +72,17 @@ func TestCollectorAddEnergyWithImportMeterAndExport(t *testing.T) {
|
|||
|
||||
// seed import meter
|
||||
clock.Add(3 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(1000), nil, 0))
|
||||
require.NoError(t, col.AddEnergy(new(1000.0), nil, 0))
|
||||
|
||||
// positive power: import via meter delta, no export
|
||||
clock.Add(3 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(1000.3), nil, 500))
|
||||
require.NoError(t, col.AddEnergy(new(1000.3), nil, 500))
|
||||
require.InDelta(t, 0.3, col.accu.Imported(), 1e-10)
|
||||
require.Equal(t, 0.0, col.accu.Exported())
|
||||
|
||||
// negative power: import via meter (no change), export via power integration
|
||||
clock.Add(3 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(1000.3), nil, -600))
|
||||
require.NoError(t, col.AddEnergy(new(1000.3), nil, -600))
|
||||
require.InDelta(t, 0.3, col.accu.Imported(), 1e-10)
|
||||
require.InDelta(t, 600.0*3/60/1e3, col.accu.Exported(), 1e-10) // 0.03 kWh
|
||||
}
|
||||
|
|
@ -100,11 +98,11 @@ func TestCollectorAddEnergyWithBothMeters(t *testing.T) {
|
|||
|
||||
// seed both meters
|
||||
clock.Add(3 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(1000), f(2000), 0))
|
||||
require.NoError(t, col.AddEnergy(new(1000.0), new(2000.0), 0))
|
||||
|
||||
// both deltas used, power ignored
|
||||
clock.Add(3 * time.Minute)
|
||||
require.NoError(t, col.AddEnergy(f(1000.3), f(2000.7), 999))
|
||||
require.NoError(t, col.AddEnergy(new(1000.3), new(2000.7), 999))
|
||||
require.InDelta(t, 0.3, col.accu.Imported(), 1e-10)
|
||||
require.InDelta(t, 0.7, col.accu.Exported(), 1e-10)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue