Пример #1
0
        public void Setup()
        {
            mockedInputSource = new Mock<CTLInputSource>();
            mockedDomain = new Mock<CTLDomain>();
            ctlModel = new CTLModel(mockedInputSource.Object, mockedDomain.Object);

            // Setup event-related data
            startedEvent = new InputElement("1", "TEST", InputElement.Type.Event, InputElement.Action.Started);
            generatedEvent = new CTLEvent("1", "TEST", 0, 0);
            mockedDomain.Setup(domain => domain.generateEvent(startedEvent)).Returns(generatedEvent);
            stoppedEvent = new InputElement("1", "TEST", InputElement.Type.Event, InputElement.Action.Stopped);

            // Setup task-related data
            startedTask = new InputElement("2", "TEST", InputElement.Type.Task, InputElement.Action.Started);
            startedTask.secondaryIndentifier = "1";
            generatedTask = new CTLTask("2", "TEST");
            mockedDomain.Setup(domain => domain.generateTask(startedTask)).Returns(generatedTask);
            stoppedTask = new InputElement("2", "TEST", InputElement.Type.Task, InputElement.Action.Stopped);

            // Setup validTasks with which to calculate multitask elements
            validTask1 = new CTLTask("2", "ARI_IN");
            validTask2 = new CTLTask("3", "COMMUNICATIE");

            usedDomains = new List<int>(new int[] { (int)InformationDomain.InformationDomainUnknown });
        }
Пример #2
0
 public void generateTask_ExistingType()
 {
     InputElement validInputElement = new InputElement("0", "ARI_UIT", InputElement.Type.Task, InputElement.Action.Started);
     CTLTask ctlTask = domain.generateTask(validInputElement);
     Assert.IsNotNull(ctlTask);
     Assert.AreEqual(validInputElement.identifier, ctlTask.identifier);
     Assert.AreEqual(validInputElement.name, ctlTask.name);
 }
Пример #3
0
 public void generateEvent_ExistingType()
 {
     InputElement validInputElement = new InputElement("0", "VERTRAAGDE_TREIN_OK", InputElement.Type.Event, InputElement.Action.Started);
     CTLEvent ctlEvent = domain.generateEvent(validInputElement);
     Assert.IsNotNull(ctlEvent);
     Assert.AreEqual(validInputElement.identifier, ctlEvent.identifier);
     Assert.AreEqual(validInputElement.name, ctlEvent.name);
 }
        public void inputElementEquals_Logic()
        {
            InputElement inputElement1 =
                new InputElement("1", "FOO", InputElement.Type.Event, InputElement.Action.Started);
            InputElement inputElement2 =
                new InputElement("2", "FOO", InputElement.Type.Event, InputElement.Action.Started);

            // x.equals(x) should be true
            Assert.IsTrue(inputElement1.Equals(inputElement1));
            // x.equals(y) should be the same as y.equals(x)
            Assert.AreEqual(inputElement1.Equals(inputElement2), inputElement2.Equals(inputElement1));
            // x.equals(null) should be false
            Assert.IsFalse(inputElement1.Equals(null));
        }
Пример #5
0
        /// <summary>
        /// Generates a CTLTask instance from a InputElement instance
        /// </summary>
        /// <param name="inputElement">The InputElement to generate from</param>
        /// <returns>The generated CTLTask</returns>
        public override CTLTask generateTask(InputElement inputElement)
        {
            CTLTask ctlTask = null;

            List<Tuple<string, string, List<int>>> availableTaskData = PRLDomain.availableTaskData();

            foreach (Tuple<string, string, List<int>> taskData in availableTaskData)
            {
                if (taskData.Item1.Equals(inputElement.name))
                {
                    ctlTask = new CTLTask(inputElement.identifier, inputElement.name);
                    ctlTask.description = taskData.Item2;
                    ctlTask.informationDomains = taskData.Item3;
                    break;
                }
            }

            return ctlTask;
        }
        public void inputElementEquals_Properties()
        {
            InputElement inputElement1 =
                new InputElement("1", "FOO", InputElement.Type.Event, InputElement.Action.Started);
            InputElement inputElement2;

            // Equal objects
            inputElement2 = new InputElement("1", "FOO", InputElement.Type.Event, InputElement.Action.Started);
            Assert.IsTrue(inputElement1.Equals(inputElement2));
            // Different identifier
            inputElement2 = new InputElement("2", "FOO", InputElement.Type.Event, InputElement.Action.Started);
            Assert.IsFalse(inputElement1.Equals(inputElement2));
            // Different name
            inputElement2 = new InputElement("1", "BAR", InputElement.Type.Event, InputElement.Action.Started);
            Assert.IsFalse(inputElement1.Equals(inputElement2));
            // Different type
            inputElement2 = new InputElement("1", "FOO", InputElement.Type.Task, InputElement.Action.Started);
            Assert.IsFalse(inputElement1.Equals(inputElement2));
            // Different action
            inputElement2 = new InputElement("1", "FOO", InputElement.Type.Event, InputElement.Action.Stopped);
            Assert.IsFalse(inputElement1.Equals(inputElement2));
        }
