Ejemplo n.º 1
0
class PageCreatorTest(unittest.TestCase):

    # Arrange
    def setUp(self):
        self.page_creator = PageCreator()
        self.pcb = PCB(0, 20, BlockHolder(None))

    def test_whenICreatePagesForPCB_ThenTheInfoHolderHasThemAsItShould(self):
        self.page_creator.create(self.pcb, 5)
        self.assertEqual(len(self.pcb.get_info_holder().get_hold()), 4)

    def test_whenICreatePagesForPCB_ThenTheInfoTheyHaveIsCorrect(self):
        self.page_creator.create(self.pcb, 5)
        page1 = self.pcb.get_info_holder().get_hold()[0]
        page2 = self.pcb.get_info_holder().get_hold()[1]
        page3 = self.pcb.get_info_holder().get_hold()[2]
        page4 = self.pcb.get_info_holder().get_hold()[3]

        self.assertEqual(page1.get_starting_index(), 0)
        self.assertEqual(page1.get_ending_index(), 4)
        self.assertEqual(page1.get_amount_of_instructions(), 5)

        self.assertEqual(page2.get_starting_index(), 5)
        self.assertEqual(page2.get_ending_index(), 9)
        self.assertEqual(page2.get_amount_of_instructions(), 5)

        self.assertEqual(page3.get_starting_index(), 10)
        self.assertEqual(page3.get_ending_index(), 14)
        self.assertEqual(page3.get_amount_of_instructions(), 5)

        self.assertEqual(page4.get_starting_index(), 15)
        self.assertEqual(page4.get_ending_index(), 19)
        self.assertEqual(page4.get_amount_of_instructions(), 5)
Ejemplo n.º 2
0
class PageCreatorTest(unittest.TestCase):

    # Arrange
    def setUp(self):
        self.page_creator = PageCreator()
        self.pcb = PCB(0, 20, BlockHolder(None))

    def test_whenICreatePagesForPCB_ThenTheInfoHolderHasThemAsItShould(self):
        self.page_creator.create(self.pcb, 5)
        self.assertEqual(len(self.pcb.get_info_holder().get_hold()), 4)

    def test_whenICreatePagesForPCB_ThenTheInfoTheyHaveIsCorrect(self):
        self.page_creator.create(self.pcb, 5)
        page1 = self.pcb.get_info_holder().get_hold()[0]
        page2 = self.pcb.get_info_holder().get_hold()[1]
        page3 = self.pcb.get_info_holder().get_hold()[2]
        page4 = self.pcb.get_info_holder().get_hold()[3]

        self.assertEqual(page1.get_starting_index(), 0)
        self.assertEqual(page1.get_ending_index(), 4)
        self.assertEqual(page1.get_amount_of_instructions(), 5)

        self.assertEqual(page2.get_starting_index(), 5)
        self.assertEqual(page2.get_ending_index(), 9)
        self.assertEqual(page2.get_amount_of_instructions(), 5)

        self.assertEqual(page3.get_starting_index(), 10)
        self.assertEqual(page3.get_ending_index(), 14)
        self.assertEqual(page3.get_amount_of_instructions(), 5)

        self.assertEqual(page4.get_starting_index(), 15)
        self.assertEqual(page4.get_ending_index(), 19)
        self.assertEqual(page4.get_amount_of_instructions(), 5)
Ejemplo n.º 3
0
 def test_whenIAddManyPCBs_thenItHasThatManyBlocks(self):
     pcb2 = PCB(1, 2, BlockHolder(None))
     pcb3 = PCB(2, 4, BlockHolder(None))
     pcb4 = PCB(2, 4, BlockHolder(None))
     self.policy.assign_to_memory(pcb2)
     self.policy.assign_to_memory(pcb3)
     self.policy.assign_to_memory(pcb4)
     self.assertEqual(len(self.policy._blocks), 4)
Ejemplo n.º 4
0
 def setUp(self):
     self.frame1 = Frame(0, 9, BlockHolder(None))
     self.frame2 = Frame(1, 9, BlockHolder(None))
     self.frame3 = Frame(2, 9, BlockHolder(None))
     self.frame4 = Frame(3, 9, BlockHolder(None))
     self.frames = [self.frame1, self.frame2, self.frame3, self.frame4]
     self.frame_manager = FrameManager(self.frames)
     self.page_creator = PageCreator()
     self.pcb = PCB(0, 30, BlockHolder(None))
     self.page_creator.create(self.pcb, 5)
