changeset 7609:62464bba05b2

Fix IntStreamTest.java because IntStream.sum() return int
author Tristan Yan <tristan.yan@oracle.com>
date Tue, 12 Mar 2013 13:45:05 +0800
parents 88776f695148
children 1047164c8255
files test/java/util/LambdaUtilities.java test/java/util/stream/Stream/IntStreamTest.java
diffstat 2 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/util/LambdaUtilities.java	Mon Mar 11 22:20:29 2013 -0400
+++ b/test/java/util/LambdaUtilities.java	Tue Mar 12 13:45:05 2013 +0800
@@ -327,7 +327,7 @@
     }
 
     public static Supplier<AtomicInteger> atomicIntegerSupplier(int value) {
-        return () -> new AtomicInteger(0);
+        return () -> new AtomicInteger(value);
     }
 
     public static <T> Supplier<AtomicReference<T>> atomicGenericSupplier(T value) {
--- a/test/java/util/stream/Stream/IntStreamTest.java	Mon Mar 11 22:20:29 2013 -0400
+++ b/test/java/util/stream/Stream/IntStreamTest.java	Tue Mar 12 13:45:05 2013 +0800
@@ -32,6 +32,7 @@
 
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.function.BiFunction;
 import java.util.function.IntPredicate;
@@ -174,12 +175,14 @@
             IntStream avgStream1 = (p == ParallelType.Parallel) ? Arrays.parallelStream(array)
                     : (p == ParallelType.Sequential) ? Arrays.stream(array).sequential() :
                     Arrays.stream(array);
-            long total1 = 0;
+            double total1 = 0;
+            int intTotal1 = 0;
             for(int index = 0; index < array.length; index++) {
                 total1 += array[index];
+                intTotal1 += array[index];
             }
-            assertEquals(avgStream1.average().getAsDouble(), (double)total1 / array.length);
-            assertEquals(sumStream1.sum(), total1);
+            assertEquals(avgStream1.average().getAsDouble(), total1 / array.length);
+            assertEquals(sumStream1.sum(), intTotal1);
 
             int startIndex = rand.nextInt(array.length);
             int endIndex = startIndex + rand.nextInt(array.length - startIndex + 1);
@@ -193,12 +196,14 @@
                assertEquals(avgStream2.average(), OptionalDouble.empty());
                assertEquals(sumStream2.sum(), 0);
             } else {
-                long total2 = 0;
+                double total2 = 0;
+                int intTotal2 = 0;
                 for(int index = startIndex; index < endIndex; index++) {
                     total2 += array[index];
+                    intTotal2 += array[index];
                 }
-                assertEquals(avgStream2.average().getAsDouble(), (double)total2 / (endIndex - startIndex));
-                assertEquals(sumStream2.sum(), total2);
+                assertEquals(avgStream2.average().getAsDouble(), total2 / (endIndex - startIndex));
+                assertEquals(sumStream2.sum(), intTotal2);
             }
         }
     }
@@ -624,14 +629,14 @@
             IntStream stream1 = (p == ParallelType.Parallel) ? Arrays.parallelStream(array)
                     : (p == ParallelType.Sequential) ? Arrays.stream(array).sequential() :
                     Arrays.stream(array);
-            AtomicLong ai1 = new AtomicLong(0);
-            long sum = stream1.peek(LambdaUtilities.addLongConsumer(ai1)).sum();
+            AtomicInteger ai1 = new AtomicInteger(0);
+            int sum = stream1.peek(LambdaUtilities.addIntConsumer(ai1)).sum();
             assertEquals(ai1.get(), sum);
 
             IntStream emptyStream = (p == ParallelType.Parallel) ? Arrays.parallelStream(new int[0]):
                     (p == ParallelType.Sequential) ? Arrays.stream(new int[0]).sequential() :
                     Arrays.stream(new int[0]);
-            assertFalse(emptyStream.peek(LambdaUtilities.addLongConsumer(ai1)).iterator().hasNext());
+            assertFalse(emptyStream.peek(LambdaUtilities.addIntConsumer(ai1)).iterator().hasNext());
             assertEquals(ai1.get(), sum);
         }
     }