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.
def setUp(self): self.block1 = Block(1, 0, 4) self.block2 = Block(2, 5, 9) self.block3 = Block(3, 10, 14)
def setUp(self): self.block1 = Block(1,0,4) self.block2 = Block(2,5,9) self.block3 = Block(3,10,14)
class TestBlock(unittest.TestCase): #Arrange def setUp(self): self.block1 = Block(1, 0, 4) self.block2 = Block(2, 5, 9) self.block3 = Block(3, 10, 14) def test_WhenICreateANewBlock_ThenTheBlockIsFree(self): self.assertTrue(self.block1.isFree()) def test_WhenISetABlockAsUser_ThenItsUsed(self): self.block1.setUsed() self.assertFalse(self.block1.isFree()) def test_WhenIChangesABlocksIndexs_ThenTheyChange(self): self.block1.changeStartIndex(5) self.block1.changeEndIndex(9) self.assertEqual(self.block1._startIndex, 5) self.assertEqual(self.block1._endIndex, 9) def test_WhenIChangeNextBlockPointers_ThenIGetTheCorrectBlocks(self): self.block1.changeNextBlock_double(self.block2) self.block2.changeNextBlock_double(self.block3) self.assertEqual(self.block1.getNextBlock(), self.block2) self.assertEqual(self.block2.getNextBlock(), self.block3) self.assertEqual(self.block3.getPreviousBlock(), self.block2) self.assertEqual(self.block2.getPreviousBlock(), self.block1) def test_WhenIChangePreviousBlockPointers_ThenIGetTheCorrectBlocks(self): self.block2.changePreviousBlock_double(self.block1) self.block3.changePreviousBlock_double(self.block2) self.assertEqual(self.block1.getNextBlock(), self.block2) self.assertEqual(self.block2.getNextBlock(), self.block3) self.assertEqual(self.block3.getPreviousBlock(), self.block2) self.assertEqual(self.block2.getPreviousBlock(), self.block1)
class TestBlock(unittest.TestCase): #Arrange def setUp(self): self.block1 = Block(1,0,4) self.block2 = Block(2,5,9) self.block3 = Block(3,10,14) def test_WhenICreateANewBlock_ThenTheBlockIsFree(self): self.assertTrue(self.block1.isFree()) def test_WhenISetABlockAsUser_ThenItsUsed(self): self.block1.setUsed() self.assertFalse(self.block1.isFree()) def test_WhenIChangesABlocksIndexs_ThenTheyChange(self): self.block1.changeStartIndex(5) self.block1.changeEndIndex(9) self.assertEqual(self.block1._startIndex, 5) self.assertEqual(self.block1._endIndex, 9) def test_WhenIChangeNextBlockPointers_ThenIGetTheCorrectBlocks(self): self.block1.changeNextBlock_double(self.block2) self.block2.changeNextBlock_double(self.block3) self.assertEqual(self.block1.getNextBlock(), self.block2) self.assertEqual(self.block2.getNextBlock(), self.block3) self.assertEqual(self.block3.getPreviousBlock(), self.block2) self.assertEqual(self.block2.getPreviousBlock(), self.block1) def test_WhenIChangePreviousBlockPointers_ThenIGetTheCorrectBlocks(self): self.block2.changePreviousBlock_double(self.block1) self.block3.changePreviousBlock_double(self.block2) self.assertEqual(self.block1.getNextBlock(), self.block2) self.assertEqual(self.block2.getNextBlock(), self.block3) self.assertEqual(self.block3.getPreviousBlock(), self.block2) self.assertEqual(self.block2.getPreviousBlock(), self.block1)