| Conditions | 3 |
| Total Lines | 45 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package encode |
||
| 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 | }) |
||
| 58 |