Repository navigation
Expand file tree
/
Copy pathlive_load_test.go
More file actions
61 lines (55 loc) · 1.8 KB
/
Copy pathlive_load_test.go
File metadata and controls
61 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mpc
import (
"math"
"testing"
"github.com/srcfl/ftw/go/internal/telemetry"
)
func TestOverlayLiveHouseLoadOnCurrentSlot(t *testing.T) {
slots := []Slot{{LoadW: 3987}, {LoadW: 2470}}
overlayLiveHouseLoad(slots, 480, true)
if math.Abs(slots[0].LoadW-480) > 1e-9 {
t.Fatalf("current slot load = %v, want live 480", slots[0].LoadW)
}
if slots[1].LoadW != 2470 {
t.Fatalf("later slot was painted with now: %v", slots[1].LoadW)
}
}
func TestOverlayLiveHouseLoadKeepsModelWhenMeterStale(t *testing.T) {
slots := []Slot{{LoadW: 3987}}
overlayLiveHouseLoad(slots, 480, false)
if slots[0].LoadW != 3987 {
t.Fatalf("stale meter overwrote the model: %v", slots[0].LoadW)
}
}
func TestOverlayLiveHouseLoadDoesNotGoNegative(t *testing.T) {
slots := []Slot{{LoadW: 4000}}
overlayLiveHouseLoad(slots, -200, true)
if slots[0].LoadW != 0 {
t.Fatalf("negative overlay = %v, want 0", slots[0].LoadW)
}
}
func TestLiveHouseLoadWMatchesHouseOnlyIdentity(t *testing.T) {
store := telemetry.NewStore()
soc := 0.5
store.Update("meter", telemetry.DerMeter, 100, nil, nil)
store.Update("pv", telemetry.DerPV, -800, nil, nil)
store.Update("sungrow", telemetry.DerBattery, 200, &soc, nil)
store.Update("easee", telemetry.DerEV, 0, nil, nil)
store.DriverHealthMut("meter").RecordSuccess()
store.DriverHealthMut("pv").RecordSuccess()
store.DriverHealthMut("sungrow").RecordSuccess()
store.DriverHealthMut("easee").RecordSuccess()
s := &Service{Tele: store, SiteMeter: "meter"}
got, ok := s.liveHouseLoadW()
if !ok {
t.Fatal("live meter reported missing")
}
// grid 100 − pv (−800) − bat 200 − ev 0 = 700
if math.Abs(got-700) > 1e-9 {
t.Fatalf("house load = %v, want 700", got)
}
store.DriverHealthMut("meter").SetOffline()
if _, ok := s.liveHouseLoadW(); ok {
t.Fatal("offline meter still overlaid")
}
}