forked from pvainio/vallox-rs485
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vallox_test.go
56 lines (48 loc) · 1.42 KB
/
vallox_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
package valloxrs485
import (
"testing"
)
func TestOutGoingAllowed(t *testing.T) {
v := new(Vallox)
assertBoolean(true, isOutgoingAllowed(v, 0), t)
assertBoolean(false, isOutgoingAllowed(v, FanSpeed), t)
assertBoolean(false, isOutgoingAllowed(v, TempIncomingInside), t)
v.writeAllowed = true
assertBoolean(true, isOutgoingAllowed(v, 0), t)
assertBoolean(true, isOutgoingAllowed(v, FanSpeed), t)
assertBoolean(false, isOutgoingAllowed(v, TempIncomingInside), t)
}
func TestValueToTemp(t *testing.T) {
assertTemp(0, -74, t)
assertTemp(255, 100, t)
assertTemp(246, 97, t)
assertTemp(247, 100, t)
}
func TestValueToSpeed(t *testing.T) {
assertSpeed(1, 1, t)
assertSpeed(3, 2, t)
assertSpeed(7, 3, t)
assertSpeed(15, 4, t)
assertSpeed(31, 5, t)
assertSpeed(63, 6, t)
assertSpeed(127, 7, t)
assertSpeed(255, 8, t)
}
func assertBoolean(expected bool, value bool, t *testing.T) {
if expected != value {
t.Errorf("exptected %v got %v", expected, value)
}
}
func assertTemp(raw byte, value int8, t *testing.T) {
if c := valueToTemp(raw); c != value {
t.Errorf("temp %d was not converted to %d but to %d", raw, value, c)
}
}
func assertSpeed(raw byte, value int8, t *testing.T) {
if c := valueToSpeed(raw); c != value {
t.Errorf("raw %d to speed was not converted to %d but to %d", raw, value, c)
}
if c := speedToValue(value); c != raw {
t.Errorf("speed %d to raw was not converted to %d but to %d", value, raw, c)
}
}