Ejemplo n.º 5
0
 def test_whenINeedToCompact_thenItCompacts(self):
     pcb1 = PCB(0, 4, BlockHolder(None))
     pcb2 = PCB(1, 2, BlockHolder(None))
     pcb3 = PCB(2, 4, BlockHolder(None))
     pcb4 = PCB(2, 4, BlockHolder(None))
     self.policy.assign_to_memory(pcb1)
     self.policy.assign_to_memory(pcb2)
     pcb5 = PCB(3, 3, BlockHolder(None))
     self.policy.assign_to_memory(pcb5)
     self.assertEqual(len(self.policy._blocks), 4)
Ejemplo n.º 6
0
class FrameManagerTest(unittest.TestCase):

    # Arrange
    def setUp(self):
        self.frame1 = Frame(0, 9, BlockHolder(None))
        self.frame2 = Frame(1, 9, BlockHolder(None))
        self.frame3 = Frame(2, 9, BlockHolder(None))
        self.frame4 = Frame(3, 9, BlockHolder(None))
        self.frames = [self.frame1, self.frame2, self.frame3, self.frame4]
        self.frame_manager = FrameManager(self.frames)
        self.page_creator = PageCreator()
        self.pcb = PCB(0, 30, BlockHolder(None))
        self.page_creator.create(self.pcb, 5)

    def test_whenIAssignAPCBTheFirstTime_ThenFrameManagerUsesTheFirstFrame(self):
        # Pages
        first_frame = self.frame_manager.get_frames()[0]

        self.frame_manager.assign_page_to_frame(self.pcb)
        first_pcb_page = self.pcb.get_info_holder().get_hold()[0]
        self.assertEquals(first_frame.get_page(), first_pcb_page)

    def test_whenTheFirstPCBPageIsUsedAndPCBIsAssigned_ThenFrameManagerUsesTheSecondFrame(self):
        # Pages
        first_pcb_page = self.pcb.get_info_holder().get_hold()[0]
        second_pcb_page =self.pcb.get_info_holder().get_hold()[1]

        self.frame_manager.assign_page_to_frame(self.pcb)
        first_pcb_page.set_used()

        self.frame_manager.assign_page_to_frame(self.pcb)
        second_frame = self.frame_manager.get_frames()[1]
        self.assertEquals(second_frame.get_page(), second_pcb_page)

    def test_whenAllFramesAreUsedAndPCBAssignsOneMorePage_ThenTheYoungestFrameGetsEmpty(self):
        # Pages
        first_pcb_page = self.pcb.get_info_holder().get_hold()[0]
        second_pcb_page =self.pcb.get_info_holder().get_hold()[1]
        third_pcb_page = self.pcb.get_info_holder().get_hold()[2]
        forth_pcb_page = self.pcb.get_info_holder().get_hold()[3]
        fifth_pcb_page = self.pcb.get_info_holder().get_hold()[4]

        self.frame_manager.assign_page_to_frame(self.pcb)
        first_pcb_page.set_used()
        self.frame_manager.assign_page_to_frame(self.pcb)
        second_pcb_page.set_used()
        self.frame_manager.assign_page_to_frame(self.pcb)
        third_pcb_page.set_used()
        self.frame_manager.assign_page_to_frame(self.pcb)
        forth_pcb_page.set_used()

        forth_frame = self.frame_manager.get_frames()[3]

        self.frame_manager.assign_page_to_frame(self.pcb)
        self.assertEqual(forth_frame.get_page(), fifth_pcb_page)
Ejemplo n.º 7
0
 def setUp(self):
     self.hdd = HDD(10)
     self.fs = self.hdd.generate_file_system()
     self.instruction1 = InstructionIO()
     self.instruction2 = InstructionCPU()
     self.instructionList1 = [self.instruction1, self.instruction2]
     self.program1 = Program(self.instructionList1, "AProgram")
     self.fs.add_file("AProgram", self.program1)
     self.file1 = self.fs.get_program("AProgram")
     self.pcb = PCB(0, 2, BlockHolder(self.file1))
     self.mm = MemoryManager()
     self.mm.set_as_ca(FirstFit())
     self.mm.write(self.pcb)
