-
Notifications
You must be signed in to change notification settings - Fork 1
/
packet_test.go
110 lines (95 loc) · 2.29 KB
/
packet_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* OpenBCI golang server allows users to control, visualize and store data
collected from the OpenBCI microcontroller.
Copyright (C) 2015 Kevin Schiesser
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"testing"
)
type test16pair struct {
data []byte
result int16
}
var tests16 = []test16pair{
{[]byte{0, 0}, 0},
{[]byte{255, 255}, -1},
{[]byte{128, 0}, -32768},
{[]byte{127, 255}, 32767},
}
func TestConvert16bitTo32bit(t *testing.T) {
for _, pair := range tests16 {
res := convert16bitTo32bit(pair.data)
if res != pair.result {
t.Error(
"For", pair.data,
"expected", pair.result,
"got", res,
)
}
}
}
type testscalepair struct {
data int32
result float64
}
var testsscale = []testscalepair{
{0, 0},
{8388607, 187500},
{-8388607, -187500},
}
//TODO:Test differnt gain factors
func TestScale(t *testing.T) {
for _, pair := range testsscale {
res := scaleToMicroVolts(pair.data, 24)
if res != pair.result {
t.Error(
"For", pair.data,
"expected", pair.result,
"got", res,
)
}
}
}
type testdiffpair struct {
x, y uint8
result uint8
}
var testsdiff = []testdiffpair{
{255, 254, 1},
{0, 255, 1},
{0, 0, 255},
{5, 1, 4},
{5, 255, 6},
}
func TestDifference(t *testing.T) {
for _, pair := range testsdiff {
res := difference(pair.x, pair.y)
if res != pair.result {
t.Error(
"For x", pair.x, "and y", pair.y,
"expected", pair.result,
"got", res,
)
}
}
}
func TestNewPacket(t *testing.T) {
p := NewPacket()
if p.header != '\xa0' || p.footer != '\xc0' {
t.Error(
"For packet header and packet footer",
"expected \xa0 and \xc0",
"got", p.header, "and", p.footer,
)
}
}