Пример #7
0
        /// <summary>
        /// Generates a CTLEvent instance from a InputElement instance
        /// </summary>
        /// <param name="inputElement">The InputElement to generate from</param>
        /// <returns>The generated CTLEvent</returns>
        public override CTLEvent generateEvent(InputElement inputElement)
        {
            CTLEvent ctlEvent = null;

            // The possible event types with their corresponding mo and lip values
            Tuple<string, double, int>[] validValues =
            {Tuple.Create("GESTRANDE_TREIN", 0.6, 2),
             Tuple.Create("GESTOORDE_WISSEL", 0.8, 3),
             Tuple.Create("VERTRAAGDE_TREIN_OK", 0.2, 1),
             Tuple.Create("VERTRAAGDE_TREIN_PROBLEEM", 0.3, 1)};

            if (inputElement != null && inputElement.identifier != null && inputElement.name != null)
            {
                foreach(var values in validValues)
                {
                    if (values.Item1.Equals(inputElement.name))
                    {
                        ctlEvent = new CTLEvent(inputElement.identifier, inputElement.name, values.Item2, values.Item3);
                    }
                }
            }

            return ctlEvent;
        }
Пример #8
0
        /// <summary>
        /// Proces the tasks that have started.
        /// </summary>
        /// <param name="taskElement">The (parsed) task data</param>
        public void taskHasStarted(InputElement taskElement)
        {
            Console.WriteLine("CTLModel.taskHasStarted()");

            CTLTask taskStarted = domain.generateTask(taskElement);
            if (taskStarted != null)
            {
                taskStarted.startTime = taskStarted.endTime = sessionTime;

                foreach (CTLEvent ctlEvent in activeEvents)
                {
                    if (ctlEvent.identifier.Equals(taskElement.secondaryIndentifier))
                    {
                        taskStarted.ctlEvent = ctlEvent;

                        // If the task's mo value is not set, fallback by grabbing it from
                        // the event it belongs to.
                        if (taskStarted.moValue == -1)
                        {
                            taskStarted.moValue = ctlEvent.moValue;
                        }
                        // If the task's lip value is not set, fallback by grabbing it from
                        // the event it belongs to.
                        if (taskStarted.lipValue == 0)
                        {
                            taskStarted.lipValue = ctlEvent.lipValue;
                        }
                    }
                }

                activeTasks.Add(taskStarted);

                activeTasksHaveChanged = true;
            }
        }
Пример #9
0
 public void generateTask_NonExistingType()
 {
     InputElement invalidInputElement = new InputElement("0", "NONEXISTING_NAME", InputElement.Type.Task, InputElement.Action.Started);
     Assert.IsNull(domain.generateTask(invalidInputElement));
 }
Пример #10
0
 public void generateEvent_NonExistingType()
 {
     InputElement invalidInputElement = new InputElement("0", "NONEXISTING_TYPE", InputElement.Type.Event,InputElement.Action.Started);
     Assert.IsNull(domain.generateEvent(invalidInputElement));
 }
Пример #11
0
 /// <summary>
 /// Generates an event from an element read from an input source
 /// </summary>
 /// <param name="InputElement">An input element representing a task</param>
 /// <returns>A CTLTask</returns>
 public abstract CTLTask generateTask(InputElement InputElement);
Пример #12
0
 /// <summary>
 /// Generates an event from an element read from an input source
 /// </summary>
 /// <param name="InputElement">An input element representing an event</param>
 /// <returns>A CTLEvent</returns>
 public abstract CTLEvent generateEvent(InputElement InputElement);
Пример #13
0
        /// <summary>
        /// Proces the tasks that have stopped.
        /// </summary>
        /// <param name="taskElement">The (parsed) task data</param>
        public void taskHasStopped(InputElement taskElement)
        {
            Console.WriteLine("CTLModel.taskHasStopped()");

            CTLTask taskToRemove = null;
            foreach (CTLTask task in activeTasks)
            {
                if (task.identifier.Equals(taskElement.identifier))
                {
                    taskToRemove = task;
                }
            }
            activeTasks.Remove(taskToRemove);

            activeTasksHaveChanged = true;
        }
