forked from reiver/go-cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuint8_test.go
91 lines (74 loc) · 1.47 KB
/
uint8_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
package cast
import (
"math"
"testing"
)
func TestUint8FromUint8(t *testing.T) {
tests := []struct{
Value uint8
}{
{
Value: 0,
},
{
Value: 1,
},
{
Value: math.MaxUint8,
},
}
{
const numRand = 20
for i:=0; i<numRand; i++ {
test := struct{
Value uint8
}{
Value: uint8(randomness.Int63n(math.MaxUint8)),
}
tests = append(tests, test)
}
}
for testNumber, test := range tests {
x, err := Uint8(test.Value)
if nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %v", testNumber, err, err)
continue
}
y := uint8(x)
if expected, actual := test.Value, y; expected != actual {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}
func TestUint8FromUint8er(t *testing.T) {
tests := []struct{
Value uint8er
Expected uint8
}{
{
Value: testUint8erZero(),
Expected: 0,
},
{
Value: testUint8erOne(),
Expected: 1,
},
{
Value: testUint8erMax(),
Expected: math.MaxUint8,
},
}
for testNumber, test := range tests {
x, err := Uint8(test.Value)
if nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %v", testNumber, err, err)
continue
}
y := uint8(x)
if expected, actual := test.Expected, y; expected != actual {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}