changeset 8358:dcafeb140b38

Update tests for range changes
author briangoetz
date Mon, 22 Apr 2013 21:13:22 -0400
parents 427053023319
children 31fa4e4e6d0e
files test-ng/bootlib/java/util/stream/IntStreamTestDataProvider.java test-ng/bootlib/java/util/stream/LongStreamTestDataProvider.java test-ng/tests/org/openjdk/tests/java/util/stream/RangeTest.java
diffstat 3 files changed, 46 insertions(+), 137 deletions(-) [+]
line wrap: on
line diff
--- a/test-ng/bootlib/java/util/stream/IntStreamTestDataProvider.java	Mon Apr 22 21:13:06 2013 -0400
+++ b/test-ng/bootlib/java/util/stream/IntStreamTestDataProvider.java	Mon Apr 22 21:13:22 2013 -0400
@@ -103,15 +103,6 @@
                                          () -> IntStream.range(0, ints.length, 3)));
                 list.add(streamDataDescr("IntStream.intRange(0,l,7): " + ints.length,
                                          () -> IntStream.range(0, ints.length, 7)));
-
-                list.add(streamDataDescr("IntStream.intRange(l): " + ints.length,
-                                         () -> IntStream.range(ints.length, 0)));
-                list.add(streamDataDescr("IntStream.intRange(l,0,-2): " + ints.length,
-                                         () -> IntStream.range(ints.length, 0, -2)));
-                list.add(streamDataDescr("IntStream.intRange(l,0,-3): " + ints.length,
-                                         () -> IntStream.range(ints.length, 0, -3)));
-                list.add(streamDataDescr("IntStream.intRange(l,0,-7): " + ints.length,
-                                         () -> IntStream.range(ints.length, 0, -7)));
             }
             testData = list.toArray(new Object[0][]);
         }
@@ -149,14 +140,6 @@
                 spliterators.add(splitDescr("IntStream.intRange(0,l,7):" + name,
                                             () -> IntStream.range(0, ints.length, 7).spliterator()));
 
-                spliterators.add(splitDescr("IntStream.intRange(l,0):" + name,
-                                            () -> IntStream.range(ints.length, 0).spliterator()));
-                spliterators.add(splitDescr("IntStream.intRange(l,0,-2):" + name,
-                                            () -> IntStream.range(ints.length, 0, -2).spliterator()));
-                spliterators.add(splitDescr("IntStream.intRange(l,0,-3):" + name,
-                                            () -> IntStream.range(ints.length, 0, -3).spliterator()));
-                spliterators.add(splitDescr("IntStream.intRange(l,0,-7):" + name,
-                                            () -> IntStream.range(ints.length, 0, -7).spliterator()));
                 // Need more!
             }
             spliteratorTestData = spliterators.toArray(new Object[0][]);
--- a/test-ng/bootlib/java/util/stream/LongStreamTestDataProvider.java	Mon Apr 22 21:13:06 2013 -0400
+++ b/test-ng/bootlib/java/util/stream/LongStreamTestDataProvider.java	Mon Apr 22 21:13:22 2013 -0400
@@ -103,15 +103,6 @@
                                          () -> LongStream.range(0, longs.length, 3)));
                 list.add(streamDataDescr("LongStream.longRange(0,l,7): " + longs.length,
                                          () -> LongStream.range(0, longs.length, 7)));
-
-                list.add(streamDataDescr("LongStream.longRange(l): " + longs.length,
-                                         () -> LongStream.range(longs.length, 0)));
-                list.add(streamDataDescr("LongStream.longRange(l,0,-2): " + longs.length,
-                                         () -> LongStream.range(longs.length, 0, -2)));
-                list.add(streamDataDescr("LongStream.longRange(l,0,-3): " + longs.length,
-                                         () -> LongStream.range(longs.length, 0, -3)));
-                list.add(streamDataDescr("LongStream.longRange(l,0,-7): " + longs.length,
-                                         () -> LongStream.range(longs.length, 0, -7)));
             }
             testData = list.toArray(new Object[0][]);
         }
@@ -148,15 +139,6 @@
                                             () -> LongStream.range(0, longs.length, 3).spliterator()));
                 spliterators.add(splitDescr("LongStream.longRange(0,l,7):" + name,
                                             () -> LongStream.range(0, longs.length, 7).spliterator()));
