forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
77 lines (65 loc) · 1.18 KB
/
examples_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
package gobot_test
import (
"fmt"
"testing"
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/gobottest"
)
func ExampleEvery() {
gobot.Every(1*time.Second, func() {
fmt.Println("Hello")
})
}
func ExampleAfter() {
gobot.After(1*time.Second, func() {
fmt.Println("Hello")
})
}
func ExamplePublish() {
e := gobot.NewEvent()
gobot.Publish(e, 100)
}
func ExampleOn() {
e := gobot.NewEvent()
gobot.On(e, func(s interface{}) {
fmt.Println(s)
})
gobot.Publish(e, 100)
gobot.Publish(e, 200)
}
func ExampleOnce() {
e := gobot.NewEvent()
gobot.Once(e, func(s interface{}) {
fmt.Println(s)
fmt.Println("I will no longer respond to events")
})
gobot.Publish(e, 100)
gobot.Publish(e, 200)
}
func ExampleRand() {
i := gobot.Rand(100)
fmt.Sprintln("%v is > 0 && < 100", i)
}
func ExampleFromScale() {
fmt.Println(gobot.FromScale(5, 0, 10))
// Output:
// 0.5
}
func ExampleToScale() {
fmt.Println(gobot.ToScale(500, 0, 10))
// Output:
// 10
}
func ExampleAssert() {
t := &testing.T{}
var a int = 100
var b int = 100
gobottest.Assert(t, a, b)
}
func ExampleRefute() {
t := &testing.T{}
var a int = 100
var b int = 200
gobottest.Refute(t, a, b)
}