File: utils_test.go

package info (click to toggle)
golang-github-jesseduffield-lazycore 0.0~git20221023.718a4ca-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 136 kB
  • sloc: makefile: 2
file content (76 lines) | stat: -rw-r--r-- 809 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
package utils

import (
	"testing"

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

// TestMin is a function.
func TestMin(t *testing.T) {
	type scenario struct {
		a        int
		b        int
		expected int
	}

	scenarios := []scenario{
		{
			1,
			1,
			1,
		},
		{
			1,
			2,
			1,
		},
		{
			2,
			1,
			1,
		},
	}

	for _, s := range scenarios {
		assert.EqualValues(t, s.expected, Min(s.a, s.b))
	}
}

func TestClamp(t *testing.T) {
	tests := []struct {
		name string
		x    int
		min  int
		max  int
		want int
	}{
		{
			"successX",
			5,
			1,
			10,
			5,
		},
		{
			"successMin",
			-5,
			1,
			10,
			1,
		},
		{
			"successMax",
			15,
			1,
			10,
			10,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			assert.Equal(t, tt.want, Clamp(tt.x, tt.min, tt.max))
		})
	}
}