forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite_test.go
77 lines (68 loc) · 1.6 KB
/
site_test.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package core
import (
"testing"
"github.com/evcc-io/evcc/util"
)
func TestSitePower(t *testing.T) {
tc := []struct {
maxGrid, grid, battery, site float64
}{
// {0, 0, 0, 0}, // silent night
// {0, 0, 1, 1}, // battery discharging
// {0, 0, -1, -1}, // battery charging -> negative result cannot occur in reality
// {0, 1, 0, 1}, // grid import
// {0, 1, 1, 2}, // grid import + battery discharging
// {0, -1, 0, -1}, // grid export
// {0, -1, -1, -2}, // grid export + battery charging
{0, 1, -1, 0}, // grid import + battery charging -> should not happen
{0.5, 1, -1, 1}, // grid import + DC battery charging
}
log := util.NewLogger("foo")
for _, tc := range tc {
res := sitePower(log, tc.maxGrid, tc.grid, tc.battery, 0)
if res != tc.site {
t.Errorf("sitePower wanted %.f, got %.f", tc.site, res)
}
}
}
func TestGreenShare(t *testing.T) {
tc := []struct {
title string
grid, pv, battery float64
share float64
}{
{"half grid, half pv",
2500, 2500, 0,
0.5},
{"full pv",
0, 5000, 0,
1},
{"full grid",
5000, 0, 0,
0},
{"half grid, half battery",
2500, 0, 2500,
0.5},
{"full pv, pv export",
-5000, 10000, 0,
1},
{"full pv, pv export, battery charge",
-2500, 10000, -2500,
1},
{"double charge speed, full grid",
10000, 0, 0,
0},
}
for _, tc := range tc {
t.Logf("%+v", tc)
s := &Site{
gridPower: tc.grid,
pvPower: tc.pv,
batteryPower: tc.battery,
}
share := s.greenShare()
if share != tc.share {
t.Errorf("greenShare wanted %.f, got %.f", tc.share, share)
}
}
}