def test_updated_task_after_cpu_udpate(self): cpu_a = Cpu('Cpu A') deadline = period = 10 cpu_time = 5 Task('A', cpu_a, deadline, period, cpu_time) Task('B', cpu_a, deadline, period, cpu_time) cpu_a.update()
def test_fail_having_more_than_one_task_overlapping(self): cpu = Cpu('Cpu A') Task('A', cpu, deadline=5, period=5, cpu_time=5) Task('B', cpu, deadline=5, period=5, cpu_time=5) with self.assertRaises(Exception): for x in range(20): cpu.update()
def test_correct_simulation_1(self): cpu = Cpu('Cpu A') Task('A', cpu, deadline=10, period=10, cpu_time=5) Task('B', cpu, deadline=10, period=10, cpu_time=3) Task('C', cpu, deadline=10, period=20, cpu_time=1) Task('D', cpu, deadline=10, period=20, cpu_time=1) for x in range(40): cpu.update()
class CpuTestCase(unittest.TestCase): def setUp(self) -> None: name = 'Demo Cpu' self.cpu_demo = Cpu(name) self.task_demo = Mock() def test_gets(self): name = 'Cpu A' cpu_a = Cpu(name) self.assertEqual(name, cpu_a.name) def test_cpu_initial_time_is_0(self): name = 'Cpu A' cpu_a = Cpu(name) self.assertEqual(0, cpu_a.time) def test_cpu_initial_tasks_is_empty(self): name = 'Cpu A' cpu_a = Cpu(name) self.assertFalse(cpu_a.tasks) def test_cpu_assign_task(self): tasks_len = len(self.cpu_demo.tasks) self.cpu_demo.add_task(self.task_demo) self.assertEqual(tasks_len + 1, len(self.cpu_demo.tasks)) def test_cpu_remove_task(self): tasks_len = len(self.cpu_demo.tasks) self.cpu_demo.add_task(self.task_demo) self.cpu_demo.remove_task(self.task_demo) self.assertEqual(tasks_len, len(self.cpu_demo.tasks)) def test_cpu_add_one_time_after_update(self): initial_time = self.cpu_demo.time self.cpu_demo.update() self.assertEqual(initial_time + 1, self.cpu_demo.time)
def setUp(self) -> None: name = 'Demo Cpu' self.cpu_demo = Cpu(name) self.task_demo = Mock()
def test_cpu_initial_tasks_is_empty(self): name = 'Cpu A' cpu_a = Cpu(name) self.assertFalse(cpu_a.tasks)
def test_cpu_initial_time_is_0(self): name = 'Cpu A' cpu_a = Cpu(name) self.assertEqual(0, cpu_a.time)
def test_gets(self): name = 'Cpu A' cpu_a = Cpu(name) self.assertEqual(name, cpu_a.name)
def test_correct_simulation_2(self): cpu = Cpu('Cpu A') Task('A', cpu, deadline=5, period=5, cpu_time=3) Task('B', cpu, deadline=5, period=5, cpu_time=2) for x in range(40): cpu.update()