blob: a4d4f22c1e81de32a8d34b2d705841f9a241ab6e [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21
22
23package org.onap.osam.testUtils;
24
25import org.junit.Assert;
26import org.junit.Test;
27import org.onap.osam.utils.Intersection;
28
29import java.util.ArrayList;
30import java.util.List;
31
32public class IntersectionTest {
33
34 @Test
35 public void testFourArrays(){
36 List<String> l1 = new ArrayList<String>();
37 l1.add("1");
38 l1.add("2");
39
40 List<String> l2 = new ArrayList<String>();
41 l2.add("2");
42 l2.add("3");
43
44 List<String> l3 = new ArrayList<String>();
45 l3.add("2");
46 l3.add("4");
47
48 List<String> l4 = new ArrayList<String>();
49 l4.add("2");
50 l4.add("5");
51
52 List<List<String>> all = new ArrayList<>();
53 all.add(l1);
54 all.add(l2);
55 all.add(l3);
56 all.add(l4);
57 Intersection<String> m = new Intersection<>();
58 List<String> ans = m.intersectMultipileArray(all);
59 Assert.assertEquals(1,ans.size());
60 Assert.assertEquals(ans.get(0),"2");
61
62 }
63
64
65
66 @Test
67 public void testTwoArrays(){
68 List<String> l1 = new ArrayList<String>();
69 l1.add("1");
70 l1.add("2");
71
72 List<String> l2 = new ArrayList<String>();
73 l2.add("2");
74 l2.add("3");
75
76 List<List<String>> all = new ArrayList<>();
77 all.add(l1);
78 all.add(l2);
79 Intersection<String> m = new Intersection<>();
80 List<String> l3 = m.intersectMultipileArray(all);
81 Assert.assertEquals(l3.size(),1);
82 Assert.assertEquals(l3.get(0),"2");
83
84 }
85
86
87 @Test
88 public void testNoIntersection(){
89 List<String> l1 = new ArrayList<String>();
90 l1.add("1");
91 l1.add("2");
92
93 List<String> l2 = new ArrayList<String>();
94 l2.add("3");
95 l2.add("4");
96
97 List<List<String>> all = new ArrayList<>();
98 all.add(l1);
99 all.add(l2);
100 Intersection<String> m = new Intersection<>();
101 List<String> l3 = m.intersectMultipileArray(all);
102 Assert.assertEquals(l3.size(),0);
103
104 }
105
106 @Test
107 public void testOneArrays(){
108 List<String> l1 = new ArrayList<String>();
109 l1.add("1");
110 l1.add("2");
111 List<List<String>> all = new ArrayList<>();
112 all.add(l1);
113 Intersection<String> m = new Intersection<>();
114 List<String> l3 = m.intersectMultipileArray(all);
115 Assert.assertEquals(l3.size(),2);
116 Assert.assertEquals(l3.get(0),"1");
117 Assert.assertEquals(l3.get(1),"2");
118
119 }
120}