Пример #14
0
        /// <summary>
        /// Proces events that have stopped.
        /// </summary>
        /// <param name="eventElement">The (parsed) event data</param>
        public void eventHasStopped(InputElement eventElement)
        {
            Console.WriteLine("CTLModel.eventHasStopped()");

            CTLEvent ctlEventToRemove = null;
            foreach (CTLEvent ctlEvent in activeEvents)
            {
                if (ctlEvent.identifier.Equals(eventElement.identifier))
                {
                    ctlEvent.stopEvent(sessionTime);
                    ctlEventToRemove = ctlEvent;
                }
            }

            activeEvents.Remove(ctlEventToRemove);
        }
Пример #15
0
 /// <summary>
 /// Proces events that have started.
 /// </summary>
 /// <param name="eventElement">The (parsed) event data</param>
 public void eventHasStarted(InputElement eventElement)
 {
     Console.WriteLine("CTLModel.eventHasStarted()");
     CTLEvent ctlEvent = domain.generateEvent(eventElement);
     if (ctlEvent != null)
     {
         ctlEvent.startEvent(sessionTime);
         activeEvents.Add(ctlEvent);
     }
 }
Пример #16
0
        /// <summary>
        /// Returns a list containing all the elements that have occured in the 
        /// requested second. 
        /// </summary>
        /// <param name="second">The second requested</param>
        /// <returns>The list of elements in the same order as they occur in the xml-file</returns>
        public List<InputElement> elementsForSecond(int second)
        {
            List<InputElement> elements = new List<InputElement>();

            // Only positive natural seconds are accepted.
            if (second >= 0)
            {
                // Collect all the nodes (events, tasks) from the given second in one list
                List<XmlNode> childNodeList = new List<XmlNode>();
                if (second < secondNodeList.Count)
                {
                    foreach (XmlNode node in this.secondNodeList[second].ChildNodes)
                    {
                        childNodeList.Add(node);
                    }
                }

                // Convert the collected nodes into a list of InputElements
                foreach (XmlNode node in childNodeList)
                {
                    // Determine the InputElement type
                    InputElement.Type elementType;
                    string secondaryIdentifier = null;
                    elementType = determineType(node);

                    if(elementType.Equals(InputElement.Type.Task))
                    {
                        secondaryIdentifier = node.Attributes["eventID"].Value;
                    }

                    // Determine the InputElement action
                    InputElement.Action elementAction;
                    elementAction = determineAction(node);

                    // Determine the remaining values
                    string identifier = node.Attributes["id"].Value;
                    string name = node.FirstChild.InnerText;

                    // Create and add the InputElement
                    InputElement returnElement = new InputElement(identifier, name, elementType, elementAction);
                    returnElement.secondaryIndentifier = secondaryIdentifier;
                    elements.Add(returnElement);
                }
            }

            return elements;
        }
Пример #17
0
        public void updateTimerCallback_taskHasStopped()
        {
            xmlParser.loadTextReader(new StringReader(testInput2));

            // Check the delegate is called correctly
            InputElement receivedElement = null;
            mockedDelegate.Setup(delegateObject => delegateObject.taskHasStopped(It.IsAny<InputElement>()))
                .Callback((InputElement element) => receivedElement = element);
            // Process two seconds
            xmlParser.updateTimerCallback(null);
            xmlParser.updateTimerCallback(null);
            mockedDelegate.Verify(delegateObject => delegateObject.taskHasStopped(It.IsAny<InputElement>()), Times.Once());

            // Check the values passed to the delegate are correct
            InputElement expectedElement =
                new InputElement("2", "ARI_UIT", InputElement.Type.Task, InputElement.Action.Stopped);
            expectedElement.secondaryIndentifier = "1";
            Assert.AreEqual(expectedElement, receivedElement);
        }
Пример #18
0
        public void updateTimerCallback_eventHasStarted()
        {
            xmlParser.loadTextReader(new StringReader(testInput2));

            // Check the delegate is called correctly
            InputElement receivedElement = null;
            mockedDelegate.Setup(delegateObject => delegateObject.eventHasStarted(It.IsAny<InputElement>()))
                .Callback((InputElement element) => receivedElement = element);
            xmlParser.updateTimerCallback(null);
            mockedDelegate.Verify(delegateObject => delegateObject.eventHasStarted(It.IsAny<InputElement>()), Times.Once());

            // Check the values passed to the delegate are correct
            InputElement expectedElement =
                new InputElement("1", "TREIN_GESTRAND", InputElement.Type.Event, InputElement.Action.Started);
            Assert.AreEqual(expectedElement, receivedElement);
        }