-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket_test.go
63 lines (50 loc) · 1.17 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
package afec
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPacket(t *testing.T) {
var mk uint8 = 0b10000000
{
var p = Pack(make([]byte, MiniPackSize))
p.setDataType()
p.setGlen(3)
require.Equal(t, p[3], mk+(uint8(1)<<6)+3)
require.Equal(t, true, p.isDataType())
require.Equal(t, uint8(3), p.glen())
}
{
var p = Pack(make([]byte, MiniPackSize))
p.setGlen(3)
p.setDataType()
require.Equal(t, p[3], mk+(uint8(1)<<6)+3)
require.Equal(t, true, p.isDataType())
require.Equal(t, uint8(3), p.glen())
}
{
var p = Pack(make([]byte, MiniPackSize))
p.setDataType()
p.setGlen(3)
p.setGlen(7)
require.Equal(t, p[3], mk+(uint8(1)<<6)+7)
require.Equal(t, true, p.isDataType())
require.Equal(t, uint8(7), p.glen())
}
{
var p = Pack(make([]byte, MiniPackSize))
p.setGlen(3)
p.setDataType()
p.setGlen(7)
p.setParityType()
require.Equal(t, p[3], mk+(uint8(0)<<6)+7)
require.Equal(t, false, p.isDataType())
require.Equal(t, uint8(7), p.glen())
}
{
var p = Pack(make([]byte, MiniPackSize))
p.setGid(111)
p.setPL(0.082)
require.Equal(t, uint8(111), p.gid())
require.InDelta(t, 0.082, p.pl().get(), prec)
}
}