-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtime_test.go
61 lines (54 loc) · 1.1 KB
/
time_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
package lifxlan_test
import (
"math/rand"
"testing"
"testing/quick"
"time"
"go.yhsif.com/lifxlan"
)
func TestTime(t *testing.T) {
// Seed rander
now := time.Now()
rander := rand.New(rand.NewSource(now.Unix() + int64(now.Nanosecond())))
var n int
var innerT *testing.T
cases := map[string]func() bool{
"Timestamp": func() bool {
n++
sec := int64(rander.Int31())
nano := int64(rander.Intn(int(time.Second)))
t := time.Unix(sec, nano)
ts := lifxlan.ConvertTime(t)
got := ts.Time()
if !got.Equal(t) {
innerT.Logf("Expected %v, got %v", t, got)
return false
}
return true
},
"TransitionTime": func() bool {
n++
d := time.Duration(rander.Int31()).Round(time.Millisecond)
ti := lifxlan.ConvertDuration(d)
got := ti.Duration()
if got != d {
innerT.Logf("Expected %v, got %v", d, got)
return false
}
return true
},
}
for label, f := range cases {
t.Run(
label,
func(t *testing.T) {
n = 0
innerT = t
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
t.Logf("quick did %d checks", n)
},
)
}
}