- Timestamp:
- 07/31/14 17:20:07 (10 years ago)
- Location:
- trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeChecker.java
r1294 r1638 27 27 28 28 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; 29 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 30 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; … … 161 162 * 162 163 */ 164 public void assertEventTaskInstancesEqual(ITaskInstanceList expected, 165 ITaskInstanceList checked) 166 { 167 final List<IEventTaskInstance> expectedEventTaskInstances = 168 new ArrayList<IEventTaskInstance>(); 169 170 final List<IEventTaskInstance> checkedEventTaskInstances = 171 new ArrayList<IEventTaskInstance>(); 172 173 for (ITaskInstance instance : expected) { 174 instance.accept(new DefaultTaskInstanceTraversingVisitor() { 175 @Override 176 public void visit(IEventTaskInstance eventTaskInstance) { 177 expectedEventTaskInstances.add(eventTaskInstance); 178 } 179 }); 180 } 181 182 for (ITaskInstance instance : checked) { 183 instance.accept(new DefaultTaskInstanceTraversingVisitor() { 184 @Override 185 public void visit(IEventTaskInstance eventTaskInstance) { 186 checkedEventTaskInstances.add(eventTaskInstance); 187 } 188 }); 189 } 190 191 assertEquals("task instance lists differ in the number of event task instances", 192 expectedEventTaskInstances.size(), checkedEventTaskInstances.size()); 193 194 for (int i = 0; i < expectedEventTaskInstances.size(); i++) { 195 assertTaskInstancesEqual 196 (expectedEventTaskInstances.get(i), checkedEventTaskInstances.get(i)); 197 } 198 } 199 200 /** 201 * 202 */ 163 203 private void assertTaskInstancesEqual(ITaskInstance expected, 164 204 ITaskInstance checked, -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeEncoder.java
r1412 r1638 189 189 } 190 190 else if (taskInstance instanceof IOptionalInstance) { 191 encode(((IOptionalInstance) taskInstance).getChild(), out, indent + " ", i++); 191 if (((IOptionalInstance) taskInstance).getChild() != null) { 192 encode(((IOptionalInstance) taskInstance).getChild(), out, indent + " ", i++); 193 } 192 194 } 193 195 -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeValidator.java
r1333 r1638 17 17 import static org.junit.Assert.*; 18 18 19 import java.util.HashMap; 20 import java.util.LinkedList; 19 21 import java.util.List; 20 22 import java.util.Map; 23 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; 21 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 22 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; … … 46 50 * 47 51 */ 52 public void validate(List<IUserSession> userSessions, boolean checkInstances) { 53 validate(userSessions); 54 55 if (!checkInstances) { 56 return; 57 } 58 59 Map<ITask, List<ITaskInstance>> allTasks = new HashMap<ITask, List<ITaskInstance>>(); 60 61 for (IUserSession userSession : userSessions) { 62 getAllTasksAndInstances(userSession, allTasks); 63 } 64 65 for (Map.Entry<ITask, List<ITaskInstance>> entry : allTasks.entrySet()) { 66 assertEquals("number of task instances of task " + entry.getKey() + " in the " + 67 "sessions is not equal to those referenced by the model", 68 entry.getValue().size(), entry.getKey().getInstances().size()); 69 70 for (ITaskInstance candidate : entry.getValue()) { 71 boolean found = false; 72 for (ITaskInstance instance : entry.getKey().getInstances()) { 73 if (candidate.equals(instance)) { 74 if (!found) { 75 found = true; 76 } 77 else { 78 fail("the same instance is referred twice by the task"); 79 } 80 } 81 } 82 83 assertTrue("instance " + candidate + " is not referred by task", found); 84 } 85 } 86 } 87 88 /** 89 * 90 */ 48 91 public void validate(List<IUserSession> userSessions) { 49 92 for (IUserSession userSession : userSessions) { … … 94 137 assertFalse("child of selection model must not be a selection", 95 138 childTask instanceof ISelection); 96 assertFalse("child of selection model must not be an optional",97 childTask instanceof IOptional); 139 /*assertFalse("child of selection model must not be an optional", 140 childTask instanceof IOptional);*/ 98 141 if (childTask.equals(((ISelectionInstance) taskInstance).getChild().getTask())) { 99 142 found = true; … … 155 198 } 156 199 } 200 201 202 /** 203 * 204 */ 205 private void getAllTasksAndInstances(ITaskInstanceList taskInstances, 206 final Map<ITask, List<ITaskInstance>> allTasks) 207 { 208 for (ITaskInstance taskInstance : taskInstances) { 209 210 taskInstance.accept(new DefaultTaskInstanceTraversingVisitor() { 211 212 /* (non-Javadoc) 213 * @see DefaultTaskInstanceTraversingVisitor#visit(IOptionalInstance) 214 */ 215 @Override 216 public void visit(IOptionalInstance optionalInstance) { 217 addToInstanceList(optionalInstance); 218 super.visit(optionalInstance); 219 } 220 221 /* (non-Javadoc) 222 * @see DefaultTaskInstanceTraversingVisitor#visit(ISelectionInstance) 223 */ 224 @Override 225 public void visit(ISelectionInstance selectionInstance) { 226 addToInstanceList(selectionInstance); 227 super.visit(selectionInstance); 228 } 229 230 /* (non-Javadoc) 231 * @see DefaultTaskInstanceTraversingVisitor#visit(IEventTaskInstance) 232 */ 233 @Override 234 public void visit(IEventTaskInstance eventTaskInstance) { 235 addToInstanceList(eventTaskInstance); 236 super.visit(eventTaskInstance); 237 } 238 239 /* (non-Javadoc) 240 * @see DefaultTaskInstanceTraversingVisitor#visit(IIterationInstance) 241 */ 242 @Override 243 public void visit(IIterationInstance iterationInstance) { 244 addToInstanceList(iterationInstance); 245 super.visit(iterationInstance); 246 } 247 248 /* (non-Javadoc) 249 * @see DefaultTaskInstanceTraversingVisitor#visit(ISequenceInstance) 250 */ 251 @Override 252 public void visit(ISequenceInstance sequenceInstance) { 253 addToInstanceList(sequenceInstance); 254 super.visit(sequenceInstance); 255 } 256 257 private void addToInstanceList(ITaskInstance taskInstance) { 258 List<ITaskInstance> instances = allTasks.get(taskInstance.getTask()); 259 260 if (instances == null) { 261 instances = new LinkedList<ITaskInstance>(); 262 allTasks.put(taskInstance.getTask(), instances); 263 } 264 265 boolean found = false; 266 267 for (ITaskInstance candidate : instances) { 268 if (candidate.equals(taskInstance)) { 269 found = true; 270 break; 271 } 272 } 273 274 assertFalse("instance " + taskInstance + " occurred twice", found); 275 276 instances.add(taskInstance); 277 } 278 279 }); 280 } 281 } 157 282 }
Note: See TracChangeset
for help on using the changeset viewer.