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 java.util.Collection;
26 import java.util.stream.*;
27 
28 import org.testng.annotations.Test;
29 
30 import static java.util.stream.LambdaTestHelpers.assertCountSum;
31 import static java.util.stream.LambdaTestHelpers.assertUnique;
32 
33 /**
34  * UniqOpTest
35  */
36 @Test
37 public class IntUniqOpTest extends OpTestCase {
38 
testUniqOp()39     public void testUniqOp() {
40         assertCountSum(IntStream.generate(() -> 0).limit(10).distinct().boxed(), 1, 0);
41         assertCountSum(IntStream.generate(() -> 1).limit(10).distinct().boxed(), 1, 1);
42         assertCountSum(IntStream.range(0, 0).distinct().boxed(), 0, 0);
43         assertCountSum(IntStream.range(1, 11).distinct().boxed(), 10, 55);
44         assertCountSum(IntStream.range(1, 11).distinct().boxed(), 10, 55);
45     }
46 
47     @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
testOp(String name, TestData.OfInt data)48     public void testOp(String name, TestData.OfInt data) {
49         Collection<Integer> result = exerciseOps(data, s -> s.distinct().boxed());
50 
51         assertUnique(result);
52         if (data.size() > 0)
53             assertTrue(result.size() > 0);
54         else
55             assertTrue(result.size() == 0);
56         assertTrue(result.size() <= data.size());
57     }
58 
59     @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
testOpSorted(String name, TestData.OfInt data)60     public void testOpSorted(String name, TestData.OfInt data) {
61         Collection<Integer> result = withData(data).
62                 stream(s -> s.sorted().distinct().boxed()).
63                 exercise();
64 
65         assertUnique(result);
66         if (data.size() > 0)
67             assertTrue(result.size() > 0);
68         else
69             assertTrue(result.size() == 0);
70         assertTrue(result.size() <= data.size());
71     }
72 }
73