def test_finishTasksAfterAssigningTasksToWorkers(self):
        workers = [
            Worker(workerID="W1",
                   begin=tHour(0, 00),
                   end=tHour(23, 59),
                   multitask=1),
            Worker(workerID="W2",
                   begin=tHour(0, 00),
                   end=tHour(23, 59),
                   multitask=1),
            Worker(workerID="W3",
                   begin=tHour(0, 00),
                   end=tHour(23, 59),
                   multitask=1)
        ]
        taskManager = TaskManager(period=self.tPeriod(), multitask=1)
        taskManager.addTask(self.tasks[0])
        taskManager.addTask(self.tasks[1])
        taskManager.addWorkers(workers)
        taskManager.assignTasksToWorkers()
        self.assertEqual(len(taskManager.workers), 3)
        taskManager.finishTask(self.tasks[0].taskID)
        self.assertEqual(len(workers[0].assignedTasks), 0)
        self.assertEqual(len(taskManager.workers), 3)

        taskManager.finishTask(self.tasks[1].taskID)  # test with id too.
        self.assertEqual(len(workers[1].assignedTasks), 0)
        self.assertEqual(len(taskManager.workers), 3)
 def test_removeWorkerAfterAssigningTasks(self):
     workers = [
         Worker(workerID="W1",
                begin=tHour(0, 00),
                end=tHour(23, 59),
                multitask=1),
         Worker(workerID="W2",
                begin=tHour(0, 00),
                end=tHour(23, 59),
                multitask=1)
     ]
     taskManager = TaskManager(self.tPeriod(), multitask=1)
     taskManager.addTasks([self.tasks[0], self.tasks[1]])
     taskManager.addWorkers(workers)
     taskManager.assignTasksToWorkers()
     # make sure the exception is thrown as the tasks are not finished yet.
     with self.assertRaises(UnfinishedTasksHeldByWorkerException):
         taskManager.removeWorker(workers[0].workerID)
     # finish the tasks and remove workers
     taskManager.finishTask(self.tasks[0].taskID)
     taskManager.removeWorker(workers[0].workerID)
     self.assertEqual(len(taskManager.workers), 1)
     taskManager.finishTask(self.tasks[1].taskID)
     taskManager.removeWorker(workers[1].workerID)
     self.assertEqual(len(taskManager.workers), 0)
 def test_finishTasks(self):
     taskManager = TaskManager(period=self.tPeriod(), multitask=1)
     taskManager.addTask(self.tasks[0])
     taskManager.addTask(self.tasks[1])
     self.assertEqual(len(taskManager.taskSet.tasks), 2)
     taskManager.finishTask(self.tasks[0].taskID)
     self.assertEqual(len(taskManager.taskSet.tasks), 1)
     taskManager.finishTask(self.tasks[1].taskID)
     self.assertEqual(len(taskManager.taskSet.tasks), 0)
 def test_noConflictsAfterAllTasksRemoved(self):
     workers = [
         Worker(workerID="W1",
                begin=tHour(0, 00),
                end=tHour(23, 59),
                multitask=1),
         Worker(workerID="W2",
                begin=tHour(0, 00),
                end=tHour(23, 59),
                multitask=1),
     ]
     taskManager = TaskManager(period=self.tPeriod(), multitask=1)
     taskManager.addWorkers(workers)
     taskManager.addTask(self.tasks[0])
     taskManager.addTask(self.tasks[1])
     taskManager.assignTasksToWorkers()
     conflicts = taskManager.analyseWorkersForNeededTaskSet()[0]
     self.assertEqual(conflicts[0].workersNeeded, 2)
     taskManager.finishTask(self.tasks[0].taskID)
     taskManager.finishTask(self.tasks[1].taskID)
     conflicts = taskManager.analyseWorkersForNeededTaskSet()[0]
     self.assertEqual(len(conflicts), 0)  # there should be not conflicts
 def test_workerGetsAssignedAnotherTaskAfterFinishing(self):
     workers = [
         Worker(workerID="W1",
                begin=tHour(0, 00),
                end=tHour(23, 59),
                multitask=1),
         Worker(workerID="W2",
                begin=tHour(0, 00),
                end=tHour(23, 59),
                multitask=1),
     ]
     taskManager = TaskManager(period=self.tPeriod(), multitask=1)
     taskManager.addWorkers(workers)
     taskManager.addTasks(self.tasks)
     taskManager.assignTasksToWorkers()
     self.assertEqual(len(workers[0].assignedTasks), 1)
     self.assertEqual(len(workers[1].assignedTasks), 1)
     # check that task was unnasigned from worker.
     assignedTask = workers[0].assignedTasks[0]
     taskManager.finishTask(assignedTask.taskID)
     self.assertEqual(len(workers[0].assignedTasks), 0)
     # now assign tasks if theres any more.
     taskManager.assignTasksToWorkers()
     self.assertEqual(len(workers[0].assignedTasks), 1)