Test Failed
Push — master ( 1b19dc...4e0cc6 )
by Nikita
01:45
created

encode/Integer_test.go   A

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 37
dl 0
loc 54
rs 10
c 0
b 0
f 0
1
package encode
2
3
import (
4
	"testing"
5
6
	"github.com/et-nik/binngo/binn"
7
	"github.com/stretchr/testify/assert"
8
)
9
10
func TestIntPack(t *testing.T) {
11
	tests := []struct {
12
		name         string
13
		int          int
14
		sizeExpected int
15
		binExpected  []byte
16
	}{
17
		{
18
			"int8 compressed",
19
			123,
20
			2,
21
			[]byte{binn.Uint8Type, 123},
22
		},
23
		{
24
			"int16 compressed",
25
			789,
26
			3,
27
			[]byte{binn.Uint16Type, 0x03, 0x15},
28
		},
29
		{
30
			"int16",
31
			-12345,
32
			3,
33
			[]byte{binn.Int16Type, 0xcf, 0xc7},
34
		},
35
		{
36
			"int32",
37
			-12345678,
38
			5,
39
			[]byte{binn.Int32Type, 0xff, 0x43, 0x9e, 0xb2},
40
		},
41
		{
42
			"uint64",
43
			9223372036854775806,
44
			9,
45
			[]byte{binn.Uint64Type, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
46
		},
47
	}
48
49
	for _, test := range tests {
50
		t.Run(test.name, func(t *testing.T) {
51
			b, err := Marshal(test.int)
52
53
			assert.Nil(t, err)
54
			assert.Equal(t, test.binExpected, b)
55
		})
56
	}
57
}
58