forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadpoint_effective_test.go
70 lines (59 loc) · 2.13 KB
/
loadpoint_effective_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
package core
import (
"testing"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
func TestEffectiveLimitSoc(t *testing.T) {
lp := NewLoadpoint(util.NewLogger("foo"), nil)
assert.Equal(t, 100, lp.effectiveLimitSoc())
}
func TestEffectiveMinMaxCurrent(t *testing.T) {
tc := []struct {
chargerMin, chargerMax float64
vehicleMin, vehicleMax float64
effectiveMin, effectiveMax float64
}{
{0, 0, 0, 0, 6, 16},
{2, 0, 0, 0, 2, 16}, // charger min lower, max empty - charger wins
{7, 0, 0, 0, 7, 16}, // charger min higher, max empty (no practical use)
{0, 10, 0, 0, 6, 10}, // charger max lower, min empty - loadpoint wins
{0, 20, 0, 0, 6, 16}, // charger max higher, min empty - loadpoint wins
{0, 0, 5, 0, 6, 16}, // vehicle min lower, max empty - loadpoint wins
{0, 0, 8, 0, 8, 16}, // vehicle min higher, max empty - vehicle wins
{0, 0, 0, 10, 6, 10}, // vehicle max lower, min empty - vehicle wins
{0, 0, 0, 20, 6, 16}, // vehicle max higher, min empty - loadpoint wins
{2, 0, 5, 0, 5, 16}, // charger + vehicle min lower, max empty - vehicle wins
{0, 20, 0, 32, 6, 16}, // charger + vehicle max higher, min empty - loadpoint wins
}
for _, tc := range tc {
t.Logf("%+v", tc)
ctrl := gomock.NewController(t)
lp := NewLoadpoint(util.NewLogger("foo"), nil)
lp.charger = api.NewMockCharger(ctrl)
if tc.chargerMin+tc.chargerMax > 0 {
currentLimiter := api.NewMockCurrentLimiter(ctrl)
currentLimiter.EXPECT().GetMinMaxCurrent().Return(tc.chargerMin, tc.chargerMax, nil).AnyTimes()
lp.charger = struct {
api.Charger
api.CurrentLimiter
}{
Charger: lp.charger,
CurrentLimiter: currentLimiter,
}
}
if tc.vehicleMin+tc.vehicleMax > 0 {
vehicle := api.NewMockVehicle(ctrl)
ac := api.ActionConfig{
MinCurrent: tc.vehicleMin,
MaxCurrent: tc.vehicleMax,
}
vehicle.EXPECT().OnIdentified().Return(ac).AnyTimes()
lp.vehicle = vehicle
}
assert.Equal(t, tc.effectiveMin, lp.effectiveMinCurrent(), "min")
assert.Equal(t, tc.effectiveMax, lp.effectiveMaxCurrent(), "max")
}
}