aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-09-07 13:43:19 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2024-09-07 13:43:19 +0200
commitd2202416d2fd5e52d835cf2268352e7279fbdf0c (patch)
treeb350ac3cf65735507cd78cb83f33b2e37dde5fb5
parent0a08a65202ca40857e580036c561bcbf940a6870 (diff)
Add test for #4210
-rw-r--r--tests/issues/run.bat1
-rwxr-xr-xtests/issues/run.sh1
-rw-r--r--tests/issues/test_issue_4210.odin85
3 files changed, 87 insertions, 0 deletions
diff --git a/tests/issues/run.bat b/tests/issues/run.bat
index 299e08791..dcea3d483 100644
--- a/tests/issues/run.bat
+++ b/tests/issues/run.bat
@@ -15,6 +15,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style
..\..\..\odin test ..\test_issue_2615.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2637.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2666.odin %COMMON% || exit /b
+..\..\..\odin test ..\test_issue_4210.odin %COMMON% || exit /b
@echo off
diff --git a/tests/issues/run.sh b/tests/issues/run.sh
index 8b4c1e7f2..c3bc00e24 100755
--- a/tests/issues/run.sh
+++ b/tests/issues/run.sh
@@ -16,6 +16,7 @@ $ODIN test ../test_issue_2466.odin $COMMON
$ODIN test ../test_issue_2615.odin $COMMON
$ODIN test ../test_issue_2637.odin $COMMON
$ODIN test ../test_issue_2666.odin $COMMON
+$ODIN test ../test_issue_4210.odin $COMMON
if [[ $($ODIN build ../test_issue_2395.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 2 ]] ; then
echo "SUCCESSFUL 1/1"
else
diff --git a/tests/issues/test_issue_4210.odin b/tests/issues/test_issue_4210.odin
new file mode 100644
index 000000000..fc361e98e
--- /dev/null
+++ b/tests/issues/test_issue_4210.odin
@@ -0,0 +1,85 @@
+// Tests issue #4210 https://github.com/odin-lang/Odin/issues/4210
+package test_issues
+
+import "core:testing"
+import "base:intrinsics"
+
+@test
+test_row_major_matrix :: proc(t: ^testing.T) {
+ row_major34: #row_major matrix[3,4]int = {
+ 11,12,13,14,
+ 21,22,23,24,
+ 31,32,33,34,
+ }
+ row_major34_expected := [?]int{11,12,13,14, 21,22,23,24, 31,32,33,34}
+
+ row_major43: #row_major matrix[4,3]int = {
+ 11,12,13,
+ 21,22,23,
+ 31,32,33,
+ 41,42,43,
+ }
+ row_major43_expected := [?]int{11,12,13, 21,22,23, 31,32,33, 41,42,43}
+
+ major34_flattened := intrinsics.matrix_flatten(row_major34)
+ major34_casted := (^[3 * 4]int)(&row_major34)^
+
+ for row in 0..<3 {
+ for column in 0..<4 {
+ idx := row * 4 + column
+ testing.expect_value(t, major34_flattened[idx], row_major34_expected[idx])
+ testing.expect_value(t, major34_casted [idx], row_major34_expected[idx])
+ }
+ }
+
+ major43_flattened := intrinsics.matrix_flatten(row_major43)
+ major43_casted := (^[4 * 3]int)(&row_major43)^
+
+ for row in 0..<4 {
+ for column in 0..<3 {
+ idx := row * 3 + column
+ testing.expect_value(t, major43_flattened[idx], row_major43_expected[idx])
+ testing.expect_value(t, major43_casted [idx], row_major43_expected[idx])
+ }
+ }
+}
+
+@test
+test_row_minor_matrix :: proc(t: ^testing.T) {
+ row_minor34: matrix[3,4]int = {
+ 11,12,13,14,
+ 21,22,23,24,
+ 31,32,33,34,
+ }
+ row_minor34_expected := [?]int{11,21,31, 12,22,32, 13,23,33, 14,24,34}
+
+ row_minor43: matrix[4,3]int = {
+ 11,12,13,
+ 21,22,23,
+ 31,32,33,
+ 41,42,43,
+ }
+ row_minor43_expected := [?]int{11,21,31,41, 12,22,32,42, 13,23,33,43}
+
+ minor34_flattened := intrinsics.matrix_flatten(row_minor34)
+ minor34_casted := (^[3 * 4]int)(&row_minor34)^
+
+ for row in 0..<3 {
+ for column in 0..<4 {
+ idx := row * 4 + column
+ testing.expect_value(t, minor34_flattened[idx], row_minor34_expected[idx])
+ testing.expect_value(t, minor34_casted [idx], row_minor34_expected[idx])
+ }
+ }
+
+ minor43_flattened := intrinsics.matrix_flatten(row_minor43)
+ minor43_casted := (^[4 * 3]int)(&row_minor43)^
+
+ for row in 0..<4 {
+ for column in 0..<3 {
+ idx := row * 3 + column
+ testing.expect_value(t, minor43_flattened[idx], row_minor43_expected[idx])
+ testing.expect_value(t, minor43_casted [idx], row_minor43_expected[idx])
+ }
+ }
+} \ No newline at end of file