-
Notifications
You must be signed in to change notification settings - Fork 54
/
util_test.go
76 lines (70 loc) · 1.64 KB
/
util_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
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package rtcp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetPadding(t *testing.T) {
assert := assert.New(t)
type testCase struct {
input int
result int
}
cases := []testCase{
{input: 0, result: 0},
{input: 1, result: 3},
{input: 2, result: 2},
{input: 3, result: 1},
{input: 4, result: 0},
{input: 100, result: 0},
{input: 500, result: 0},
}
for _, testCase := range cases {
assert.Equalf(getPadding(testCase.input), testCase.result, "Test case returned wrong value for input %d", testCase.input)
}
}
func TestSetNBitsOfUint16(t *testing.T) {
for _, test := range []struct {
name string
source uint16
size uint16
index uint16
value uint16
result uint16
err string
}{
{
"setOneBit", 0, 1, 8, 1, 128, "",
},
{
"setStatusVectorBit", 0, 1, 0, 1, 32768, "",
},
{
"setStatusVectorSecondBit", 32768, 1, 1, 1, 49152, "",
},
{
"setStatusVectorInnerBitsAndCutValue", 49152, 2, 6, 11111, 49920, "",
},
{
"setRunLengthSecondTwoBit", 32768, 2, 1, 1, 40960, "",
},
{
"setOneBitOutOfBounds", 32768, 2, 15, 1, 0, "invalid size or startIndex",
},
} {
test := test
t.Run(test.name, func(t *testing.T) {
got, err := setNBitsOfUint16(test.source, test.size, test.index, test.value)
if err != nil {
if err.Error() != test.err {
t.Fatalf("setNBitsOfUint16 %q : got = %v, want %v", test.name, err, test.err)
}
return
}
if got != test.result {
t.Fatalf("setNBitsOfUint16 %q : got = %v, want %v", test.name, got, test.result)
}
})
}
}