source: trunk/autoquest-core-tasktrees-test/src/test/java/de/ugoe/cs/autoquest/tasktrees/taskequality/SelectionComparisonRuleTest.java @ 1146

Last change on this file since 1146 was 1146, checked in by pharms, 11 years ago
  • complete refactoring of task tree model with a separation of task models and task instances
  • appropriate adaptation of task tree generation process
  • appropriate adaptation of commands and task tree visualization
File size: 4.8 KB
Line 
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
15package de.ugoe.cs.autoquest.tasktrees.taskequality;
16
17import static org.junit.Assert.*;
18
19import org.junit.Test;
20
21import de.ugoe.cs.autoquest.eventcore.IEventTarget;
22import de.ugoe.cs.autoquest.eventcore.IEventType;
23import de.ugoe.cs.autoquest.eventcore.StringEventType;
24import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEquality;
25import de.ugoe.cs.autoquest.tasktrees.taskequality.SelectionComparisonRule;
26import de.ugoe.cs.autoquest.tasktrees.taskequality.TaskEqualityRuleManager;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder;
30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
31import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
32import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskBuilder;
33import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory;
34import de.ugoe.cs.autoquest.test.DummyGUIElement;
35
36/**
37 * @author Patrick Harms
38 */
39public class SelectionComparisonRuleTest {
40
41    /**
42     *
43     */
44    @Test
45    public void test() {
46        TaskEqualityRuleManager manager = new TaskEqualityRuleManager();
47        manager.init();
48       
49        ITaskFactory taskFactory = new TaskFactory();
50        ITaskBuilder treeBuilder = new TaskBuilder();
51       
52        SelectionComparisonRule rule = new SelectionComparisonRule(manager);
53       
54        IEventType eventType1 = new StringEventType("eventType1");
55        IEventTarget eventTarget1 = new DummyGUIElement("elem1");
56
57        IEventType eventType2 = new StringEventType("eventType2");
58        IEventTarget eventTarget2 = new DummyGUIElement("elem2");
59
60        ITask task1 = taskFactory.createNewEventTask(eventType1, eventTarget1);
61        ITask task2 = taskFactory.createNewEventTask(eventType2, eventTarget2);
62       
63        assertFalse(rule.isApplicable(task1, task2));
64       
65        ISelection selection1 = taskFactory.createNewSelection();
66        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection1));
67
68        ISelection selection2 = taskFactory.createNewSelection();
69       
70        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection2));
71        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection1));
72       
73        treeBuilder.addChild(selection1, task1);
74       
75        assertEquals(TaskEquality.UNEQUAL, rule.compare(selection1, selection2));
76        assertEquals(TaskEquality.UNEQUAL, rule.compare(selection2, selection1));
77       
78        treeBuilder.addChild(selection2, task1);
79       
80        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection2));
81        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection1));
82       
83        treeBuilder.addChild(selection1, task2);
84       
85        assertEquals(TaskEquality.UNEQUAL, rule.compare(selection1, selection2));
86        assertEquals(TaskEquality.UNEQUAL, rule.compare(selection2, selection1));
87       
88        treeBuilder.addChild(selection2, task2);
89       
90        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection2));
91        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection1));
92       
93        ISelection selection3 = taskFactory.createNewSelection();
94        treeBuilder.addChild(selection3, task2);
95        treeBuilder.addChild(selection3, task1);
96       
97        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection1, selection3));
98        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection3, selection1));
99       
100        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection2, selection3));
101        assertEquals(TaskEquality.LEXICALLY_EQUAL, rule.compare(selection3, selection2));
102
103        ISequence sequence = taskFactory.createNewSequence();
104        assertFalse(rule.isApplicable(selection1, sequence));
105        assertFalse(rule.isApplicable(sequence, selection1));
106        assertFalse(rule.isApplicable(selection2, sequence));
107        assertFalse(rule.isApplicable(sequence, selection2));
108        assertFalse(rule.isApplicable(selection3, sequence));
109        assertFalse(rule.isApplicable(sequence, selection3));
110    }
111
112}
Note: See TracBrowser for help on using the repository browser.