2015-01-12 03:56:17 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestMax(t *testing.T) {
|
2016-08-14 02:58:47 +00:00
|
|
|
if Max(-2, 5) != 5 {
|
2015-01-12 03:56:17 +00:00
|
|
|
t.Error("Invalid result")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContrain(t *testing.T) {
|
|
|
|
if Constrain(-3, -1, 3) != -1 {
|
|
|
|
t.Error("Expected", -1)
|
|
|
|
}
|
|
|
|
if Constrain(2, -1, 3) != 2 {
|
|
|
|
t.Error("Expected", 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
if Constrain(5, -1, 3) != 3 {
|
|
|
|
t.Error("Expected", 3)
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 12:32:58 +00:00
|
|
|
|
|
|
|
func TestOnce(t *testing.T) {
|
|
|
|
o := Once(false)
|
|
|
|
if o() {
|
|
|
|
t.Error("Expected: false")
|
|
|
|
}
|
|
|
|
if o() {
|
|
|
|
t.Error("Expected: false")
|
|
|
|
}
|
|
|
|
|
|
|
|
o = Once(true)
|
|
|
|
if !o() {
|
|
|
|
t.Error("Expected: true")
|
|
|
|
}
|
|
|
|
if o() {
|
|
|
|
t.Error("Expected: false")
|
|
|
|
}
|
|
|
|
}
|