-
-                spliterators.add(splitDescr("LongStream.longRange(l,0):" + name,
-                                            () -> LongStream.range(longs.length, 0).spliterator()));
-                spliterators.add(splitDescr("LongStream.longRange(l,0,-2):" + name,
-                                            () -> LongStream.range(longs.length, 0, -2).spliterator()));
-                spliterators.add(splitDescr("LongStream.longRange(l,0,-3):" + name,
-                                            () -> LongStream.range(longs.length, 0, -3).spliterator()));
-                spliterators.add(splitDescr("LongStream.longRange(l,0,-7):" + name,
-                                            () -> LongStream.range(longs.length, 0, -7).spliterator()));
                 // Need more!
             }
             spliteratorTestData = spliterators.toArray(new Object[0][]);
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/RangeTest.java	Mon Apr 22 21:13:06 2013 -0400
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/RangeTest.java	Mon Apr 22 21:13:22 2013 -0400
@@ -60,14 +60,10 @@
         for (int start : Arrays.asList(1, 10, -1, -10)) {
             for (int end : Arrays.asList(1, 10, -1, -10)) {
                 for (int step : Arrays.asList(0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE)) {
-                    if ((start < end && step > 0) ||
-                        (start > end && step < 0) ||
-                        (start == end && step != 0)) {
+                    if (step > 0)
                         executeAndNoCatch(() -> IntStream.range(start, end, step));
-                    }
-                    else {
+                    else
                         executeAndCatch(() -> IntStream.range(start, end, step));
-                    }
                 }
             }
         }
