-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidate_test.go
128 lines (105 loc) · 2.52 KB
/
validate_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
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
121
122
123
124
125
126
127
128
package yeelight
import (
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestValidateDuration(t *testing.T) {
tests := map[time.Duration]error{
MinDuration - 1: ErrDurationTooSmall,
MinDuration: nil,
MinDuration + 1: nil,
}
for duration, exp := range tests {
t.Run(duration.String(), func(t *testing.T) {
err := ValidateDuration(duration)
assert.Equal(t, exp, err)
})
}
}
func TestValidateAdjustPercentage(t *testing.T) {
tests := map[int]error{
MinAdjustPercentage - 1: ErrWrongAdjustPercentage,
MinAdjustPercentage: nil,
MinAdjustPercentage + 1: nil,
MaxAdjustPercentage: nil,
MaxAdjustPercentage + 1: ErrWrongAdjustPercentage,
}
for percentage, exp := range tests {
t.Run(strconv.Itoa(percentage), func(t *testing.T) {
err := ValidateAdjustPercentage(percentage)
assert.Equal(t, exp, err)
})
}
}
func TestValidateRGB(t *testing.T) {
tests := map[int]error{
MinRGB - 1: ErrWrongRGBValue,
MinRGB: nil,
MaxRGB: nil,
MaxRGB + 1: ErrWrongRGBValue,
}
for rgb, exp := range tests {
t.Run(strconv.Itoa(rgb), func(t *testing.T) {
err := ValidateRGB(rgb)
assert.Equal(t, exp, err)
})
}
}
func TestValidateHue(t *testing.T) {
tests := map[int]error{
MinHue - 1: ErrWrongHueValue,
MinHue: nil,
MaxHue: nil,
MaxHue + 1: ErrWrongHueValue,
}
for hue, exp := range tests {
t.Run(strconv.Itoa(hue), func(t *testing.T) {
err := ValidateHue(hue)
assert.Equal(t, exp, err)
})
}
}
func TestValidateSat(t *testing.T) {
tests := map[int]error{
MinSat - 1: ErrWrongSatValue,
MinSat: nil,
MaxSat: nil,
MaxSat + 1: ErrWrongSatValue,
}
for hue, exp := range tests {
t.Run(strconv.Itoa(hue), func(t *testing.T) {
err := ValidateSat(hue)
assert.Equal(t, exp, err)
})
}
}
func TestValidateBright(t *testing.T) {
tests := map[int]error{
MinBright - 1: ErrWrongBrightValue,
MinBright: nil,
MaxBright: nil,
MaxBright + 1: ErrWrongBrightValue,
}
for hue, exp := range tests {
t.Run(strconv.Itoa(hue), func(t *testing.T) {
err := ValidateBright(hue)
assert.Equal(t, exp, err)
})
}
}
func TestValidateColorTemperature(t *testing.T) {
tests := map[int]error{
MinColorTemperature - 1: ErrWrongColorTemperature,
MinColorTemperature: nil,
MaxColorTemperature: nil,
MaxColorTemperature + 1: ErrWrongColorTemperature,
}
for hue, exp := range tests {
t.Run(strconv.Itoa(hue), func(t *testing.T) {
err := ValidateColorTemperature(hue)
assert.Equal(t, exp, err)
})
}
}