Ejemplo n.º 8
0
class PCBTest(unittest.TestCase):

    #Arrange
    def setUp(self):
        self.hdd = HDD(10)
        self.fs = self.hdd.generate_file_system()
        self.instruction1 = InstructionIO()
        self.instruction2 = InstructionCPU()
        self.instructionList1 = [self.instruction1, self.instruction2]
        self.program1 = Program(self.instructionList1, "AProgram")
        self.fs.add_file("AProgram", self.program1)
        self.file1 = self.fs.get_program("AProgram")
        self.pcb = PCB(0, 2, BlockHolder(self.file1))
        self.mm = MemoryManager()
        self.mm.set_as_ca(FirstFit())
        self.mm.write(self.pcb)

    def test_whenIHaveAPCBAndItsIncremented_thenIHaveAPCBWithOneMoreInstructionIndex(self):
        self.pcb.increment()
        self.assertEqual(self.pcb.get_pc(), 3)

    def test_whenIHaveAPCBAndItsPriorityItsChanged_thenItsDifferent(self):
        self.pcb.set_priority(PCBPriorities().getPriorities().LOW)
        self.pcb.increase_priority()
        self.assertEqual(self.pcb._priority, PCBPriorities().getPriorities().MEDIUM)
Ejemplo n.º 9
0
class PCBTest(unittest.TestCase):

    #Arrange
    def setUp(self):
        self.hdd = HDD(10)
        self.fs = self.hdd.generate_file_system()
        self.instruction1 = InstructionIO()
        self.instruction2 = InstructionCPU()
        self.instructionList1 = [self.instruction1, self.instruction2]
        self.program1 = Program(self.instructionList1, "AProgram")
        self.fs.add_file("AProgram", self.program1)
        self.file1 = self.fs.get_program("AProgram")
        self.pcb = PCB(0, 2, BlockHolder(self.file1))
        self.mm = MemoryManager()
        self.mm.set_as_ca(FirstFit())
        self.mm.write(self.pcb)

    def test_whenIHaveAPCBAndItsIncremented_thenIHaveAPCBWithOneMoreInstructionIndex(
            self):
        self.pcb.increment()
        self.assertEqual(self.pcb.get_pc(), 3)

    def test_whenIHaveAPCBAndItsPriorityItsChanged_thenItsDifferent(self):
        self.pcb.set_priority(PCBPriorities().getPriorities().LOW)
        self.pcb.increase_priority()
        self.assertEqual(self.pcb._priority,
                         PCBPriorities().getPriorities().MEDIUM)
Ejemplo n.º 10
0
 def setUp(self):
     self.pcb = PCB(0, 0, None)
     self.block1 = Block(0, 0, 3)   # 4  Not enough size.
     self.block2 = Block(1, 4, 11)  # 6  First Fit.
     self.block3 = Block(2, 10, 12) # 3  Just another block with not enough size.
     self.block4 = Block(3, 13, 23) # 11 Worst Fit.
     self.block5 = Block(3, 24, 29) # 6  Another block.
     self.block6 = Block(4, 30, 34) # 5  Best Fit.
     self.blocks = [self.block1, self.block2, self.block3, self.block4, self.block5, self.block6] # This list is a list of Free Blocks.
Ejemplo n.º 11
0
 def setUp(self):
     self.hdd = HDD(10)
     self.fs = self.hdd.generate_file_system()
     self.instruction1 = InstructionIO()
     self.instruction2 = InstructionCPU()
     self.instructionList1 = [self.instruction1, self.instruction2]
     self.program1 = Program(self.instructionList1, "AProgram")
     self.fs.add_file("AProgram", self.program1)
     self.file1 = self.fs.get_program("AProgram")
     self.pcb = PCB(0, 2, BlockHolder(self.file1))
     self.mm = MemoryManager()
     self.mm.set_as_ca(FirstFit())
     self.mm.write(self.pcb)
