forked from segmentio/stats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
value_test.go
51 lines (46 loc) · 952 Bytes
/
value_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
package stats
import (
"fmt"
"reflect"
"testing"
"time"
)
func TestValueOf(t *testing.T) {
tests := []struct {
in interface{}
out interface{}
}{
{nil, nil},
{true, true},
{false, false},
{int8(1), int64(1)},
{int8(-1), int64(-1)},
{int16(1), int64(1)},
{int16(-1), int64(-1)},
{int32(1), int64(1)},
{int32(-1), int64(-1)},
{int64(1), int64(1)},
{int64(-1), int64(-1)},
{uint8(1), uint64(1)},
{uint16(1), uint64(1)},
{uint32(1), uint64(1)},
{uint64(1), uint64(1)},
{uintptr(1), uint64(1)},
{float32(0.5), float64(0.5)},
{float64(0.5), float64(0.5)},
{time.Second, time.Second},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%T(%v)", test.in, test.in), func(t *testing.T) {
v := ValueOf(test.in).Interface()
if !reflect.DeepEqual(v, test.out) {
t.Errorf("bad value: %T(%v)", v, v)
}
})
}
}
func BenchmarkValueOf(b *testing.B) {
for i := 0; i != b.N; i++ {
ValueOf(42)
}
}