aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNoahR02 <noahreppert95@protonmail.com>2022-02-08 06:16:10 -0500
committerNoahR02 <noahreppert95@protonmail.com>2022-02-08 06:16:10 -0500
commit817bc7434dfd0ebfeb1310c22741b9d66af67ac2 (patch)
treecead2609cdffec63b731ae1ed9adf1143cfa6b6f /tests
parent3c2ed3bb69df24ba162e5f2ea8f61ee3f7fd8e2f (diff)
Ports OpenSimplex2 from https://github.com/KdotJPG/OpenSimplex2 to Odin. Adds tests for the noise procedures.
Diffstat (limited to 'tests')
-rw-r--r--tests/core/Makefile7
-rw-r--r--tests/core/build.bat7
-rw-r--r--tests/core/math/noise/test_core_math_noise.odin153
3 files changed, 164 insertions, 3 deletions
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 0f0ffe4d6..1c2cee6bd 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -1,7 +1,7 @@
ODIN=../../odin
PYTHON=$(shell which python3)
-all: download_test_assets image_test compress_test strings_test hash_test crypto_test
+all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test
download_test_assets:
$(PYTHON) download_assets.py
@@ -19,4 +19,7 @@ hash_test:
$(ODIN) run hash -out=test_hash -o:speed -no-bounds-check
crypto_test:
- $(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check \ No newline at end of file
+ $(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check
+
+noise_test:
+ $(ODIN) run math/noise -out=test_noise \ No newline at end of file
diff --git a/tests/core/build.bat b/tests/core/build.bat
index 176b7f175..6af39e688 100644
--- a/tests/core/build.bat
+++ b/tests/core/build.bat
@@ -35,4 +35,9 @@ echo ---
echo ---
echo Running core:encoding tests
echo ---
-%PATH_TO_ODIN% run encoding %COMMON% \ No newline at end of file
+%PATH_TO_ODIN% run encoding %COMMON%
+
+echo ---
+echo Running core:math/noise tests
+echo ---
+%PATH_TO_ODIN% run math/noise %COMMON% \ 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
new file mode 100644
index 000000000..a3ac1b955
--- /dev/null
+++ b/tests/core/math/noise/test_core_math_noise.odin
@@ -0,0 +1,153 @@
+package test_core_math_noise
+
+import "core:testing"
+import "core:math/noise"
+import "core:fmt"
+
+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) {
+ fmt.printf("[%v] ", loc)
+ TEST_count += 1
+ if !condition {
+ TEST_fail += 1
+ fmt.println(message)
+ return
+ }
+ fmt.println(" PASS")
+ }
+ 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)
+}
+
+Test_Vector :: struct {
+ seed: i64,
+ coord: union {V2, V3, V4},
+ expected: f32,
+
+ test_proc: union {
+ proc(_: i64, _: V2) -> f32,
+ proc(_: i64, _: V3) -> f32,
+ proc(_: i64, _: V4) -> f32,
+ },
+}
+
+SEED_1 :: 2324223232
+SEED_2 :: 932466901
+SEED_3 :: 9321
+
+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},
+
+ // TODO: Output according to C# - Figure out which of these two is right (and why).
+ // {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},
+}
+
+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)
+ }
+} \ No newline at end of file