aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-05-30 19:42:44 +0200
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-02 14:47:09 -0400
commitb0faab29e0c4cfcde54b5ffa66f5b43c77283d3d (patch)
treed0ac3f488e155689d199e65f597db2079b5e4daa
parentd7bfbe05523ec4a786e57a916d32b6e849de1681 (diff)
Port `tests\core\math`, `math\linalg\glsl` and `math\noise`
-rw-r--r--tests/core/Makefile14
-rw-r--r--tests/core/build.bat6
-rw-r--r--tests/core/math/linalg/glsl/test_linalg_glsl_math.odin20
-rw-r--r--tests/core/math/noise/test_core_math_noise.odin195
-rw-r--r--tests/core/math/test_core_math.odin258
5 files changed, 180 insertions, 313 deletions
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 6a01653f0..eb16f6645 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -68,21 +68,21 @@ image_test:
i18n_test:
$(ODIN) test text/i18n $(COMMON) -out:test_core_i18n
+math_test:
+ $(ODIN) test math $(COMMON) -out:test_core_math
+
linalg_glsl_math_test:
- $(ODIN) run math/linalg/glsl $(COMMON) $(COLLECTION) -out:test_linalg_glsl_math
+ $(ODIN) test math/linalg/glsl $(COMMON) -out:test_linalg_glsl_math
+
+noise_test:
+ $(ODIN) test math/noise $(COMMON) -out:test_noise
match_test:
$(ODIN) run text/match $(COMMON) -out:test_core_match
-math_test:
- $(ODIN) run math $(COMMON) $(COLLECTION) -out:test_core_math
-
net_test:
$(ODIN) run net $(COMMON) -out:test_core_net
-noise_test:
- $(ODIN) run math/noise $(COMMON) -out:test_noise
-
os_exit_test:
$(ODIN) run os/test_core_os_exit.odin -file -out:test_core_os_exit && exit 1 || exit 0
diff --git a/tests/core/build.bat b/tests/core/build.bat
index c06a9269f..f14579056 100644
--- a/tests/core/build.bat
+++ b/tests/core/build.bat
@@ -62,17 +62,17 @@ echo ---
echo ---
echo Running core:math tests
echo ---
-%PATH_TO_ODIN% run math %COMMON% %COLLECTION% -out:test_core_math.exe || exit /b
+%PATH_TO_ODIN% test math %COMMON% -out:test_core_math.exe || exit /b
echo ---
echo Running core:math/linalg/glsl tests
echo ---
-%PATH_TO_ODIN% run math/linalg/glsl %COMMON% %COLLECTION% -out:test_linalg_glsl.exe || exit /b
+%PATH_TO_ODIN% test math/linalg/glsl %COMMON% -out:test_linalg_glsl.exe || exit /b
echo ---
echo Running core:math/noise tests
echo ---
-%PATH_TO_ODIN% run math/noise %COMMON% -out:test_noise.exe || exit /b
+%PATH_TO_ODIN% test math/noise %COMMON% -out:test_noise.exe || exit /b
echo ---
echo Running core:net
diff --git a/tests/core/math/linalg/glsl/test_linalg_glsl_math.odin b/tests/core/math/linalg/glsl/test_linalg_glsl_math.odin
index cf91b8a97..6d4571b24 100644
--- a/tests/core/math/linalg/glsl/test_linalg_glsl_math.odin
+++ b/tests/core/math/linalg/glsl/test_linalg_glsl_math.odin
@@ -1,24 +1,10 @@
// Tests "linalg_glsl_math.odin" in "core:math/linalg/glsl".
-// Must be run with `-collection:tests=` flag, e.g.
-// ./odin run tests/core/math/linalg/glsl/test_linalg_glsl_math.odin -collection:tests=./tests
package test_core_math_linalg_glsl_math
import glsl "core:math/linalg/glsl"
-import "core:fmt"
import "core:math"
import "core:testing"
-import tc "tests:common"
-
-main :: proc() {
-
- t := testing.T{}
-
- test_fract_f32(&t)
- test_fract_f64(&t)
-
- tc.report(&t)
-}
@test
test_fract_f32 :: proc(t: ^testing.T) {
@@ -45,7 +31,7 @@ test_fract_f32 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = glsl.fract(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%v (%h)) -> %v (%h) != %v", i, #procedure, d.v, d.v, r, r, d.e))
+ testing.expectf(t, r == d.e, "%v (%h) -> %v (%h) != %v", d.v, d.v, r, r, d.e)
}
}
@@ -74,6 +60,6 @@ test_fract_f64 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = glsl.fract(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%v (%h)) -> %v (%h) != %v", i, #procedure, d.v, d.v, r, r, d.e))
+ testing.expectf(t, r == d.e, "%v (%h) -> %v (%h) != %v", d.v, d.v, r, r, d.e)
}
-}
+} \ No newline at end of file
diff --git a/tests/core/math/noise/test_core_math_noise.odin b/tests/core/math/noise/test_core_math_noise.odin
index a0360e695..f835cf58c 100644
--- a/tests/core/math/noise/test_core_math_noise.odin
+++ b/tests/core/math/noise/test_core_math_noise.odin
@@ -2,42 +2,6 @@ package test_core_math_noise
import "core:testing"
import "core:math/noise"
-import "core:fmt"
-import "core:os"
-
-TEST_count := 0
-TEST_fail := 0
-
-V2 :: noise.Vec2
-V3 :: noise.Vec3
-V4 :: noise.Vec4
-
-when ODIN_TEST {
- expect :: testing.expect
- log :: testing.log
-} else {
- expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
- TEST_count += 1
- if !condition {
- TEST_fail += 1
- fmt.printf("[%v] %v\n", loc, message)
- return
- }
- }
- log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
- fmt.printf("[%v] ", loc)
- fmt.printf("log: %v\n", v)
- }
-}
-
-main :: proc() {
- t := testing.T{}
- noise_test(&t)
- fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
- if TEST_fail > 0 {
- os.exit(1)
- }
-}
Test_Vector :: struct {
seed: i64,
@@ -51,6 +15,10 @@ Test_Vector :: struct {
},
}
+V2 :: noise.Vec2
+V3 :: noise.Vec3
+V4 :: noise.Vec4
+
SEED_1 :: 2324223232
SEED_2 :: 932466901
SEED_3 :: 9321
@@ -59,93 +27,78 @@ COORD_1 :: V4{ 242.0, 3433.0, 920.0, 222312.0}
COORD_2 :: V4{ 590.0, 9411.0, 5201.0, 942124256.0}
COORD_3 :: V4{12090.0, 19411.0, 81950901.0, 4224219.0}
-Noise_Tests := []Test_Vector{
- /*
- `noise_2d` tests.
- */
- {SEED_1, COORD_1.xy, 0.25010583, noise.noise_2d},
- {SEED_2, COORD_2.xy, -0.92513955, noise.noise_2d},
- {SEED_3, COORD_3.xy, 0.67327416, noise.noise_2d},
-
- /*
- `noise_2d_improve_x` tests.
- */
- {SEED_1, COORD_1.xy, 0.17074019, noise.noise_2d_improve_x},
- {SEED_2, COORD_2.xy, 0.72330487, noise.noise_2d_improve_x},
- {SEED_3, COORD_3.xy, -0.032076947, noise.noise_2d_improve_x},
-
- /*
- `noise_3d_improve_xy` tests.
- */
- {SEED_1, COORD_1.xyz, 0.14819577, noise.noise_3d_improve_xy},
- {SEED_2, COORD_2.xyz, -0.065345764, noise.noise_3d_improve_xy},
- {SEED_3, COORD_3.xyz, -0.37761918, noise.noise_3d_improve_xy},
-
- /*
- `noise_3d_improve_xz` tests.
- */
- {SEED_1, COORD_1.xyz, -0.50075006, noise.noise_3d_improve_xz},
- {SEED_2, COORD_2.xyz, -0.36039603, noise.noise_3d_improve_xz},
- {SEED_3, COORD_3.xyz, -0.3479203, noise.noise_3d_improve_xz},
-
- /*
- `noise_3d_fallback` tests.
- */
- {SEED_1, COORD_1.xyz, 0.6557345, noise.noise_3d_fallback},
- {SEED_2, COORD_2.xyz, 0.55452216, noise.noise_3d_fallback},
- {SEED_3, COORD_3.xyz, -0.26408964, noise.noise_3d_fallback},
-
- /*
- `noise_3d_fallback` tests.
- */
- {SEED_1, COORD_1.xyz, 0.6557345, noise.noise_3d_fallback},
- {SEED_2, COORD_2.xyz, 0.55452216, noise.noise_3d_fallback},
- {SEED_3, COORD_3.xyz, -0.26408964, noise.noise_3d_fallback},
-
- /*
- `noise_4d_improve_xyz_improve_xy` tests.
- */
- {SEED_1, COORD_1, 0.44929826, noise.noise_4d_improve_xyz_improve_xy},
- {SEED_2, COORD_2, -0.13270882, noise.noise_4d_improve_xyz_improve_xy},
- {SEED_3, COORD_3, 0.10298563, noise.noise_4d_improve_xyz_improve_xy},
-
- /*
- `noise_4d_improve_xyz_improve_xz` tests.
- */
- {SEED_1, COORD_1, -0.078514606, noise.noise_4d_improve_xyz_improve_xz},
- {SEED_2, COORD_2, -0.032157656, noise.noise_4d_improve_xyz_improve_xz},
- {SEED_3, COORD_3, -0.38607058, noise.noise_4d_improve_xyz_improve_xz},
-
- /*
- `noise_4d_improve_xyz` tests.
- */
- {SEED_1, COORD_1, -0.4442258, noise.noise_4d_improve_xyz},
- {SEED_2, COORD_2, 0.36822623, noise.noise_4d_improve_xyz},
- {SEED_3, COORD_3, 0.22628775, noise.noise_4d_improve_xyz},
-
- /*
- `noise_4d_fallback` tests.
- */
- {SEED_1, COORD_1, -0.14233987, noise.noise_4d_fallback},
- {SEED_2, COORD_2, 0.1354035, noise.noise_4d_fallback},
- {SEED_3, COORD_3, 0.14565045, noise.noise_4d_fallback},
+@(test)
+test_noise_2d :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1.xy, 0.25010583, noise.noise_2d})
+ test(t, {SEED_2, COORD_2.xy, -0.92513955, noise.noise_2d})
+ test(t, {SEED_3, COORD_3.xy, 0.67327416, noise.noise_2d})
+}
+
+@(test)
+test_noise_2d_improve_x :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1.xy, 0.17074019, noise.noise_2d_improve_x})
+ test(t, {SEED_2, COORD_2.xy, 0.72330487, noise.noise_2d_improve_x})
+ test(t, {SEED_3, COORD_3.xy, -0.032076947, noise.noise_2d_improve_x})
+}
+
+@(test)
+test_noise_3d_improve_xy :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1.xyz, 0.14819577, noise.noise_3d_improve_xy})
+ test(t, {SEED_2, COORD_2.xyz, -0.065345764, noise.noise_3d_improve_xy})
+ test(t, {SEED_3, COORD_3.xyz, -0.37761918, noise.noise_3d_improve_xy})
+}
+
+@(test)
+test_noise_3d_improve_xz :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1.xyz, -0.50075006, noise.noise_3d_improve_xz})
+ test(t, {SEED_2, COORD_2.xyz, -0.36039603, noise.noise_3d_improve_xz})
+ test(t, {SEED_3, COORD_3.xyz, -0.3479203, noise.noise_3d_improve_xz})
+}
+
+@(test)
+test_noise_3d_fallback :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1.xyz, 0.6557345, noise.noise_3d_fallback})
+ test(t, {SEED_2, COORD_2.xyz, 0.55452216, noise.noise_3d_fallback})
+ test(t, {SEED_3, COORD_3.xyz, -0.26408964, noise.noise_3d_fallback})
+}
+
+@(test)
+test_noise_4d_improve_xyz_improve_xy :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1, 0.44929826, noise.noise_4d_improve_xyz_improve_xy})
+ test(t, {SEED_2, COORD_2, -0.13270882, noise.noise_4d_improve_xyz_improve_xy})
+ test(t, {SEED_3, COORD_3, 0.10298563, noise.noise_4d_improve_xyz_improve_xy})
+}
+
+@(test)
+test_noise_4d_improve_xyz_improve_xz :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1, -0.078514606, noise.noise_4d_improve_xyz_improve_xz})
+ test(t, {SEED_2, COORD_2, -0.032157656, noise.noise_4d_improve_xyz_improve_xz})
+ test(t, {SEED_3, COORD_3, -0.38607058, noise.noise_4d_improve_xyz_improve_xz})
+}
+
+@(test)
+test_noise_4d_improve_xyz :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1, -0.4442258, noise.noise_4d_improve_xyz})
+ test(t, {SEED_2, COORD_2, 0.36822623, noise.noise_4d_improve_xyz})
+ test(t, {SEED_3, COORD_3, 0.22628775, noise.noise_4d_improve_xyz})
+}
+@(test)
+test_noise_4d_fallback :: proc(t: ^testing.T) {
+ test(t, {SEED_1, COORD_1, -0.14233987, noise.noise_4d_fallback})
+ test(t, {SEED_2, COORD_2, 0.1354035, noise.noise_4d_fallback})
+ test(t, {SEED_3, COORD_3, 0.14565045, noise.noise_4d_fallback})
}
-noise_test :: proc(t: ^testing.T) {
- for test in Noise_Tests {
- output: f32
-
- switch coord in test.coord {
- case V2:
- output = test.test_proc.(proc(_: i64, _: V2) -> f32)(test.seed, test.coord.(V2))
- case V3:
- output = test.test_proc.(proc(_: i64, _: V3) -> f32)(test.seed, test.coord.(V3))
- case V4:
- output = test.test_proc.(proc(_: i64, _: V4) -> f32)(test.seed, test.coord.(V4))
- }
-
- error := fmt.tprintf("Seed %v, Coord: %v, Expected: %3.8f. Got %3.8f", test.seed, test.coord, test.expected, output)
- expect(t, test.expected == output, error)
+test :: proc(t: ^testing.T, test: Test_Vector) {
+ output: f32
+ switch coord in test.coord {
+ case V2:
+ output = test.test_proc.(proc(_: i64, _: V2) -> f32)(test.seed, test.coord.(V2))
+ case V3:
+ output = test.test_proc.(proc(_: i64, _: V3) -> f32)(test.seed, test.coord.(V3))
+ case V4:
+ output = test.test_proc.(proc(_: i64, _: V4) -> f32)(test.seed, test.coord.(V4))
}
+ testing.expectf(t, test.expected == output, "Seed %v, Coord: %v, Expected: %3.8f. Got %3.8f", test.seed, test.coord, test.expected, output)
} \ No newline at end of file
diff --git a/tests/core/math/test_core_math.odin b/tests/core/math/test_core_math.odin
index df989bff6..2a752e366 100644
--- a/tests/core/math/test_core_math.odin
+++ b/tests/core/math/test_core_math.odin
@@ -1,49 +1,8 @@
// Tests "math.odin" in "core:math".
-// Must be run with `-collection:tests=` flag, e.g.
-// ./odin run tests/core/math/test_core_math.odin -collection:tests=./tests
package test_core_math
-import "core:fmt"
import "core:math"
import "core:testing"
-import tc "tests:common"
-
-main :: proc() {
- t := testing.T{}
-
- test_classify_f16(&t)
- test_classify_f32(&t)
- test_classify_f64(&t)
-
- test_trunc_f16(&t)
- test_trunc_f32(&t)
- test_trunc_f64(&t)
-
- test_round_f16(&t)
- test_round_f32(&t)
- test_round_f64(&t)
-
- test_nan(&t)
- test_acos(&t)
- test_acosh(&t)
- test_asin(&t)
- test_asinh(&t)
- test_atan(&t)
- test_atanh(&t)
- test_atan2(&t)
- test_cos(&t)
- test_cosh(&t)
- test_sin(&t)
- test_sinh(&t)
- test_sqrt(&t)
- test_tan(&t)
- test_tanh(&t)
- test_large_cos(&t)
- test_large_sin(&t)
- test_large_tan(&t)
-
- tc.report(&t)
-}
@test
test_classify_f16 :: proc(t: ^testing.T) {
@@ -68,7 +27,7 @@ test_classify_f16 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.classify_f16(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %v != %v", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %v != %v", d.v, r, d.e)
}
/* Check all subnormals (exponent 0, 10-bit significand non-zero) */
@@ -76,7 +35,7 @@ test_classify_f16 :: proc(t: ^testing.T) {
v := transmute(f16)i
r = math.classify_f16(v)
e :: math.Float_Class.Subnormal
- tc.expect(t, r == e, fmt.tprintf("i:%d %s(%h) -> %v != %v", i, #procedure, v, r, e))
+ testing.expectf(t, r == e, "%h -> %v != %v", v, r, e)
}
}
@@ -103,7 +62,7 @@ test_classify_f32 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.classify_f32(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %v != %v", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %v != %v", d.v, r, d.e)
}
}
@@ -130,7 +89,7 @@ test_classify_f64 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.classify_f64(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %v != %v", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %v != %v", d.v, r, d.e)
}
}
@@ -175,16 +134,16 @@ test_trunc_f16 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.trunc_f16(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %h != %h", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %h != %h", d.v, r, d.e)
}
v = math.SNAN_F16
r = math.trunc_f16(v)
- tc.expect(t, math.is_nan_f16(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f16(r), "%f != NaN", v, r)
v = math.QNAN_F16
r = math.trunc_f16(v)
- tc.expect(t, math.is_nan_f16(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f16(r), "%f != NaN", v, r)
}
@test
@@ -237,16 +196,16 @@ test_trunc_f32 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.trunc_f32(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %h != %h", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %h != %h", d.v, r, d.e)
}
v = math.SNAN_F32
r = math.trunc_f32(v)
- tc.expect(t, math.is_nan_f32(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f32(r), "%f -> %f != NaN", v, r)
v = math.QNAN_F32
r = math.trunc_f32(v)
- tc.expect(t, math.is_nan_f32(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f32(r), "%f -> %f != NaN", v, r)
}
@test
@@ -299,16 +258,16 @@ test_trunc_f64 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.trunc_f64(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %h != %h", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %h != %h", d.v, r, d.e)
}
v = math.SNAN_F64
r = math.trunc_f64(v)
- tc.expect(t, math.is_nan_f64(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f64(r), "%f -> %f != NaN", v, r)
v = math.QNAN_F64
r = math.trunc_f64(v)
- tc.expect(t, math.is_nan_f64(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f64(r), "%f -> %f != NaN", v, r)
}
@test
@@ -352,16 +311,16 @@ test_round_f16 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.round_f16(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %h != %h", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %h != %h", d.v, r, d.e)
}
v = math.SNAN_F16
r = math.round_f16(v)
- tc.expect(t, math.is_nan_f16(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f16(r), "%f -> %f != NaN", v, r)
v = math.QNAN_F16
r = math.round_f16(v)
- tc.expect(t, math.is_nan_f16(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f16(r), "%f -> %f != NaN", v, r)
}
@test
@@ -414,16 +373,16 @@ test_round_f32 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.round_f32(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %h != %h", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %h != %h", i, d.v, r, d.e)
}
v = math.SNAN_F32
r = math.round_f32(v)
- tc.expect(t, math.is_nan_f32(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f32(r), "%f -> %f != NaN", v, r)
v = math.QNAN_F32
r = math.round_f32(v)
- tc.expect(t, math.is_nan_f32(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f32(r), "%f -> %f != NaN", v, r)
}
@test
@@ -476,16 +435,16 @@ test_round_f64 :: proc(t: ^testing.T) {
for d, i in data {
assert(i == d.i)
r = math.round_f64(d.v)
- tc.expect(t, r == d.e, fmt.tprintf("i:%d %s(%h) -> %h != %h", i, #procedure, d.v, r, d.e))
+ testing.expectf(t, r == d.e, "%h -> %h != %h", d.v, r, d.e)
}
v = math.SNAN_F64
r = math.round_f64(v)
- tc.expect(t, math.is_nan_f64(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f64(r), "%f -> %f != NaN", v, r)
v = math.QNAN_F64
r = math.round_f64(v)
- tc.expect(t, math.is_nan_f64(r), fmt.tprintf("%s(%f) -> %f != NaN", #procedure, v, r))
+ testing.expectf(t, math.is_nan_f64(r), "%f -> %f != NaN", v, r)
}
@@ -1033,17 +992,17 @@ tolerance :: proc(a, b, e: f64) -> bool {
}
close :: proc(t: ^testing.T, a, b: f64, loc := #caller_location) -> bool {
ok := tolerance(a, b, 1e-9)
- // tc.expect(t, ok, fmt.tprintf("%.15g is not close to %.15g", a, b), loc)
+ testing.expectf(t, ok, "%.15g is not close to %.15g", a, b, loc=loc)
return ok
}
veryclose :: proc(t: ^testing.T, a, b: f64, loc := #caller_location) -> bool {
ok := tolerance(a, b, 4e-14)
- // tc.expect(t, ok, fmt.tprintf("%.15g is not veryclose to %.15g", a, b), loc)
+ testing.expectf(t, ok, "%.15g is not veryclose to %.15g", a, b, loc=loc)
return ok
}
soclose :: proc(t: ^testing.T, a, b, e: f64, loc := #caller_location) -> bool {
ok := tolerance(a, b, e)
- // tc.expect(t, ok, fmt.tprintf("%.15g is not soclose to %.15g", a, b), loc)
+ testing.expectf(t, ok, "%.15g is not soclose to %.15g", a, b, loc=loc)
return ok
}
alike :: proc(t: ^testing.T, a, b: f64, loc := #caller_location) -> bool {
@@ -1054,34 +1013,34 @@ alike :: proc(t: ^testing.T, a, b: f64, loc := #caller_location) -> bool {
case a == b:
ok = math.signbit(a) == math.signbit(b)
}
- // tc.expect(t, ok, fmt.tprintf("%.15g is not alike to %.15g", a, b), loc)
+ testing.expectf(t, ok, "%.15g is not alike to %.15g", a, b, loc=loc)
return ok
}
@test
-test_nan :: proc(t: ^testing.T) {
+test_nan32 :: proc(t: ^testing.T) {
+ float32 := f32(NaN)
+ equal := float32 == float32
+ testing.expectf(t, !equal, "float32(NaN) is %.15g, expected NaN", float32)
+}
+
+@test
+test_nan64 :: proc(t: ^testing.T) {
float64 := NaN
- if float64 == float64 {
- tc.errorf(t, "NaN returns %.15g, expected NaN", float64)
- }
- float32 := f32(float64)
- if float32 == float32 {
- tc.errorf(t, "float32(NaN) is %.15g, expected NaN", float32)
- }
+ equal := float64 == float64
+ testing.expectf(t, !equal, "NaN returns %.15g, expected NaN", float64)
}
@test
test_acos :: proc(t: ^testing.T) {
for _, i in vf {
a := vf[i] / 10
- if f := math.acos(a); !close(t, acos[i], f) {
- tc.errorf(t, "math.acos(%.15g) = %.15g, want %.15g", a, f, acos[i])
- }
+ f := math.acos(a)
+ testing.expectf(t, close(t, acos[i], f), "math.acos(%.15g) = %.15g, want %.15g", a, f, acos[i])
}
for _, i in vfacos_sc {
- if f := math.acos(vfacos_sc[i]); !alike(t, acos_sc[i], f) {
- tc.errorf(t, "math.acos(%.15g) = %.15g, want %.15g", vfacos_sc[i], f, acos_sc[i])
- }
+ f := math.acos(vfacos_sc[i])
+ testing.expectf(t, alike(t, acos_sc[i], f), "math.acos(%.15g) = %.15g, want %.15g", vfacos_sc[i], f, acos_sc[i])
}
}
@@ -1089,14 +1048,12 @@ test_acos :: proc(t: ^testing.T) {
test_acosh :: proc(t: ^testing.T) {
for _, i in vf {
a := 1 + abs(vf[i])
- if f := math.acosh(a); !veryclose(t, acosh[i], f) {
- tc.errorf(t, "math.acosh(%.15g) = %.15g, want %.15g", a, f, acosh[i])
- }
+ f := math.acosh(a)
+ testing.expectf(t, veryclose(t, acosh[i], f), "math.acosh(%.15g) = %.15g, want %.15g", a, f, acosh[i])
}
for _, i in vfacosh_sc {
- if f := math.acosh(vfacosh_sc[i]); !alike(t, acosh_sc[i], f) {
- tc.errorf(t, "math.acosh(%.15g) = %.15g, want %.15g", vfacosh_sc[i], f, acosh_sc[i])
- }
+ f := math.acosh(vfacosh_sc[i])
+ testing.expectf(t, alike(t, acosh_sc[i], f), "math.acosh(%.15g) = %.15g, want %.15g", vfacosh_sc[i], f, acosh_sc[i])
}
}
@@ -1104,42 +1061,36 @@ test_acosh :: proc(t: ^testing.T) {
test_asin :: proc(t: ^testing.T) {
for _, i in vf {
a := vf[i] / 10
- if f := math.asin(a); !veryclose(t, asin[i], f) {
- tc.errorf(t, "math.asin(%.15g) = %.15g, want %.15g", a, f, asin[i])
- }
+ f := math.asin(a)
+ testing.expectf(t, veryclose(t, asin[i], f), "math.asin(%.15g) = %.15g, want %.15g", a, f, asin[i])
}
for _, i in vfasin_sc {
- if f := math.asin(vfasin_sc[i]); !alike(t, asin_sc[i], f) {
- tc.errorf(t, "math.asin(%.15g) = %.15g, want %.15g", vfasin_sc[i], f, asin_sc[i])
- }
+ f := math.asin(vfasin_sc[i])
+ testing.expectf(t, alike(t, asin_sc[i], f), "math.asin(%.15g) = %.15g, want %.15g", vfasin_sc[i], f, asin_sc[i])
}
}
@test
test_asinh :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.asinh(vf[i]); !veryclose(t, asinh[i], f) {
- tc.errorf(t, "math.asinh(%.15g) = %.15g, want %.15g", vf[i], f, asinh[i])
- }
+ f := math.asinh(vf[i])
+ testing.expectf(t, veryclose(t, asinh[i], f), "math.asinh(%.15g) = %.15g, want %.15g", vf[i], f, asinh[i])
}
for _, i in vfasinh_sc {
- if f := math.asinh(vfasinh_sc[i]); !alike(t, asinh_sc[i], f) {
- tc.errorf(t, "math.asinh(%.15g) = %.15g, want %.15g", vfasinh_sc[i], f, asinh_sc[i])
- }
+ f := math.asinh(vfasinh_sc[i])
+ testing.expectf(t, alike(t, asinh_sc[i], f), "math.asinh(%.15g) = %.15g, want %.15g", vfasinh_sc[i], f, asinh_sc[i])
}
}
@test
test_atan :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.atan(vf[i]); !veryclose(t, atan[i], f) {
- tc.errorf(t, "math.atan(%.15g) = %.15g, want %.15g", vf[i], f, atan[i])
- }
+ f := math.atan(vf[i])
+ testing.expectf(t, veryclose(t, atan[i], f), "math.atan(%.15g) = %.15g, want %.15g", vf[i], f, atan[i])
}
for _, i in vfatan_sc {
- if f := math.atan(vfatan_sc[i]); !alike(t, atan_sc[i], f) {
- tc.errorf(t, "math.atan(%.15g) = %.15g, want %.15g", vfatan_sc[i], f, atan_sc[i])
- }
+ f := math.atan(vfatan_sc[i])
+ testing.expectf(t, alike(t, atan_sc[i], f), "math.atan(%.15g) = %.15g, want %.15g", vfatan_sc[i], f, atan_sc[i])
}
}
@@ -1147,84 +1098,72 @@ test_atan :: proc(t: ^testing.T) {
test_atanh :: proc(t: ^testing.T) {
for _, i in vf {
a := vf[i] / 10
- if f := math.atanh(a); !veryclose(t, atanh[i], f) {
- tc.errorf(t, "math.atanh(%.15g) = %.15g, want %.15g", a, f, atanh[i])
- }
+ f := math.atanh(a)
+ testing.expectf(t, veryclose(t, atanh[i], f), "math.atanh(%.15g) = %.15g, want %.15g", a, f, atanh[i])
}
for _, i in vfatanh_sc {
- if f := math.atanh(vfatanh_sc[i]); !alike(t, atanh_sc[i], f) {
- tc.errorf(t, "math.atanh(%.15g) = %.15g, want %.15g", vfatanh_sc[i], f, atanh_sc[i])
- }
+ f := math.atanh(vfatanh_sc[i])
+ testing.expectf(t, alike(t, atanh_sc[i], f), "math.atanh(%.15g) = %.15g, want %.15g", vfatanh_sc[i], f, atanh_sc[i])
}
}
@test
test_atan2 :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.atan2(10, vf[i]); !veryclose(t, atan2[i], f) {
- tc.errorf(t, "math.atan2(10, %.15g) = %.15g, want %.15g", vf[i], f, atan2[i])
- }
+ f := math.atan2(10, vf[i])
+ testing.expectf(t, veryclose(t, atan2[i], f), "math.atan2(10, %.15g) = %.15g, want %.15g", vf[i], f, atan2[i])
}
for _, i in vfatan2_sc {
- if f := math.atan2(vfatan2_sc[i][0], vfatan2_sc[i][1]); !alike(t, atan2_sc[i], f) {
- tc.errorf(t, "math.atan2(%.15g, %.15g) = %.15g, want %.15g", vfatan2_sc[i][0], vfatan2_sc[i][1], f, atan2_sc[i])
- }
+ f := math.atan2(vfatan2_sc[i][0], vfatan2_sc[i][1])
+ testing.expectf(t, alike(t, atan2_sc[i], f), "math.atan2(%.15g, %.15g) = %.15g, want %.15g", vfatan2_sc[i][0], vfatan2_sc[i][1], f, atan2_sc[i])
}
}
@test
test_cos :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.cos(vf[i]); !veryclose(t, cos[i], f) {
- tc.errorf(t, "math.cos(%.15g) = %.15g, want %.15g", vf[i], f, cos[i])
- }
+ f := math.cos(vf[i])
+ testing.expectf(t, veryclose(t, cos[i], f), "math.cos(%.15g) = %.15g, want %.15g", vf[i], f, cos[i])
}
for _, i in vfcos_sc {
- if f := math.cos(vfcos_sc[i]); !alike(t, cos_sc[i], f) {
- tc.errorf(t, "math.cos(%.15g) = %.15g, want %.15g", vfcos_sc[i], f, cos_sc[i])
- }
+ f := math.cos(vfcos_sc[i])
+ testing.expectf(t, alike(t, cos_sc[i], f), "math.cos(%.15g) = %.15g, want %.15g", vfcos_sc[i], f, cos_sc[i])
}
}
@test
test_cosh :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.cosh(vf[i]); !close(t, cosh[i], f) {
- tc.errorf(t, "math.cosh(%.15g) = %.15g, want %.15g", vf[i], f, cosh[i])
- }
+ f := math.cosh(vf[i])
+ testing.expectf(t, close(t, cosh[i], f), "math.cosh(%.15g) = %.15g, want %.15g", vf[i], f, cosh[i])
}
for _, i in vfcosh_sc {
- if f := math.cosh(vfcosh_sc[i]); !alike(t, cosh_sc[i], f) {
- tc.errorf(t, "math.cosh(%.15g) = %.15g, want %.15g", vfcosh_sc[i], f, cosh_sc[i])
- }
+ f := math.cosh(vfcosh_sc[i])
+ testing.expectf(t, alike(t, cosh_sc[i], f), "math.cosh(%.15g) = %.15g, want %.15g", vfcosh_sc[i], f, cosh_sc[i])
}
}
@test
test_sin :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.sin(vf[i]); !veryclose(t, sin[i], f) {
- tc.errorf(t, "math.sin(%.15g) = %.15g, want %.15g", vf[i], f, sin[i])
- }
+ f := math.sin(vf[i])
+ testing.expectf(t, veryclose(t, sin[i], f), "math.sin(%.15g) = %.15g, want %.15g", vf[i], f, sin[i])
}
for _, i in vfsin_sc {
- if f := math.sin(vfsin_sc[i]); !alike(t, sin_sc[i], f) {
- tc.errorf(t, "math.sin(%.15g) = %.15g, want %.15g", vfsin_sc[i], f, sin_sc[i])
- }
+ f := math.sin(vfsin_sc[i])
+ testing.expectf(t, alike(t, sin_sc[i], f), "math.sin(%.15g) = %.15g, want %.15g", vfsin_sc[i], f, sin_sc[i])
}
}
@test
test_sinh :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.sinh(vf[i]); !close(t, sinh[i], f) {
- tc.errorf(t, "math.sinh(%.15g) = %.15g, want %.15g", vf[i], f, sinh[i])
- }
+ f := math.sinh(vf[i])
+ testing.expectf(t, close(t, sinh[i], f), "math.sinh(%.15g) = %.15g, want %.15g", vf[i], f, sinh[i])
}
for _, i in vfsinh_sc {
- if f := math.sinh(vfsinh_sc[i]); !alike(t, sinh_sc[i], f) {
- tc.errorf(t, "math.sinh(%.15g) = %.15g, want %.15g", vfsinh_sc[i], f, sinh_sc[i])
- }
+ f := math.sinh(vfsinh_sc[i])
+ testing.expectf(t, alike(t, sinh_sc[i], f), "math.sinh(%.15g) = %.15g, want %.15g", vfsinh_sc[i], f, sinh_sc[i])
}
}
@@ -1232,38 +1171,33 @@ test_sinh :: proc(t: ^testing.T) {
test_sqrt :: proc(t: ^testing.T) {
for _, i in vf {
a := abs(vf[i])
- if f := math.sqrt(a); !veryclose(t, sqrt[i], f) {
- tc.errorf(t, "math.sqrt(%.15g) = %.15g, want %.15g", a, f, sqrt[i])
- }
+ f := math.sqrt(a)
+ testing.expectf(t, veryclose(t, sqrt[i], f), "math.sqrt(%.15g) = %.15g, want %.15g", a, f, sqrt[i])
}
}
@test
test_tan :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.tan(vf[i]); !veryclose(t, tan[i], f) {
- tc.errorf(t, "math.tan(%.15g) = %.15g, want %.15g", vf[i], f, tan[i])
- }
+ f := math.tan(vf[i])
+ testing.expectf(t, veryclose(t, tan[i], f), "math.tan(%.15g) = %.15g, want %.15g", vf[i], f, tan[i])
}
// same special cases as Sin
for _, i in vfsin_sc {
- if f := math.tan(vfsin_sc[i]); !alike(t, sin_sc[i], f) {
- tc.errorf(t, "math.tan(%.15g) = %.15g, want %.15g", vfsin_sc[i], f, sin_sc[i])
- }
+ f := math.tan(vfsin_sc[i])
+ testing.expectf(t, alike(t, sin_sc[i], f), "math.tan(%.15g) = %.15g, want %.15g", vfsin_sc[i], f, sin_sc[i])
}
}
@test
test_tanh :: proc(t: ^testing.T) {
for _, i in vf {
- if f := math.tanh(vf[i]); !veryclose(t, tanh[i], f) {
- tc.errorf(t, "math.tanh(%.15g) = %.15g, want %.15g", vf[i], f, tanh[i])
- }
+ f := math.tanh(vf[i])
+ testing.expectf(t, veryclose(t, tanh[i], f), "math.tanh(%.15g) = %.15g, want %.15g", vf[i], f, tanh[i])
}
for _, i in vftanh_sc {
- if f := math.tanh(vftanh_sc[i]); !alike(t, tanh_sc[i], f) {
- tc.errorf(t, "math.tanh(%.15g) = %.15g, want %.15g", vftanh_sc[i], f, tanh_sc[i])
- }
+ f := math.tanh(vftanh_sc[i])
+ testing.expectf(t, alike(t, tanh_sc[i], f), "math.tanh(%.15g) = %.15g, want %.15g", vftanh_sc[i], f, tanh_sc[i])
}
}
@@ -1273,9 +1207,7 @@ test_large_cos :: proc(t: ^testing.T) {
for _, i in vf {
f1 := cosLarge[i]
f2 := math.cos(vf[i] + large)
- if !close(t, f1, f2) {
- tc.errorf(t, "math.cos(%.15g) = %.15g, want %.15g", vf[i]+large, f2, f1)
- }
+ testing.expectf(t, close(t, f1, f2), "math.cos(%.15g) = %.15g, want %.15g", vf[i]+large, f2, f1)
}
}
@@ -1285,9 +1217,7 @@ test_large_sin :: proc(t: ^testing.T) {
for _, i in vf {
f1 := sinLarge[i]
f2 := math.sin(vf[i] + large)
- if !close(t, f1, f2) {
- tc.errorf(t, "math.sin(%.15g) = %.15g, want %.15g", vf[i]+large, f2, f1)
- }
+ testing.expectf(t, close(t, f1, f2), "math.sin(%.15g) = %.15g, want %.15g", vf[i]+large, f2, f1)
}
}
@@ -1297,8 +1227,6 @@ test_large_tan :: proc(t: ^testing.T) {
for _, i in vf {
f1 := tanLarge[i]
f2 := math.tan(vf[i] + large)
- if !close(t, f1, f2) {
- tc.errorf(t, "math.tan(%.15g) = %.15g, want %.15g", vf[i]+large, f2, f1)
- }
+ testing.expectf(t, close(t, f1, f2), "math.tan(%.15g) = %.15g, want %.15g", vf[i]+large, f2, f1)
}
} \ No newline at end of file