class TestMemory(unittest.TestCase): def setUp(self): self.memory = Memory() def test_put_adds_instruction_in_specified_address(self): self.memory.put(00000, "instruccion1") self.assertEqual("instruccion1", self.memory.get(00000), "Instruction not found in memory cell") def test_get_gets_instruction_from_specified_address(self): instruction = self.memory.put(00000, "instruccion1") self.assertEqual("instruccion1", instruction, "Instruction not found in memory cell")
def setUp(self): self.memory = Memory() self.memory.put(1, Instruction("CPU Instruction", True )) self.memory.put(2, Instruction("IO Instruction", False )) self.irq_manager = IrqManager() self.cpu = Cpu(self.memory, self.irq_manager) self.pcb = Pcb(0, 1, 2)
class TestCpu(unittest.TestCase): def setUp(self): self.memory = Memory() self.memory.put(1, Instruction("CPU Instruction", True )) self.memory.put(2, Instruction("IO Instruction", False )) self.irq_manager = IrqManager() self.cpu = Cpu(self.memory, self.irq_manager) self.pcb = Pcb(0, 1, 2) def test_when_fetch_without_pcb_then_throws_exception(self): with self.assertRaises(NoPcbSetException): self.cpu.__fetch() def test_when_fetch_with_pcb_and_no_interruption_then_executes_instruction(self): self.cpu.set_current_pcb(self.pcb) def test_when_fetch_with_pcb_and_interruption_ocurrs_then_delegates_to_int_mgr(self): pass
class TestMemory(unittest.TestCase): def setUp(self): self.memory = Memory() for n in range(10): self.memory.put(n, "instruction" + str(n)) def test_get_gets_instruction_from_specified_address(self): instruction = self.memory.get(1) self.assertEqual("instruction1", instruction , "Instruction not found in memory cell") def test_put_adds_instruction_in_specified_address(self): self.memory.put(10, "ins") self.assertEqual("ins", self.memory.get(10), "Instruction not found in memory cell") def test_memory_error(self): with self.assertRaises(InvalidAddressException): self.memory.get(-1)
def setUp(self): self.memory = Memory() for n in range(10): self.memory.put(n, "instruction" + str(n))
def setUp(self): self.memory = Memory()
def setUp(self): self.pcb = Pcb() self.cpu = Cpu(Memory())