@@ -77,28 +73,19 @@
         // Without step
         for (int start : Arrays.asList(1, 10, -1, -10)) {
             for (int end : Arrays.asList(1, 10, -1, -10)) {
-                int step = (start < end) ? 1 : -1;
-                int size = Math.abs(start - end);
+                int step = 1;
+                int size = (start < end) ? end - start : 0;
                 int[] exp = new int[size];
                 if (start < end) {
                     for (int i = start, p = 0; i < end; i++, p++) {
                         exp[p] = i;
                     }
-                } else {
-                    for (int i = start, p = 0; i > end; i--, p++) {
-                        exp[p] = i;
-                    }
                 }
 
                 int[] inc = IntStream.range(start, end).toArray();
                 assertEquals(inc.length, size);
                 assertTrue(Arrays.equals(exp, inc));
 
-                if (start != end) {
-                    int[] dec = IntStream.range(end - step, start - step).toArray();
-                    assertTrue(Arrays.equals(reverse(dec), inc));
-                }
-
                 withData(intRangeData(start, end, step)).stream(s -> s).
                         expectedResult(exp).exercise();
             }
@@ -108,33 +95,20 @@
         for (int start : Arrays.asList(1, 10, -1, -10)) {
             for (int end : Arrays.asList(1, 10, -1, -10)) {
                 for (int step : Arrays.asList(1, -1, -2, 2)) {
-                    if ((start < end && step > 0) ||
-                        (start > end && step < 0) ||
-                        (start == end && step != 0)) {
-
+                    if (step > 0) {
                         int d = end - start;
-                        int size = (d / step) + ((d % step == 0) ? 0 : 1);
+                        int size = (start < end) ? (d / step) + ((d % step == 0) ? 0 : 1) : 0;
                         int[] exp = new int[size];
                         if (start < end) {
                             for (int i = start, p = 0; i < end; i += step, p++) {
                                 exp[p] = i;
                             }
-                        } else {
-                            for (int i = start, p = 0; i > end; i += step, p++) {
-                                exp[p] = i;
-                            }
                         }
 
                         int[] inc = IntStream.range(start, end, step).toArray();
                         assertEquals(inc.length, size);
                         assertTrue(Arrays.equals(exp, inc));
 
-                        if (start != end) {
-                            int s = (start < end) ? 1 : -1;
-                            int[] dec = IntStream.range(inc[inc.length - 1], inc[0] - s, -step).toArray();
-                            assertTrue(Arrays.equals(reverse(dec), inc));
-                        }
-
                         withData(intRangeData(start, end, step)).stream(s -> s).
                                 expectedResult(exp).exercise();
                     }
@@ -169,14 +143,10 @@
         for (long start : Arrays.asList(1, 10, -1, -10)) {
             for (long end : Arrays.asList(1, 10, -1, -10)) {
                 for (long step : Arrays.asList(0L, 1L, -1L, Long.MAX_VALUE, Long.MIN_VALUE)) {
-                    if ((start < end && step > 0) ||
-                        (start > end && step < 0) ||
-                        (start == end && step != 0)) {
+                    if (step > 0)
                         executeAndNoCatch(() -> LongStream.range(start, end, step));
-                    }
-                    else {
+                    else
                         executeAndCatch(() -> LongStream.range(start, end, step));
-                    }
                 }
             }
         }
@@ -186,28 +156,19 @@
         // Without step
         for (long start : Arrays.asList(1, 1000, -1, -1000)) {
             for (long end : Arrays.asList(1, 1000, -1, -1000)) {
-                long step = (start < end) ? 1 : -1;
-                long size = Math.abs(start - end);
+                long step = 1;
+                long size = start < end ? end - start : 0;
                 long[] exp = new long[(int) size];
                 if (start < end) {
                     for (long i = start, p = 0; i < end; i++, p++) {
                         exp[(int) p] = i;
                     }
-                } else {
-                    for (long i = start, p = 0; i > end; i--, p++) {
-                        exp[(int) p] = i;
-                    }
                 }
 
                 long[] inc = LongStream.range(start, end).toArray();
                 assertEquals(inc.length, size);
                 assertTrue(Arrays.equals(exp, inc));
 
-                if (start != end) {
-                    long[] dec = LongStream.range(end - step, start - step).toArray();
-                    assertTrue(Arrays.equals(reverse(dec), inc));
-                }
-
                 withData(longRangeData(start, end, step)).stream(s -> s).
                         expectedResult(exp).exercise();
             }
@@ -217,33 +178,21 @@
         for (long start : Arrays.asList(1, 1000, -1, -1000)) {
             for (long end : Arrays.asList(1, 1000, -1, -1000)) {
                 for (long step : Arrays.asList(1, -1, -2, 2)) {
-                    if ((start < end && step > 0) ||
-                        (start > end && step < 0) ||
-                        (start == end && step != 0)) {
+                    if (step > 0) {
 
                         long d = end - start;
-                        long size = (d / step) + ((d % step == 0) ? 0 : 1);
+                        long size = start < end ? (d / step) + ((d % step == 0) ? 0 : 1) : 0;
                         long[] exp = new long[(int) size];
                         if (start < end) {
                             for (long i = start, p = 0; i < end; i += step, p++) {
                                 exp[(int) p] = i;
                             }
-                        } else {
-                            for (long i = start, p = 0; i > end; i += step, p++) {
-                                exp[(int) p] = i;
-                            }
                         }
 
                         long[] inc = LongStream.range(start, end, step).toArray();
                         assertEquals(inc.length, size);
                         assertTrue(Arrays.equals(exp, inc));
 
-                        if (start != end) {
-                            long s = (start < end) ? 1 : -1;
-                            long[] dec = LongStream.range(inc[inc.length - 1], inc[0] - s, -step).toArray();
-                            assertTrue(Arrays.equals(reverse(dec), inc));
-                        }
-
                         withData(longRangeData(start, end, step)).stream(s -> s).
                                 expectedResult(exp).exercise();
                     }
@@ -278,13 +227,15 @@
         for (double start : Arrays.asList(1, 10, -1, -10)) {
             for (double end : Arrays.asList(1, 10, -1, -10)) {
                 for (double step : Arrays.asList(0.0, +0.0, -0.0, 1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)) {
-                    if ((start < end && step > 0) ||
-                        (start > end && step < 0) ||
-                        (start == end && step != 0)) {
-                        executeAndNoCatch(() -> DoubleStream.range(start, end, step));
+                    try {
+                        if (step > 0)
+                            executeAndNoCatch(() -> DoubleStream.range(start, end, step));
+                        else
+                            executeAndCatch(() -> DoubleStream.range(start, end, step));
                     }
-                    else {
-                        executeAndCatch(() -> DoubleStream.range(start, end, step));
+                    catch (AssertionError e) {
+                        System.out.printf("start=%f, end=%f, step=%f%n", start, end, step);
+                        throw e;
                     }
                 }
             }
@@ -293,11 +244,18 @@
         for (double start : Arrays.asList(0.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
             for (double end : Arrays.asList(0.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
                 for (double step : Arrays.asList(1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN)) {
-                    if (start == 0.0 && end == 0.0 && !Double.isNaN(step)) {
-                        executeAndNoCatch(() -> DoubleStream.range(start, end, step));
+                    try {
+                        if ((start == 0.0 && end == 0.0 && step > 0)
+                            || (start > end && step > 0)) {
+                            executeAndNoCatch(() -> DoubleStream.range(start, end, step));
+                        }
+                        else {
+                            executeAndCatch(() -> DoubleStream.range(start, end, step));
+                        }
                     }
-                    else {
-                        executeAndCatch(() -> DoubleStream.range(start, end, step));
+                    catch (AssertionError e) {
+                        System.out.printf("start=%f, end=%f, step=%f%n", start, end, step);
+                        throw e;
                     }
                 }
             }
@@ -308,8 +266,8 @@
         // Without step
         for (double start : Arrays.asList(1, 1000, -1, -1000)) {
             for (double end : Arrays.asList(1, 1000, -1, -1000)) {
-                double step = (start < end) ? 1 : -1;
-                double size = Math.ceil((end - start) / step);
+                double step = 1;
+                double size = start < end ? Math.ceil((end - start) / step) : 0;
                 double[] exp = new double[(int) size];
                 for (long i = 0; i < size; i++) {
                     exp[(int) i] = start + i * step;
@@ -319,11 +277,6 @@
                 assertEquals(inc.length, (int) size);
                 assertTrue(Arrays.equals(exp, inc));
 
-                if (start != end) {
-                    double[] dec = DoubleStream.range(end - step, start - step).toArray();
-                    assertTrue(Arrays.equals(reverse(dec), inc));
-                }
-
                 withData(doubleRangeData(start, end, step)).stream(s -> s).
                         expectedResult(exp).exercise();
             }
@@ -333,29 +286,20 @@
         for (double start : Arrays.asList(1, 1000, -1, -1000)) {
             for (double end : Arrays.asList(1, 1000, -1, -1000)) {
                 for (double step : Arrays.asList(1, -1, -2, 2)) {
-                    if ((start < end && step > 0) ||
-                        (start > end && step < 0) ||
-                        (start == end && step != 0)) {
+                    if (step <= 0)
+                        continue;
+                    double size = start < end ? Math.ceil((end - start) / step) : 0;
+                    double[] exp = new double[(int) size];
+                    for (long i = 0; i < size; i++) {
+                        exp[(int) i] = start + i * step;
+                    }
 
-                        double size = Math.ceil((end - start) / step);
-                        double[] exp = new double[(int) size];
-                        for (long i = 0; i < size; i++) {
-                            exp[(int) i] = start + i * step;
-                        }
+                    double[] inc = DoubleStream.range(start, end, step).toArray();
+                    assertEquals(inc.length, (int) size);
+                    assertTrue(Arrays.equals(exp, inc));
 
-                        double[] inc = DoubleStream.range(start, end, step).toArray();
-                        assertEquals(inc.length, (int) size);
-                        assertTrue(Arrays.equals(exp, inc));
-
-                        if (start != end) {
-                            double s = (start < end) ? 1 : -1;
-                            double[] dec = DoubleStream.range(inc[inc.length - 1], inc[0] - s, -step).toArray();
-                            assertTrue(Arrays.equals(reverse(dec), inc));
-                        }
-
-                        withData(doubleRangeData(start, end, step)).stream(s -> s).
-                                expectedResult(exp).exercise();
-                    }
+                    withData(doubleRangeData(start, end, step)).stream(s -> s).
+                            expectedResult(exp).exercise();
                 }
             }
         }
@@ -364,7 +308,7 @@
         for (double step : Arrays.asList(Math.PI / 1000.0, Math.PI / 1000.0, Math.PI / 10000.0)) {
             double start = -Math.PI;
             double end = Math.PI;
-            double size = Math.ceil((end - start) / step);
+            double size = start < end ? Math.ceil((end - start) / step) : 0;
             double[] exp = new double[(int) size];
             for (long i = 0; i < size; i++) {
                 exp[(int) i] = start + i * step;