[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
| 2 | // |
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 4 | // you may not use this file except in compliance with the License. |
---|
| 5 | // You may obtain a copy of the License at |
---|
| 6 | // |
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 8 | // |
---|
| 9 | // Unless required by applicable law or agreed to in writing, software |
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 12 | // See the License for the specific language governing permissions and |
---|
| 13 | // limitations under the License. |
---|
| 14 | |
---|
[1146] | 15 | package de.ugoe.cs.autoquest.tasktrees.taskequality; |
---|
[807] | 16 | |
---|
| 17 | import static org.junit.Assert.*; |
---|
| 18 | |
---|
| 19 | import org.junit.Test; |
---|
| 20 | |
---|
[1146] | 21 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
| 22 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
| 23 | import de.ugoe.cs.autoquest.eventcore.StringEventType; |
---|
| 24 | import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality; |
---|
| 25 | import de.ugoe.cs.autoquest.tasktrees.taskequality.SelectionComparisonRule; |
---|
[922] | 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
[1146] | 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; |
---|
| 29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; |
---|
| 31 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskBuilder; |
---|
| 32 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory; |
---|
| 33 | import de.ugoe.cs.autoquest.test.DummyGUIElement; |
---|
[807] | 34 | |
---|
| 35 | /** |
---|
| 36 | * @author Patrick Harms |
---|
| 37 | */ |
---|
| 38 | public class SelectionComparisonRuleTest { |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * |
---|
| 42 | */ |
---|
| 43 | @Test |
---|
| 44 | public void test() { |
---|
[1146] | 45 | ITaskFactory taskFactory = new TaskFactory(); |
---|
| 46 | ITaskBuilder treeBuilder = new TaskBuilder(); |
---|
[807] | 47 | |
---|
[1190] | 48 | SelectionComparisonRule rule = new SelectionComparisonRule(); |
---|
[807] | 49 | |
---|
[1146] | 50 | IEventType eventType1 = new StringEventType("eventType1"); |
---|
| 51 | IEventTarget eventTarget1 = new DummyGUIElement("elem1"); |
---|
| 52 | |
---|
| 53 | IEventType eventType2 = new StringEventType("eventType2"); |
---|
| 54 | IEventTarget eventTarget2 = new DummyGUIElement("elem2"); |
---|
| 55 | |
---|
| 56 | ITask task1 = taskFactory.createNewEventTask(eventType1, eventTarget1); |
---|
| 57 | ITask task2 = taskFactory.createNewEventTask(eventType2, eventTarget2); |
---|
[807] | 58 | |
---|
[1125] | 59 | assertFalse(rule.isApplicable(task1, task2)); |
---|
[807] | 60 | |
---|
[1146] | 61 | ISelection selection1 = taskFactory.createNewSelection(); |
---|
| 62 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection1)); |
---|
[807] | 63 | |
---|
[1146] | 64 | ISelection selection2 = taskFactory.createNewSelection(); |
---|
[807] | 65 | |
---|
[1146] | 66 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection2)); |
---|
| 67 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection1)); |
---|
[807] | 68 | |
---|
| 69 | treeBuilder.addChild(selection1, task1); |
---|
| 70 | |
---|
[1146] | 71 | assertEquals(TaskEquality.UNEQUAL, rule.compare(selection1, selection2)); |
---|
| 72 | assertEquals(TaskEquality.UNEQUAL, rule.compare(selection2, selection1)); |
---|
[807] | 73 | |
---|
| 74 | treeBuilder.addChild(selection2, task1); |
---|
| 75 | |
---|
[1146] | 76 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection2)); |
---|
| 77 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection1)); |
---|
[807] | 78 | |
---|
| 79 | treeBuilder.addChild(selection1, task2); |
---|
| 80 | |
---|
[1146] | 81 | assertEquals(TaskEquality.UNEQUAL, rule.compare(selection1, selection2)); |
---|
| 82 | assertEquals(TaskEquality.UNEQUAL, rule.compare(selection2, selection1)); |
---|
[807] | 83 | |
---|
| 84 | treeBuilder.addChild(selection2, task2); |
---|
| 85 | |
---|
[1146] | 86 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection2)); |
---|
| 87 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection1)); |
---|
[807] | 88 | |
---|
[1146] | 89 | ISelection selection3 = taskFactory.createNewSelection(); |
---|
[807] | 90 | treeBuilder.addChild(selection3, task2); |
---|
| 91 | treeBuilder.addChild(selection3, task1); |
---|
| 92 | |
---|
[1146] | 93 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection3)); |
---|
| 94 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection3, selection1)); |
---|
[807] | 95 | |
---|
[1146] | 96 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection3)); |
---|
| 97 | assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection3, selection2)); |
---|
[807] | 98 | |
---|
[1146] | 99 | ISequence sequence = taskFactory.createNewSequence(); |
---|
[1125] | 100 | assertFalse(rule.isApplicable(selection1, sequence)); |
---|
| 101 | assertFalse(rule.isApplicable(sequence, selection1)); |
---|
| 102 | assertFalse(rule.isApplicable(selection2, sequence)); |
---|
| 103 | assertFalse(rule.isApplicable(sequence, selection2)); |
---|
| 104 | assertFalse(rule.isApplicable(selection3, sequence)); |
---|
| 105 | assertFalse(rule.isApplicable(sequence, selection3)); |
---|
[807] | 106 | } |
---|
| 107 | |
---|
| 108 | } |
---|