Files
gglm/gglm/scalar_test.go
2024-05-14 06:06:00 +04:00

65 lines
1.0 KiB
Go
Executable File

package gglm_test
import (
"testing"
"github.com/bloeys/gglm/gglm"
)
func TestClamp(t *testing.T) {
x := 5
ans := 5
if gglm.Clamp(x, 0, 10) != ans {
t.Errorf("Got: %v; Expected: %v", x, ans)
}
x = 10
ans = 10
if gglm.Clamp(x, 0, 10) != ans {
t.Errorf("Got: %v; Expected: %v", x, ans)
}
x = 20
ans = 10
if gglm.Clamp(x, 0, 10) != ans {
t.Errorf("Got: %v; Expected: %v", x, ans)
}
x = -10
ans = 0
if gglm.Clamp(x, 0, 10) != ans {
t.Errorf("Got: %v; Expected: %v", x, ans)
}
xf := 1.5
ansf := 1.5
if gglm.Clamp(xf, 0, 10) != ansf {
t.Errorf("Got: %v; Expected: %v", xf, ansf)
}
xf = 15
ansf = 10
if gglm.Clamp(xf, 0, 10) != ansf {
t.Errorf("Got: %v; Expected: %v", xf, ansf)
}
xf = -1.5
ansf = 0
if gglm.Clamp(xf, 0, 10) != ansf {
t.Errorf("Got: %v; Expected: %v", xf, ansf)
}
xf = 2
ansf = 1.5
if gglm.Clamp(xf, 0.5, 1.5) != ansf {
t.Errorf("Got: %v; Expected: %v", xf, ansf)
}
xf = 1.2
ansf = 1.2
if gglm.Clamp(xf, 0.5, 1.5) != ansf {
t.Errorf("Got: %v; Expected: %v", xf, ansf)
}
}