-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttyReader_test.go
62 lines (47 loc) · 965 Bytes
/
ttyReader_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
package main
import (
"bufio"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDataParsing(t *testing.T) {
f, err := os.Open("./resources/test-data")
reader := bufio.NewReader(f)
readData, err := reader.ReadString('\x21')
if err != nil {
panic(err)
}
matches := matchData(readData)
assert.Len(t, matches, 48)
kwhMap := map[string]string{
"omis": "2.8.1",
"data": "795.989",
"unit": "kWh",
}
assert.Contains(t, matches, kwhMap)
kwMap := map[string]string{
"omis": "1.7.0",
"data": "0.348",
"unit": "kW",
}
assert.Contains(t, matches, kwMap)
kvarMap := map[string]string{
"omis": "4.7.0",
"data": "0.296",
"unit": "kvar",
}
assert.Contains(t, matches, kvarMap)
vMap := map[string]string{
"omis": "32.7",
"data": "232.4",
"unit": "V",
}
assert.Contains(t, matches, vMap)
aMap := map[string]string{
"omis": "31.7",
"data": "0.58",
"unit": "A",
}
assert.Contains(t, matches, aMap)
}