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>(){{add("str1");}}));
48 expectedListOfLists.add((new ArrayList<String>(){{add("str2");}}));
49 expectedListOfLists.add((new ArrayList<String>(){{add("str3");}}));
50 expectedListOfLists.add((new ArrayList<String>(){{add("str1");add("str2");}}));
51 expectedListOfLists.add((new ArrayList<String>(){{add("str1");add("str3");}}));
52 expectedListOfLists.add((new ArrayList<String>(){{add("str2");add("str3");}}));
53 expectedListOfLists.add((new ArrayList<String>(){{add("str1");add("str2");add("str3");}}));
55 int expectedCount = expectedListOfLists.size();
57 ArrayList<ArrayList<String>> actualListOfLists = SuggestionsPermutation.getNonEmptyUniqueLists(inputList);
59 for (List<String> list: expectedListOfLists){
60 for (ArrayList<String> actualList: actualListOfLists) {
61 if (new HashSet(list).equals (new HashSet(actualList)) ){
67 assertTrue("Missing entries in the unique list of lists for input: " + inputList.toString()
68 + ". Found: "+ actualListOfLists.toString()
69 + " expected: " + expectedListOfLists.toString(), actualCount == expectedCount);
73 public void testGetListPermutations() {
74 List<String> inputList = new ArrayList<String>();
75 inputList.add("str1");
76 inputList.add("str2");
77 inputList.add("str3");
79 List<List<String>> expectedPermutations = new ArrayList<List<String>>();
80 expectedPermutations.add((new ArrayList<String>(){{add("str1");add("str2");add("str3");}}));
81 expectedPermutations.add((new ArrayList<String>(){{add("str2");add("str1");add("str3");}}));
82 expectedPermutations.add((new ArrayList<String>(){{add("str2");add("str3");add("str1");}}));
83 expectedPermutations.add((new ArrayList<String>(){{add("str1");add("str3");add("str2");}}));
84 expectedPermutations.add((new ArrayList<String>(){{add("str3");add("str1");add("str2");}}));
85 expectedPermutations.add((new ArrayList<String>(){{add("str3");add("str2");add("str1");}}));
87 int expectedCount = expectedPermutations.size();
89 List<List<String>> actualPermutations = SuggestionsPermutation.getListPermutations(inputList);
91 for (List<String> list: expectedPermutations){
92 for (List<String> actualList: actualPermutations) {
93 if (list.toString().equals(actualList.toString()) ){
99 assertTrue("Missing entries in the permutation of list: "
100 + inputList.toString() + ". Found: "+ actualPermutations.toString()
101 + " expected: " + expectedPermutations.toString(), actualCount == expectedCount);
105 public void isValidSuggestionInputPermutation_verbose_successPath() {
107 List<String> x = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
109 ArrayList<ArrayList<String>> uniqueLists = SuggestionsPermutation.getNonEmptyUniqueLists(x);
111 assertTrue(uniqueLists.get(0).toString().equals("[A, B, C, D]"));
112 assertTrue(uniqueLists.get(1).toString().equals("[B, C, D]"));
113 assertTrue(uniqueLists.get(2).toString().equals("[A, C, D]"));
114 assertTrue(uniqueLists.get(3).toString().equals("[C, D]"));
115 assertTrue(uniqueLists.get(4).toString().equals("[A, B, D]"));
116 assertTrue(uniqueLists.get(5).toString().equals("[B, D]"));
117 assertTrue(uniqueLists.get(6).toString().equals("[A, D]"));
118 assertTrue(uniqueLists.get(7).toString().equals("[D]"));
119 assertTrue(uniqueLists.get(8).toString().equals("[A, B, C]"));
120 assertTrue(uniqueLists.get(9).toString().equals("[B, C]"));
121 assertTrue(uniqueLists.get(10).toString().equals("[A, C]"));
122 assertTrue(uniqueLists.get(11).toString().equals("[C]"));
123 assertTrue(uniqueLists.get(12).toString().equals("[A, B]"));
124 assertTrue(uniqueLists.get(13).toString().equals("[B]"));
125 assertTrue(uniqueLists.get(14).toString().equals("[A]"));
126 assertTrue(uniqueLists.size() == 15);