Debian Codegraph @

pkg/utils/utils_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package utils
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 // TestMin is a function.
10 func TestMin(t *testing.T) {
11 type scenario struct {
12 a int
13 b int
14 expected int
15 }
16
17 scenarios := []scenario{
18 {
19 1,
20 1,
21 1,
22 },
23 {
24 1,
25 2,
26 1,
27 },
28 {
29 2,
30 1,
31 1,
32 },
33 }
34
35 for _, s := range scenarios {
36 assert.EqualValues(t, s.expected, Min(s.a, s.b))
37 }
38 }
39
40 func TestClamp(t *testing.T) {
41 tests := []struct {
42 name string
43 x int
44 min int
45 max int
46 want int
47 }{
48 {
49 "successX",
50 5,
51 1,
52 10,
53 5,
54 },
55 {
56 "successMin",
57 -5,
58 1,
59 10,
60 1,
61 },
62 {
63 "successMax",
64 15,
65 1,
66 10,
67 10,
68 },
69 }
70
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 assert.Equal(t, tt.want, Clamp(tt.x, tt.min, tt.max))
74 })
75 }
76 }