2014-11-13 07:00:40 +08:00
|
|
|
package gobot_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2016-02-22 13:21:24 +08:00
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/gobottest"
|
2014-11-13 07:00:40 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, a, b)
|
2014-11-13 07:00:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func ExampleRefute() {
|
|
|
|
t := &testing.T{}
|
|
|
|
var a int = 100
|
|
|
|
var b int = 200
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Refute(t, a, b)
|
2014-11-13 07:00:40 +08:00
|
|
|
}
|