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 }); }
/// <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; }
/// <summary> /// Sets the MO-value of a multitaks to be the sum of the MO-values of the original tasks when this sum is greater than 1. /// </summary> /// <param name="task1">The first task that overlaps</param> /// <param name="task2">The task that overlaps with task1</param> /// <returns>A double representing the MO value of the new multitask</returns> public static double multitaskMO(CTLTask task1, CTLTask task2) { double returnMO = 0.0; if (task1 != null && task2 != null) { returnMO = Math.Min(task1.moValue + task2.moValue, 1); } return returnMO; }
/// <summary> /// Sets the Lip-value of a multitask: the largest of the two lip-values of the original tasks /// </summary> /// <param name="task1">The first task that overlaps</param> /// <param name="task2">The task that overlaps with task1</param> /// <returns>The Lip value for a new task</returns> public static int multitaskLip(CTLTask task1, CTLTask task2) { int returnLip = 0; if (task1 != null && task2 != null) { returnLip = Math.Max(task1.lipValue, task2.lipValue); } return returnLip; }
/// <summary> /// Sets the array of domains of the new tasks to be the combined domains of both task1 and task2 /// Domains that occur in both tasks are only added once. /// </summary> /// <param name="task1">The first task that overlaps</param> /// <param name="task2">The task that overlaps with task1</param> /// <returns>An array of informationDomains</returns> public static List<int> multitaskDomain(CTLTask task1, CTLTask task2) { List<int> newDomain = null; if (task1 != null && task2 != null) { if (task1.informationDomains != null && task2.informationDomains != null) { newDomain = task1.informationDomains; List<int> tempDomain = task2.informationDomains; for (int i = 0; i <= tempDomain.Count - 1; i++) { if (!newDomain.Contains(tempDomain[i])) { newDomain.Add(tempDomain[i]); } } } } return newDomain; }
public void Setup() { // 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 }); }
public void multitaskMO_Null() { validTask1 = null; Assert.AreEqual(0.0, CTLMath.multitaskMO(validTask1, validTask2)); Assert.AreEqual(0.0, CTLMath.multitaskMO(validTask1, null)); }
public void multitaskDomain_DifferentDomains() { // The tasks have no domains in common, both domains are in usedDomains usedDomains.Add((int)InformationDomain.InformationDomainExternalContact); validTask1.informationDomains = new List<int>(new int[] { (int)InformationDomain.InformationDomainUnknown }); validTask2.informationDomains = new List<int>(new int[] { (int)InformationDomain.InformationDomainExternalContact }); Assert.AreEqual(CTLMath.multitaskDomain(validTask1, validTask2), usedDomains); // The tasks have 1 domain in common, all 3 domains are in usedDomains usedDomains.Add((int)InformationDomain.InformationDomainUsingInterface); CTLTask validTask3 = new CTLTask("4", "ARI_UIT"); validTask3.informationDomains = new List<int>(new int[] { (int)InformationDomain.InformationDomainUsingInterface, (int)InformationDomain.InformationDomainExternalContact }); Assert.AreEqual(usedDomains, CTLMath.multitaskDomain(validTask1, validTask3)); }
/// <summary> /// Creates a multitask from two tasks. The CTL-values for the multitask will be /// calculated and set, however the start- and endtime will not. /// </summary> /// <param name="task1">the first task</param> /// <param name="task2">the second task</param> /// <returns>the multitask</returns> private static CTLTask createMultitask(CTLTask task1, CTLTask task2) { // Create a new CTLTask CTLTask multiTask = new CTLTask("m"+multiTaskCounter+"("+task1.identifier+"+"+task2.identifier+")", task1.name + task2.name); // Set its values if (task1 != null && task2 != null) { multiTask.moValue = CTLMath.multitaskMO(task1, task2); multiTask.lipValue = CTLMath.multitaskLip(task1, task2); multiTask.informationDomains = CTLMath.multitaskDomain(task1, task2); } multiTaskCounter++; return multiTask; }
/// <summary> /// Returns a clone of the task. /// </summary> /// <returns>The clone object</returns> public Object Clone() { // NOTE: Structs are always copied on assignment CTLTask clone = new CTLTask(identifier, name); clone.description = this.description; clone.ctlEvent = this.ctlEvent; clone.startTime = this.startTime; clone.inProgress = this.inProgress; clone.endTime = this.endTime; clone.moValue = this.moValue; clone.lipValue = this.lipValue; clone.informationDomains = this.informationDomains; return clone; }