test/jdk/java/util/Arrays/SetAllTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 32427 jdk/test/java/util/Arrays/SetAllTest.java@c22b7e41adf3
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     1
/*
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     4
 *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     8
 *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    13
 * accompanied this code).
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    14
 *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    18
 *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    21
 * questions.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    22
 */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    23
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    24
/*
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    25
 * @test
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    26
 * @bug 8012650
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    27
 * @summary Unit test for setAll, parallelSetAll variants
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    28
 * @run testng SetAllTest
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    29
 */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    30
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    31
import org.testng.annotations.DataProvider;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    32
import org.testng.annotations.Test;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    33
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    34
import java.util.Arrays;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    35
import java.util.function.IntFunction;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    36
import java.util.function.IntToDoubleFunction;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    37
import java.util.function.IntToLongFunction;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    38
import java.util.function.IntUnaryOperator;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    39
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    40
import static org.testng.Assert.assertEquals;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    41
import static org.testng.Assert.assertTrue;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    42
import static org.testng.Assert.assertSame;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    43
import static org.testng.Assert.fail;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    44
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    45
@Test
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    46
public class SetAllTest {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    47
    private static final IntFunction<String> toString = i -> "N" + Integer.valueOf(i);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    48
    private static final IntFunction<String> fillString = i -> "X";
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    49
    private static final String[] r0 = {};
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    50
    private static final String[] r1 = { "N0" };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    51
    private static final String[] r10 = { "N0", "N1", "N2", "N3", "N4", "N5", "N6", "N7", "N8", "N9" };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    52
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    53
    private Object[][] stringData = new Object[][] {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    54
        { "empty", 0, toString, r0 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    55
        { "one", 1, toString, r1 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    56
        { "ten", 10, toString, r10 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    57
        { "fill", 3, fillString, new String[] { "X", "X", "X" }}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    58
    };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    59
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    60
    private static final IntUnaryOperator toInt = i -> i << 1;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    61
    private static final IntUnaryOperator fillInt = i -> 99;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    62
    private static final int[] ir0 = {};
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    63
    private static final int[] ir1 = { 0 };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    64
    private static final int[] ir10 = { 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    65
    private Object[][] intData = new Object[][] {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    66
        { "empty", 0, toInt, ir0 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    67
        { "one", 1, toInt, ir1 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    68
        { "ten", 10, toInt, ir10 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    69
        { "fill", 3, fillInt, new int[] { 99, 99, 99 }}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    70
    };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    71
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    72
    private static final IntToLongFunction toLong = i -> i << 1;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    73
    private static final IntToLongFunction fillLong = i -> 9999L;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    74
    private static final long[] lr0 = {};
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    75
    private static final long[] lr1 = { 0L };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    76
    private static final long[] lr10 = { 0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    77
    private Object[][] longData = new Object[][] {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    78
        { "empty", 0, toLong, lr0 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    79
        { "one", 1, toLong, lr1 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    80
        { "ten", 10, toLong, lr10 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    81
        { "fill", 3, fillLong, new long[] { 9999L, 9999L, 9999L }}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    82
    };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    83
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    84
    private static final IntToDoubleFunction toDouble = i -> i * 1.1;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    85
    private static final IntToDoubleFunction fillDouble = i -> 3.14;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    86
    private static final double[] dr0 = {};
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    87
    private static final double[] dr1 = { 0.0 };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    88
    private static final double[] dr10 = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    89
    private Object[][] doubleData = new Object[][] {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    90
        { "empty", 0, toDouble, dr0 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    91
        { "one", 1, toDouble, dr1 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    92
        { "ten", 10, toDouble, dr10 },
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    93
        { "fill", 3, fillDouble, new double[] { 3.14, 3.14, 3.14 }}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    94
    };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    95
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    96
    @DataProvider(name="string")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    97
    public Object[][] stringTests() { return stringData; }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    98
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
    99
    @DataProvider(name="int")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   100
    public Object[][] intTests() { return intData; }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   101
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   102
    @DataProvider(name="long")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   103
    public Object[][] longTests() { return longData; }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   104
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   105
    @DataProvider(name="double")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   106
    public Object[][] doubleTests() { return doubleData; }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   107
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   108
    @Test(dataProvider = "string")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   109
    public void testSetAllString(String name, int size, IntFunction<String> generator, String[] expected) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   110
        String[] result = new String[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   111
        Arrays.setAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   112
        assertEquals(result, expected, "setAll(String[], IntFunction<String>) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   113
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   114
        // ensure fresh array
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   115
        result = new String[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   116
        Arrays.parallelSetAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   117
        assertEquals(result, expected, "parallelSetAll(String[], IntFunction<String>) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   118
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   119
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   120
    @Test(dataProvider = "int")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   121
    public void testSetAllInt(String name, int size, IntUnaryOperator generator, int[] expected) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   122
        int[] result = new int[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   123
        Arrays.setAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   124
        assertEquals(result, expected, "setAll(int[], IntUnaryOperator) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   125
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   126
        // ensure fresh array
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   127
        result = new int[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   128
        Arrays.parallelSetAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   129
        assertEquals(result, expected, "parallelSetAll(int[], IntUnaryOperator) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   130
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   131
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   132
    @Test(dataProvider = "long")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   133
    public void testSetAllLong(String name, int size, IntToLongFunction generator, long[] expected) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   134
        long[] result = new long[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   135
        Arrays.setAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   136
        assertEquals(result, expected, "setAll(long[], IntToLongFunction) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   137
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   138
        // ensure fresh array
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   139
        result = new long[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   140
        Arrays.parallelSetAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   141
        assertEquals(result, expected, "parallelSetAll(long[], IntToLongFunction) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   142
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   143
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   144
    private void assertDoubleArrayEquals(double[] actual, double[] expected, double delta, String msg) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   145
        if (actual.length != expected.length) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   146
            fail(msg + ": length mismatch, expected " + expected.length + ", got " + actual.length);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   147
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   148
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   149
        for (int i = 0; i < actual.length; i++) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   150
            assertEquals(actual[i], expected[i], delta, msg + "(mismatch at index " + i + ")");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   151
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   152
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   153
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   154
    @Test(dataProvider = "double")
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   155
    public void testSetAllDouble(String name, int size, IntToDoubleFunction generator, double[] expected) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   156
        double[] result = new double[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   157
        Arrays.setAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   158
        assertDoubleArrayEquals(result, expected, 0.05, "setAll(double[], IntToDoubleFunction) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   159
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   160
        // ensure fresh array
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   161
        result = new double[size];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   162
        Arrays.parallelSetAll(result, generator);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   163
        assertDoubleArrayEquals(result, expected, 0.05, "setAll(double[], IntToDoubleFunction) case " + name + " failed.");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   164
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   165
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   166
    @Test
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   167
    public void testStringSetNulls() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   168
        String[] ar = new String[2];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   169
        try {
19805
39ccb0972a2f 8024182: test/java/util/Arrays/SetAllTest.java fails to compile due to recent compiler changes
psandoz
parents: 17195
diff changeset
   170
            Arrays.setAll(null, (IntFunction<String>) i -> "X");
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   171
            fail("Arrays.setAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   172
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   173
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   174
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   175
        try {
19805
39ccb0972a2f 8024182: test/java/util/Arrays/SetAllTest.java fails to compile due to recent compiler changes
psandoz
parents: 17195
diff changeset
   176
            Arrays.parallelSetAll(null, (IntFunction<String>) i -> "X");
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   177
            fail("Arrays.parallelSetAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   178
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   179
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   180
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   181
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   182
            Arrays.setAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   183
            fail("Arrays.setAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   184
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   185
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   186
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   187
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   188
            Arrays.parallelSetAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   189
            fail("Arrays.parallelSetAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   190
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   191
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   192
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   193
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   194
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   195
    @Test
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   196
    public void testIntSetNulls() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   197
        int[] ar = new int[2];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   198
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   199
            Arrays.setAll(null, (IntUnaryOperator) i -> i);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   200
            fail("Arrays.setAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   201
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   202
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   203
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   204
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   205
            Arrays.parallelSetAll(null, (IntUnaryOperator) i -> i);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   206
            fail("Arrays.parallelSetAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   207
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   208
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   209
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   210
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   211
            Arrays.setAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   212
            fail("Arrays.setAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   213
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   214
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   215
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   216
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   217
            Arrays.parallelSetAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   218
            fail("Arrays.parallelSetAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   219
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   220
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   221
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   222
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   223
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   224
    @Test
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   225
    public void testLongSetNulls() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   226
        long[] ar = new long[2];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   227
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   228
            Arrays.setAll(null, (IntToLongFunction) i -> Long.MAX_VALUE);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   229
            fail("Arrays.setAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   230
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   231
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   232
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   233
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   234
            Arrays.parallelSetAll(null, (IntToLongFunction) i -> Long.MAX_VALUE);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   235
            fail("Arrays.parallelSetAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   236
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   237
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   238
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   239
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   240
            Arrays.setAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   241
            fail("Arrays.setAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   242
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   243
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   244
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   245
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   246
            Arrays.parallelSetAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   247
            fail("Arrays.parallelSetAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   248
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   249
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   250
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   251
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   252
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   253
    @Test
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   254
    public void testDoubleSetNulls() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   255
        double[] ar = new double[2];
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   256
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   257
            Arrays.setAll(null, (IntToDoubleFunction) i -> Math.E);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   258
            fail("Arrays.setAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   259
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   260
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   261
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   262
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   263
            Arrays.parallelSetAll(null, (IntToDoubleFunction) i -> Math.E);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   264
            fail("Arrays.parallelSetAll(null, foo) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   265
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   266
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   267
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   268
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   269
            Arrays.setAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   270
            fail("Arrays.setAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   271
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   272
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   273
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   274
        try {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   275
            Arrays.parallelSetAll(ar, null);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   276
            fail("Arrays.parallelSetAll(array, null) should throw NPE");
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   277
        } catch (NullPointerException npe) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   278
            // expected
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   279
        }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents:
diff changeset
   280
    }
32427
c22b7e41adf3 8134984: Text files should end in exactly one newline
martin
parents: 19805
diff changeset
   281
}