Ejemplo n.º 12
0
class TestScheduler(unittest.TestCase):
    # Arrange
    def setUp(self):
        self.pcb1 = PCB(3, 5, 10)
        self.pcb2 = PCB(2, 5, 10)
        self.pcb3 = PCB(1, 5, 10)
        self.scheduler = Scheduler()

    def test_whenISetTheSchedulerPolicyAsFifo_thenIThePCBsAsThePriorityStates(
            self):
        self.scheduler.set_as_fifo()
        self.scheduler.add(self.pcb1)
        self.scheduler.add(self.pcb2)
        self.scheduler.add(self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb1)
        self.assertEquals(self.scheduler.next(), self.pcb2)
        self.assertEquals(self.scheduler.next(), self.pcb3)

    def test_whenISetTheSchedulerPolicyAsPriority_thenIThePCBsAsThePriorityStates(
            self):
        self.scheduler.set_as_pq()
        self.pcb1.set_priority(PCBPriorities().getPriorities().LOW)
        self.pcb2.set_priority(PCBPriorities().getPriorities().MEDIUM)
        self.pcb3.set_priority(PCBPriorities().getPriorities().HIGH)
        self.scheduler.add(self.pcb1)
        self.scheduler.add(self.pcb2)
        self.scheduler.add(self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb2)
        self.assertEquals(self.scheduler.next(), self.pcb1)

    def test_whenISetTheSchedulerPolicyAsRR_thenIThePCBsAsThePriorityStates(
            self):
        self.scheduler.set_as_rr(5)
        self.scheduler.add(self.pcb1)
        self.scheduler.add(self.pcb2)
        self.scheduler.add(self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb1)
        self.assertEquals(self.scheduler.next(), self.pcb2)
        self.assertEquals(self.scheduler.next(), self.pcb3)
Ejemplo n.º 13
0
class TestScheduler(unittest.TestCase):
    # Arrange
    def setUp(self):
        self.pcb1 = PCB(3, 5, 10)
        self.pcb2 = PCB(2, 5, 10)
        self.pcb3 = PCB(1, 5, 10)
        self.scheduler = Scheduler()

    def test_whenISetTheSchedulerPolicyAsFifo_thenIThePCBsAsThePriorityStates(self):
        self.scheduler.set_as_fifo()
        self.scheduler.add(self.pcb1)
        self.scheduler.add(self.pcb2)
        self.scheduler.add(self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb1)
        self.assertEquals(self.scheduler.next(), self.pcb2)
        self.assertEquals(self.scheduler.next(), self.pcb3)

    def test_whenISetTheSchedulerPolicyAsPriority_thenIThePCBsAsThePriorityStates(self):
        self.scheduler.set_as_pq()
        self.pcb1.set_priority(PCBPriorities().getPriorities().LOW)
        self.pcb2.set_priority(PCBPriorities().getPriorities().MEDIUM)
        self.pcb3.set_priority(PCBPriorities().getPriorities().HIGH)
        self.scheduler.add(self.pcb1)
        self.scheduler.add(self.pcb2)
        self.scheduler.add(self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb2)
        self.assertEquals(self.scheduler.next(), self.pcb1)

    def test_whenISetTheSchedulerPolicyAsRR_thenIThePCBsAsThePriorityStates(self):
        self.scheduler.set_as_rr(5)
        self.scheduler.add(self.pcb1)
        self.scheduler.add(self.pcb2)
        self.scheduler.add(self.pcb3)
        self.assertEquals(self.scheduler.next(), self.pcb1)
        self.assertEquals(self.scheduler.next(), self.pcb2)
        self.assertEquals(self.scheduler.next(), self.pcb3)
Ejemplo n.º 14
0
 def setUp(self):
     self.pcb1 = PCB(0, 4, BlockHolder(None))
     self.caPolicy = FirstFit()
     self.memory = Memory(20)
     self.policy = ContinuousAssignment(self.memory, self.caPolicy)
Ejemplo n.º 15
0
 def setUp(self):
     self.pcb1 = PCB(3, 5, 10)
     self.pcb2 = PCB(2, 5, 10)
     self.pcb3 = PCB(1, 5, 10)
     self.scheduler = Scheduler()
Ejemplo n.º 16
0
 def setUp(self):
     self.memory = Memory(50)
     self.policy = Paging(self.memory, 10)
     self.pcb1 = PCB(0, 25, PageHolder(None))
     self.pcb2 = PCB(1, 16, PageHolder(None))
Ejemplo n.º 17
0
 def setUp(self):
     self.page_creator = PageCreator()
     self.pcb = PCB(0, 20, BlockHolder(None))
Ejemplo n.º 18
0
 def setUp(self):
     self.page_creator = PageCreator()
     self.pcb = PCB(0, 20, BlockHolder(None))
Ejemplo n.º 19
0
 def setUp(self):
     self.pcb1 = PCB(3, 5, 10)
     self.pcb2 = PCB(2, 5, 10)
     self.pcb3 = PCB(1, 5, 10)
     self.scheduler = Scheduler()