From 52dce5ab2ce226688ecc2c744d64d88910017cc6 Mon Sep 17 00:00:00 2001
From: CoreRasurae <luis.p.mendes@gmail.com>
Date: Thu, 22 Aug 2019 01:10:37 +0100
Subject: [PATCH] Test: Add test for #153 - IntArray2DTest (refs #153)

---
 .../com/aparapi/runtime/IntArray2DTest.java   | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 src/test/java/com/aparapi/runtime/IntArray2DTest.java

diff --git a/src/test/java/com/aparapi/runtime/IntArray2DTest.java b/src/test/java/com/aparapi/runtime/IntArray2DTest.java
new file mode 100644
index 00000000..98b27402
--- /dev/null
+++ b/src/test/java/com/aparapi/runtime/IntArray2DTest.java
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2016 - 2018 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 com.aparapi.Kernel;
+import com.aparapi.Range;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class IntArray2DTest {
+    @Test
+    public void test() {
+        int size = 1048576;
+        final int count = 3;
+        final int[][] V = new int[count][size];
+
+        //lets fill in V randomly...
+        for (int j = 0; j < count; j++) {
+            for (int i = 0; i < size; i++) {
+                //random number either 0, 1, or 2
+                V[j][i] = (int) (Math.random() * 3);
+            }
+        }
+
+        Kernel sumConstantKernel= null;
+        final int totals[][] = V;
+        try {
+            sumConstantKernel = new Kernel() {
+                @Override
+                public void run() {
+                    int gid = getGlobalId();
+                    for(int index = 0; index < count; index++) {
+                        totals[index][gid] += gid + 1;
+                    }
+                }
+            };
+            sumConstantKernel.execute(Range.create(size));
+        } finally {
+            sumConstantKernel.dispose();
+        }
+
+        for (int index = 0; index < count; index++) {
+            for (int gid = 0; gid < size; gid++) {
+                assertEquals(V[index][gid] + gid + 1, totals[index][gid]);
+            }
+        }
+    }
+}
\ No newline at end of file
-- 
GitLab