-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversion_test.go
64 lines (50 loc) · 1.15 KB
/
conversion_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
package toyls
import . "gopkg.in/check.v1"
func (s *ToySuite) TestExtractUint16(c *C) {
data := []byte{
0x12, 0x34, 0x45,
}
n, p := extractUint16(data)
c.Assert(n, Equals, uint16(0x1234))
c.Assert(p, DeepEquals, data[2:])
}
func (s *ToySuite) TestExtractUint24(c *C) {
data := []byte{
0x12, 0x34, 0x56, 0x78,
}
n, p := extractUint24(data)
c.Assert(n, Equals, uint32(0x123456))
c.Assert(p, DeepEquals, data[3:])
}
func (s *ToySuite) TestExtractUint32(c *C) {
data := []byte{
0x12, 0x34, 0x56, 0x78, 0x90,
}
n, p := extractUint32(data)
c.Assert(n, Equals, uint32(0x12345678))
c.Assert(p, DeepEquals, data[4:])
}
func (s *ToySuite) TestWriteBytesFromUint16(c *C) {
n := uint16(0x1234)
b := writeBytesFromUint16(n)
exp := [2]byte{
0x12, 0x34,
}
c.Assert(b, DeepEquals, exp)
}
func (s *ToySuite) TestWriteBytesFromUint24(c *C) {
n := uint32(0x123456)
b := writeBytesFromUint24(n)
exp := [3]byte{
0x12, 0x34, 0x56,
}
c.Assert(b, DeepEquals, exp)
}
func (s *ToySuite) TestWriteBytesFromUint32(c *C) {
n := uint32(0x12345678)
exp := [4]byte{
0x12, 0x34, 0x56, 0x78,
}
b := writeBytesFromUint32(n)
c.Assert(b, DeepEquals, exp)
}