package de.ugoe.cs.quest.tasktrees.nodeequality;

import static org.junit.Assert.*;

import org.junit.Test;

import de.ugoe.cs.quest.eventcore.IEventTarget;
import de.ugoe.cs.quest.eventcore.IEventType;
import de.ugoe.cs.quest.eventcore.StringEventType;
import de.ugoe.cs.quest.tasktrees.treeifc.ISelection;
import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode;
import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory;
import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory;
import de.ugoe.cs.quest.test.DummyGUIElement;

/**
 * @author Patrick Harms
 */
public class EventTaskComparisonRuleTest {

    /**
     *
     */
    @Test
    public void test() {
        ITaskTreeNodeFactory treeNodeFactory = new TaskTreeNodeFactory();
        
        EventTaskComparisonRule rule = new EventTaskComparisonRule();
        
        // test the identity check
        IEventType eventType1 = new StringEventType("eventType1");
        IEventTarget eventTarget1 = new DummyGUIElement("elem1");
        ITaskTreeNode task1 = treeNodeFactory.createNewEventTask(eventType1, eventTarget1);
        
        assertEquals(NodeEquality.IDENTICAL, rule.compare(task1, task1));

        ITaskTreeNode task2 = treeNodeFactory.createNewEventTask(eventType1, eventTarget1);
        
        assertEquals(NodeEquality.LEXICALLY_EQUAL, rule.compare(task1, task2));
        assertEquals(NodeEquality.LEXICALLY_EQUAL, rule.compare(task2, task1));
        
        IEventType eventType2 = new StringEventType("eventType2");
        task2 = treeNodeFactory.createNewEventTask(eventType2, eventTarget1);

        assertEquals(NodeEquality.UNEQUAL, rule.compare(task1, task2));
        assertEquals(NodeEquality.UNEQUAL, rule.compare(task2, task1));
        
        IEventTarget eventTarget2 = new DummyGUIElement("elem2");
        task2 = treeNodeFactory.createNewEventTask(eventType1, eventTarget2);
        
        assertEquals(NodeEquality.UNEQUAL, rule.compare(task1, task2));
        assertEquals(NodeEquality.UNEQUAL, rule.compare(task2, task1));
        
        task2 = treeNodeFactory.createNewEventTask(eventType2, eventTarget2);
        
        assertEquals(NodeEquality.UNEQUAL, rule.compare(task1, task2));
        assertEquals(NodeEquality.UNEQUAL, rule.compare(task2, task1));

        ISelection selection = treeNodeFactory.createNewSelection();
        assertNull(rule.compare(task1, selection));
        assertNull(rule.compare(selection, task1));
        assertNull(rule.compare(task2, selection));
        assertNull(rule.compare(selection, task2));
    }

}
