|
@@ -0,0 +1,43 @@
|
|
1
|
+package resize
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "testing"
|
|
5
|
+)
|
|
6
|
+
|
|
7
|
+func Test_ClampUint8(t *testing.T) {
|
|
8
|
+ var testData = []struct {
|
|
9
|
+ in int32
|
|
10
|
+ expected uint8
|
|
11
|
+ }{
|
|
12
|
+ {0, 0},
|
|
13
|
+ {255, 255},
|
|
14
|
+ {128, 128},
|
|
15
|
+ {-2, 0},
|
|
16
|
+ {256, 255},
|
|
17
|
+ }
|
|
18
|
+ for _, test := range testData {
|
|
19
|
+ actual := clampUint8(test.in)
|
|
20
|
+ if actual != test.expected {
|
|
21
|
+ t.Fail()
|
|
22
|
+ }
|
|
23
|
+ }
|
|
24
|
+}
|
|
25
|
+
|
|
26
|
+func Test_ClampUint16(t *testing.T) {
|
|
27
|
+ var testData = []struct {
|
|
28
|
+ in int64
|
|
29
|
+ expected uint16
|
|
30
|
+ }{
|
|
31
|
+ {0, 0},
|
|
32
|
+ {65535, 65535},
|
|
33
|
+ {128, 128},
|
|
34
|
+ {-2, 0},
|
|
35
|
+ {65536, 65535},
|
|
36
|
+ }
|
|
37
|
+ for _, test := range testData {
|
|
38
|
+ actual := clampUint16(test.in)
|
|
39
|
+ if actual != test.expected {
|
|
40
|
+ t.Fail()
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+}
|