1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.r2.common.permutation;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.BlockJUnit4ClassRunner;
30 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
31 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
32 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
33 import org.kuali.student.r2.common.exceptions.MissingParameterException;
34 import org.kuali.student.r2.common.exceptions.OperationFailedException;
35 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
36
37
38
39
40
41
42
43
44 @RunWith(BlockJUnit4ClassRunner.class)
45 public class TestPermutationUtils {
46
47
48 public TestPermutationUtils() {
49 }
50
51 @Test
52 public void testGeneratePermutations() throws DoesNotExistException,
53 InvalidParameterException, MissingParameterException,
54 OperationFailedException, PermissionDeniedException {
55
56
57
58
59
60
61
62
63
64
65
66
67
68 Map<String, List<String>> typeToListMap = new HashMap<String, List<String>>();
69
70 List<String> lecList = new ArrayList<String>(2);
71
72 lecList.add("A");
73 lecList.add("B");
74
75
76 typeToListMap.put("LEC", lecList);
77
78 List<String> labList = new ArrayList<String>(3);
79
80 labList.add("X");
81 labList.add("Y");
82 labList.add("Z");
83
84
85 typeToListMap.put("LAB", labList);
86
87 Set<String> nextStateSet = new HashSet<String>();
88
89 nextStateSet.addAll(typeToListMap.keySet());
90
91 int expectedPermutations = 0;
92
93 for (String key : typeToListMap.keySet()) {
94
95 int length = typeToListMap.get(key).size();
96
97 if (expectedPermutations == 0)
98 expectedPermutations = length;
99 else
100 expectedPermutations *= length;
101 }
102
103 assertEquals(6, expectedPermutations);
104
105 List<List<String>> permutations = new ArrayList<List<String>>();
106
107 ArrayList<String> keyList = new ArrayList<String>(
108 typeToListMap.keySet());
109
110 PermutationUtils.generatePermutations(keyList, new ArrayList<String>(), typeToListMap,
111 permutations);
112
113 assertEquals(6, permutations.size());
114
115 List<String> discussionList = new ArrayList<String>();
116
117 discussionList.add("Q");
118 discussionList.add("R");
119 discussionList.add("S");
120 discussionList.add("T");
121
122
123 typeToListMap.put("DIS", discussionList);
124
125 permutations.clear();
126
127 keyList = new ArrayList<String>(typeToListMap.keySet());
128
129 PermutationUtils.generatePermutations(keyList, new ArrayList<String>(), typeToListMap,
130 permutations);
131
132 assertEquals(24, permutations.size());
133
134 }
135 }