changeset 7840:4317c86ff03e

Unit tests for JDK-8011715 - typos in XxxSummaryStatistics
author briangoetz
date Mon, 08 Apr 2013 12:45:45 -0400
parents 3d940b4308ee
children 3a84da0da6dc
files test-ng/tests/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java
diffstat 1 files changed, 38 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java	Mon Apr 08 12:30:39 2013 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java	Mon Apr 08 12:45:45 2013 -0400
@@ -24,14 +24,18 @@
  */
 package org.openjdk.tests.java.util.stream;
 
+import java.util.ArrayList;
 import java.util.DoubleSummaryStatistics;
 import java.util.IntSummaryStatistics;
+import java.util.List;
 import java.util.LongSummaryStatistics;
 import java.util.stream.Collectors;
 import java.util.stream.OpTestCase;
 import java.util.stream.Stream;
 import java.util.stream.StreamTestData;
 
+import org.testng.annotations.Test;
+
 import static java.util.stream.LambdaTestHelpers.countTo;
 
 /**
@@ -39,46 +43,50 @@
  *
  * @author Brian Goetz
  */
+@Test
 public class SummaryStatisticsTest extends OpTestCase {
     public void testIntStatistics() {
-        IntSummaryStatistics stats = countTo(1000).stream().collect(Collectors.toIntSummaryStatistics(i -> i));
-        assertEquals(stats.getCount(), 1000);
-        assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum());
-        assertEquals(stats.getMax(), 1000);
-        assertEquals(stats.getMin(), 1);
+        List<IntSummaryStatistics> instances = new ArrayList<>();
+        instances.add(countTo(1000).stream().collect(Collectors.toIntSummaryStatistics(i -> i)));
+        instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics());
+        instances.add(countTo(1000).parallelStream().collect(Collectors.toIntSummaryStatistics(i -> i)));
+        instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics());
 
-        stats = countTo(1000).stream().mapToInt(i -> i).summaryStatistics();
-        assertEquals(stats.getCount(), 1000);
-        assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum());
-        assertEquals(stats.getMax(), 1000);
-        assertEquals(stats.getMin(), 1);
+        for (IntSummaryStatistics stats : instances) {
+            assertEquals(stats.getCount(), 1000);
+            assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum());
+            assertEquals(stats.getMax(), 1000);
+            assertEquals(stats.getMin(), 1);
+        }
     }
 
     public void testLongStatistics() {
-        LongSummaryStatistics stats = countTo(1000).stream().mapToLong(i -> i).boxed().collect(Collectors.toLongSummaryStatistics(i -> i));
-        assertEquals(stats.getCount(), 1000);
-        assertEquals(stats.getSum(), (long) countTo(1000).stream().mapToInt(i -> i).sum());
-        assertEquals(stats.getMax(), 1000L);
-        assertEquals(stats.getMin(), 1L);
+        List<LongSummaryStatistics> instances = new ArrayList<>();
+        instances.add(countTo(1000).stream().collect(Collectors.toLongSummaryStatistics(i -> i)));
+        instances.add(countTo(1000).stream().mapToLong(i -> i).summaryStatistics());
+        instances.add(countTo(1000).parallelStream().collect(Collectors.toLongSummaryStatistics(i -> i)));
+        instances.add(countTo(1000).parallelStream().mapToLong(i -> i).summaryStatistics());
 
-        stats = countTo(1000).stream().mapToLong(i -> i).summaryStatistics();
-        assertEquals(stats.getCount(), 1000);
-        assertEquals(stats.getSum(), (long) countTo(1000).stream().mapToInt(i -> i).sum());
-        assertEquals(stats.getMax(), 1000L);
-        assertEquals(stats.getMin(), 1L);
+        for (LongSummaryStatistics stats : instances) {
+            assertEquals(stats.getCount(), 1000);
+            assertEquals(stats.getSum(), (long) countTo(1000).stream().mapToInt(i -> i).sum());
+            assertEquals(stats.getMax(), 1000L);
+            assertEquals(stats.getMin(), 1L);
+        }
     }
 
     public void testDoubleStatistics() {
-        DoubleSummaryStatistics stats = countTo(1000).stream().mapToDouble(i -> i).boxed().collect(Collectors.toDoubleSummaryStatistics(i -> i));
-        assertEquals(stats.getCount(), 1000);
-        assertEquals(stats.getSum(), (double) countTo(1000).stream().mapToInt(i -> i).sum());
-        assertEquals(stats.getMax(), 1000.0);
-        assertEquals(stats.getMin(), 1.0);
+        List<DoubleSummaryStatistics> instances = new ArrayList<>();
+        instances.add(countTo(1000).stream().collect(Collectors.toDoubleSummaryStatistics(i -> i)));
+        instances.add(countTo(1000).stream().mapToDouble(i -> i).summaryStatistics());
+        instances.add(countTo(1000).parallelStream().collect(Collectors.toDoubleSummaryStatistics(i -> i)));
+        instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).summaryStatistics());
 
-        stats = countTo(1000).stream().mapToDouble(i -> i).summaryStatistics();
-        assertEquals(stats.getCount(), 1000);
-        assertEquals(stats.getSum(), (double) countTo(1000).stream().mapToInt(i -> i).sum());
-        assertEquals(stats.getMax(), 1000.0);
-        assertEquals(stats.getMin(), 1.0);
+        for (DoubleSummaryStatistics stats : instances) {
+            assertEquals(stats.getCount(), 1000);
+            assertEquals(stats.getSum(), (double) countTo(1000).stream().mapToInt(i -> i).sum());
+            assertEquals(stats.getMax(), 1000.0);
+            assertEquals(stats.getMin(), 1.0);
+        }
     }
 }