Initial commit
implemented the game of life variation with hexagonal grid
This commit is contained in:
47
math/ops_test.go
Normal file
47
math/ops_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package math
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAbs(t *testing.T) {
|
||||
assertEqual(t, 0, Abs(0))
|
||||
assertEqual(t, 1, Abs(1))
|
||||
assertEqual(t, 2, Abs(-2))
|
||||
|
||||
assertEqual(t, 0.0, Abs(0.0))
|
||||
assertEqual(t, 1.5, Abs(1.5))
|
||||
assertEqual(t, 2.75, Abs(-2.75))
|
||||
}
|
||||
|
||||
func TestRoundPositive(t *testing.T) {
|
||||
posf64 := float64(0.987654321)
|
||||
posf64 = Round(posf64, 2)
|
||||
assertEqual(t, float64(0.99), posf64)
|
||||
|
||||
posf32 := float32(0.987654321)
|
||||
posf32 = Round(posf32, 5)
|
||||
assertEqual(t, float32(0.98765), posf32)
|
||||
|
||||
negf64 := float64(-0.987654321)
|
||||
negf64 = Round(negf64, 2)
|
||||
assertEqual(t, float64(-0.99), negf64)
|
||||
|
||||
negf32 := float32(-0.987654321)
|
||||
negf32 = Round(negf32, 5)
|
||||
assertEqual(t, float32(-0.98765), negf32)
|
||||
}
|
||||
|
||||
func TestRoundInt(t *testing.T) {
|
||||
i := RoundInt(float64(0.5))
|
||||
assertEqual(t, 1, i)
|
||||
|
||||
i = RoundInt(float32(1.4999999))
|
||||
assertEqual(t, 1, i)
|
||||
}
|
||||
|
||||
func assertEqual[T comparable](t testing.TB, want, got T) {
|
||||
if want != got {
|
||||
t.Fatalf("want %v but got %v", want, got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user