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
|
package sequencenumber
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsNewer(t *testing.T) {
cases := []struct {
a, b uint16
expected bool
}{
{
a: 1,
b: 0,
expected: true,
},
{
a: 65534,
b: 65535,
expected: false,
},
{
a: 65535,
b: 65535,
expected: false,
},
{
a: 0,
b: 65535,
expected: true,
},
{
a: 0,
b: 32767,
expected: false,
},
{
a: 32770,
b: 2,
expected: true,
},
{
a: 3,
b: 32770,
expected: false,
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
assert.Equalf(t, tc.expected, isNewer(tc.a, tc.b), "expected isNewer(%v, %v) to be %v", tc.a, tc.b, tc.expected)
})
}
}
func TestUnwrapper(t *testing.T) {
cases := []struct {
input []uint16
expected []int64
}{
{
input: []uint16{},
expected: []int64{},
},
{
input: []uint16{0, 1, 2, 3, 4},
expected: []int64{0, 1, 2, 3, 4},
},
{
input: []uint16{65534, 65535, 0, 1, 2},
expected: []int64{65534, 65535, 65536, 65537, 65538},
},
{
input: []uint16{32769, 0},
expected: []int64{32769, 65536},
},
{
input: []uint16{32767, 0},
expected: []int64{32767, 0},
},
{
input: []uint16{
0, 32767, 32768, 32769, 32770,
1, 2, 32765, 32770, 65535,
},
expected: []int64{
0, 32767, 32768, 32769, 32770,
65537, 65538, 98301, 98306, 131071,
},
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
u := &Unwrapper{}
result := []int64{}
for _, i := range tc.input {
result = append(result, u.Unwrap(i))
}
assert.Equal(t, tc.expected, result)
})
}
}
|