changeset 7627:214c838ad4bd

Add back test for Arrays.parallelPrefix(double[]...)
author Tristan Yan <tristan.yan@oracle.com>
date Wed, 13 Mar 2013 16:07:35 +0800
parents 85912d2b4773
children f136adc07108
files test/java/util/Arrays/ParallelPrefixTest.java
diffstat 1 files changed, 23 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/util/Arrays/ParallelPrefixTest.java	Tue Mar 12 22:38:54 2013 -0400
+++ b/test/java/util/Arrays/ParallelPrefixTest.java	Wed Mar 13 16:07:35 2013 +0800
@@ -27,7 +27,7 @@
  * @library ../
  * @(#) ArraysTest.java
  * @author Tristan Yan
- * @run testng/othervm -mx512m ParallelPrefixTest
+ * @run testng ParallelPrefixTest
  */
 
 import java.util.Arrays;
@@ -40,7 +40,7 @@
 
     private final static int MIN_LEN = 1 << 2;
 
-    private final static int MAX_LEN = 1 << 12;
+    private final static int MAX_LEN = 1 << 6;
 
     private final static Random rand = new Random(System.currentTimeMillis());
 
@@ -62,8 +62,10 @@
 
     private double[] generateDoubleData(int size) {
         double[] array = new double[size];
+        //Precision could be changed when do parallel calculation, we only use
+        //integer to test it to prevent precision lost issue
         for(int i = 0; i < size; i++) {
-            array[i] = rand.nextDouble();
+            array[i] = rand.nextInt(1024);
         }
         return array;
     }
@@ -123,27 +125,24 @@
 
     @Test
     public void testParallelPrefixForDouble() {
-        //This has potential bug becuase percision could be changed when do
-        //parallel calculation, maybe we should remove parallelPrefix because
-        //it's not so useful
-//                int startIndex = rand.nextInt(ARRAY_SIZE);
-//        int endIndex = startIndex + rand.nextInt(ARRAY_SIZE + 1 - startIndex);
-//        double[] doubleArr1 = generateDoubleData(ARRAY_SIZE);
-//        double[] doubleArr2 = Arrays.copyOf(doubleArr1, ARRAY_SIZE);
-//        double[] doubleBackArr = Arrays.copyOf(doubleArr1, ARRAY_SIZE);
-//        Arrays.parallelPrefix(doubleArr1, LambdaUtilities.addDoubleBinaryOperator());
-//        assertEquals(doubleArr1.length, doubleBackArr.length);
-//        long totalDouble = 0;
-//        for(int i = 0; i < ARRAY_SIZE; i++) {
-//            totalDouble += doubleBackArr[i];
-//            assertEquals(totalDouble, doubleArr1[i]);
-//        }
-//        Arrays.parallelPrefix(doubleArr2, startIndex, endIndex, LambdaUtilities.addDoubleBinaryOperator());
-//        totalDouble = 0;
-//        for(int i = startIndex; i < endIndex; i++) {
-//            totalDouble += doubleBackArr[i];
-//            assertEquals(totalDouble, doubleArr2[i]);
-//        }
+        int startIndex = rand.nextInt(ARRAY_SIZE);
+        int endIndex = startIndex + rand.nextInt(ARRAY_SIZE + 1 - startIndex);
+        double[] doubleArr1 = generateDoubleData(ARRAY_SIZE);
+        double[] doubleArr2 = Arrays.copyOf(doubleArr1, ARRAY_SIZE);
+        double[] doubleBackArr = Arrays.copyOf(doubleArr1, ARRAY_SIZE);
+        Arrays.parallelPrefix(doubleArr1, LambdaUtilities.addDoubleBinaryOperator());
+        assertEquals(doubleArr1.length, doubleBackArr.length);
+        double totalDouble = 0;
+        for(int i = 0; i < ARRAY_SIZE; i++) {
+            totalDouble += doubleBackArr[i];
+            assertEquals(totalDouble, doubleArr1[i]);
+        }
+        Arrays.parallelPrefix(doubleArr2, startIndex, endIndex, LambdaUtilities.addDoubleBinaryOperator());
+        totalDouble = 0;
+        for(int i = startIndex; i < endIndex; i++) {
+            totalDouble += doubleBackArr[i];
+            assertEquals(totalDouble, doubleArr2[i]);
+        }
     }
 
     @Test