File: gcc_test.go

package info (click to toggle)
golang-github-pion-interceptor 0.1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports, forky, sid, trixie
  • size: 764 kB
  • sloc: makefile: 8
file content (120 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package gcc

import (
	"fmt"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestMinInt(t *testing.T) {
	tests := []struct {
		expected int
		a, b     int
	}{
		{
			expected: 0,
			a:        0,
			b:        100,
		},
		{
			expected: 10,
			a:        10,
			b:        10,
		},
		{
			expected: 1,
			a:        10,
			b:        1,
		},
	}
	for i, tt := range tests {
		tt := tt
		t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
			assert.Equal(t, tt.expected, minInt(tt.a, tt.b))
		})
	}
}

func TestMaxInt(t *testing.T) {
	tests := []struct {
		expected int
		a, b     int
	}{
		{
			expected: 100,
			a:        0,
			b:        100,
		},
		{
			expected: 10,
			a:        10,
			b:        10,
		},
		{
			expected: 10,
			a:        10,
			b:        1,
		},
	}
	for i, tt := range tests {
		tt := tt
		t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
			assert.Equal(t, tt.expected, maxInt(tt.a, tt.b))
		})
	}
}

func TestClamp(t *testing.T) {
	tests := []struct {
		expected int
		x        int
		min      int
		max      int
	}{
		{
			expected: 50,
			x:        50,
			min:      0,
			max:      100,
		},
		{
			expected: 50,
			x:        50,
			min:      50,
			max:      100,
		},
		{
			expected: 100,
			x:        100,
			min:      0,
			max:      100,
		},
		{
			expected: 50,
			x:        3,
			min:      50,
			max:      100,
		},
		{
			expected: 100,
			x:        150,
			min:      0,
			max:      100,
		},
	}
	for i, tt := range tests {
		tt := tt
		t.Run(fmt.Sprintf("int/%v", i), func(t *testing.T) {
			assert.Equal(t, tt.expected, clampInt(tt.x, tt.min, tt.max))
		})
		t.Run(fmt.Sprintf("duration/%v", i), func(t *testing.T) {
			x := time.Duration(tt.x)
			min := time.Duration(tt.min)
			max := time.Duration(tt.max)
			expected := time.Duration(tt.expected)
			assert.Equal(t, expected, clampDuration(x, min, max))
		})
	}
}