From d0f3280bf5aa7c71ad0feabb4c92a7426c064ecb Mon Sep 17 00:00:00 2001
From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com>
Date: Sun, 22 Oct 2017 23:40:37 -0400
Subject: [PATCH] chore: added unit test demonstrating bug when using
 multidimensional arrays.

---
 .../java/com/aparapi/runtime/Issue51Test.java | 88 +++++++++++++++++++
 .../java/com/aparapi/runtime/Issue69Test.java |  8 +-
 2 files changed, 92 insertions(+), 4 deletions(-)
 create mode 100644 src/test/java/com/aparapi/runtime/Issue51Test.java

diff --git a/src/test/java/com/aparapi/runtime/Issue51Test.java b/src/test/java/com/aparapi/runtime/Issue51Test.java
new file mode 100644
index 00000000..ee5203e9
--- /dev/null
+++ b/src/test/java/com/aparapi/runtime/Issue51Test.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2016 - 2017 Syncleus, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.aparapi.runtime;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.aparapi.Kernel;
+import com.aparapi.Range;
+
+public class Issue51Test
+{
+    @Test
+    public void passingTest()
+    {
+        final int SIZE = 16;
+        final float[] RESULT = new float[] {1};
+        Kernel kernel = new Kernel()
+        {
+            @Local final float[] localArray = new float[SIZE*SIZE];
+
+            @Override
+            public void run()
+            {
+                int row = getGlobalId(0);
+                int column = getGlobalId(1);
+                localArray[row + column*SIZE] = row + column;
+                localBarrier();
+                float value = 0;
+                for (int x = 0; x < SIZE; x++)
+                {
+                    for (int y = 0; y < SIZE; y++)
+                    {
+                        value += localArray[x + y*SIZE];
+                    }
+                }
+                RESULT[0] = value;
+            }
+        };
+        kernel.execute(Range.create2D(SIZE, SIZE, SIZE, SIZE));
+        assertEquals(3840, RESULT[0], 1E-6F);
+    }
+
+    @Test
+    public void crashingTest()
+    {
+        final int SIZE = 16;
+        final float[] RESULT = new float[] {1};
+        Kernel kernel = new Kernel()
+        {
+            @Local final float[][] localArray = new float[SIZE][SIZE];
+
+            @Override
+            public void run()
+            {
+                int row = getGlobalId(0);
+                int column = getGlobalId(1);
+                localArray[row][column] = row + column;
+                localBarrier();
+                float value = 0;
+                for (int x = 0; x < SIZE; x++)
+                {
+                    for (int y = 0; y < SIZE; y++)
+                    {
+                        value += localArray[x][y];
+                    }
+                }
+                RESULT[0] = value;
+            }
+        };
+        kernel.execute(Range.create2D(SIZE, SIZE, SIZE, SIZE));
+        assertEquals(3840, RESULT[0], 1E-6F);
+    }
+}
diff --git a/src/test/java/com/aparapi/runtime/Issue69Test.java b/src/test/java/com/aparapi/runtime/Issue69Test.java
index 8f2aa47a..d33243cb 100644
--- a/src/test/java/com/aparapi/runtime/Issue69Test.java
+++ b/src/test/java/com/aparapi/runtime/Issue69Test.java
@@ -1,12 +1,12 @@
 /**
  * Copyright (c) 2016 - 2017 Syncleus, Inc.
- * <p>
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- 
GitLab