1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.openjdk.tests.java.util.stream; 24 25 import org.openjdk.testlib.java.util.stream.IntStreamTestDataProvider; 26 import org.openjdk.testlib.java.util.stream.LambdaTestHelpers; 27 import org.openjdk.testlib.java.util.stream.OpTestCase; 28 import org.openjdk.testlib.java.util.stream.StreamTestDataProvider; 29 import org.openjdk.testlib.java.util.stream.TestData; 30 31 import java.util.Collection; 32 import java.util.stream.Stream; 33 import java.util.stream.IntStream; 34 35 import org.testng.annotations.Test; 36 37 import static org.openjdk.testlib.java.util.stream.LambdaTestHelpers.assertCountSum; 38 import static org.openjdk.testlib.java.util.stream.LambdaTestHelpers.assertUnique; 39 40 /** 41 * UniqOpTest 42 */ 43 @Test 44 public class IntUniqOpTest extends OpTestCase { 45 testUniqOp()46 public void testUniqOp() { 47 assertCountSum(IntStream.generate(() -> 0).limit(10).distinct().boxed(), 1, 0); 48 assertCountSum(IntStream.generate(() -> 1).limit(10).distinct().boxed(), 1, 1); 49 assertCountSum(IntStream.range(0, 0).distinct().boxed(), 0, 0); 50 assertCountSum(IntStream.range(1, 11).distinct().boxed(), 10, 55); 51 assertCountSum(IntStream.range(1, 11).distinct().boxed(), 10, 55); 52 } 53 54 @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) testOp(String name, TestData.OfInt data)55 public void testOp(String name, TestData.OfInt data) { 56 Collection<Integer> result = exerciseOps(data, s -> s.distinct().boxed()); 57 58 assertUnique(result); 59 if (data.size() > 0) 60 assertTrue(result.size() > 0); 61 else 62 assertTrue(result.size() == 0); 63 assertTrue(result.size() <= data.size()); 64 } 65 66 @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) testOpSorted(String name, TestData.OfInt data)67 public void testOpSorted(String name, TestData.OfInt data) { 68 Collection<Integer> result = withData(data). 69 stream(s -> s.sorted().distinct().boxed()). 70 exercise(); 71 72 assertUnique(result); 73 if (data.size() > 0) 74 assertTrue(result.size() > 0); 75 else 76 assertTrue(result.size() == 0); 77 assertTrue(result.size() <= data.size()); 78 } 79 } 80