2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.sparky.util;
27 import static org.junit.Assert.assertTrue;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.HashSet;
32 import java.util.List;
34 import org.junit.Test;
35 import org.onap.aai.sparky.util.SuggestionsPermutation;
37 public class SuggestionsPermutationTest {
40 public void testGetUniqueListForSuggestions() {
41 List<String> inputList = new ArrayList<String>();
42 inputList.add("str1");
43 inputList.add("str2");
44 inputList.add("str3");
46 List<List<String>> expectedListOfLists = new ArrayList<List<String>>();
47 expectedListOfLists.add((new ArrayList<String>() {
52 expectedListOfLists.add((new ArrayList<String>() {
57 expectedListOfLists.add((new ArrayList<String>() {
62 expectedListOfLists.add((new ArrayList<String>() {
68 expectedListOfLists.add((new ArrayList<String>() {
74 expectedListOfLists.add((new ArrayList<String>() {
80 expectedListOfLists.add((new ArrayList<String>() {
88 int expectedCount = expectedListOfLists.size();
90 ArrayList<ArrayList<String>> actualListOfLists =
91 SuggestionsPermutation.getNonEmptyUniqueLists(inputList);
93 for (List<String> list : expectedListOfLists) {
94 for (ArrayList<String> actualList : actualListOfLists) {
95 if (new HashSet(list).equals(new HashSet(actualList))) {
101 assertTrue("Missing entries in the unique list of lists for input: " + inputList.toString()
102 + ". Found: " + actualListOfLists.toString() + " expected: "
103 + expectedListOfLists.toString(), actualCount == expectedCount);
107 public void testGetListPermutations() {
108 List<String> inputList = new ArrayList<String>();
109 inputList.add("str1");
110 inputList.add("str2");
111 inputList.add("str3");
113 List<List<String>> expectedPermutations = new ArrayList<List<String>>();
114 expectedPermutations.add((new ArrayList<String>() {
121 expectedPermutations.add((new ArrayList<String>() {
128 expectedPermutations.add((new ArrayList<String>() {
135 expectedPermutations.add((new ArrayList<String>() {
142 expectedPermutations.add((new ArrayList<String>() {
149 expectedPermutations.add((new ArrayList<String>() {
157 int expectedCount = expectedPermutations.size();
159 List<List<String>> actualPermutations = SuggestionsPermutation.getListPermutations(inputList);
161 for (List<String> list : expectedPermutations) {
162 for (List<String> actualList : actualPermutations) {
163 if (list.toString().equals(actualList.toString())) {
170 "Missing entries in the permutation of list: " + inputList.toString() + ". Found: "
171 + actualPermutations.toString() + " expected: " + expectedPermutations.toString(),
172 actualCount == expectedCount);
176 public void isValidSuggestionInputPermutation_verbose_successPath() {
178 List<String> x = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
180 ArrayList<ArrayList<String>> uniqueLists = SuggestionsPermutation.getNonEmptyUniqueLists(x);
182 assertTrue(uniqueLists.get(0).toString().equals("[A, B, C, D]"));
183 assertTrue(uniqueLists.get(1).toString().equals("[B, C, D]"));
184 assertTrue(uniqueLists.get(2).toString().equals("[A, C, D]"));
185 assertTrue(uniqueLists.get(3).toString().equals("[C, D]"));
186 assertTrue(uniqueLists.get(4).toString().equals("[A, B, D]"));
187 assertTrue(uniqueLists.get(5).toString().equals("[B, D]"));
188 assertTrue(uniqueLists.get(6).toString().equals("[A, D]"));
189 assertTrue(uniqueLists.get(7).toString().equals("[D]"));
190 assertTrue(uniqueLists.get(8).toString().equals("[A, B, C]"));
191 assertTrue(uniqueLists.get(9).toString().equals("[B, C]"));
192 assertTrue(uniqueLists.get(10).toString().equals("[A, C]"));
193 assertTrue(uniqueLists.get(11).toString().equals("[C]"));
194 assertTrue(uniqueLists.get(12).toString().equals("[A, B]"));
195 assertTrue(uniqueLists.get(13).toString().equals("[B]"));
196 assertTrue(uniqueLists.get(14).toString().equals("[A]"));
197 assertTrue(uniqueLists.size() == 15);