def setUp(self): self.pencil = Item.create("Pencil", 0.40) self.ruler = Item.create("Ruler", 1.60) self.eraser = Item.create("Eraser", 0.20) self.pencilSet = Item.compose("Pencil Set", self.pencil, self.ruler, self.eraser) self.stdout = MockStdout()
def test_add_to_composite(self): lead = Item.create("Lead", 0.05) self.pencilSet.add(lead) self.assertAlmostEqual(self.pencilSet.price, 2.25) pen = Item.create("Pen", 0.25) self.pencilSet.add(pen) self.assertAlmostEqual(self.pencilSet.price, 2.50)
def test_compose(self): # TODO Implement me! # Do not forget to replace self.fail() statement with # correct assertion method(s)! mechPencilCasing = Item.create("Mechanical Pencil Casing", 4.20) mechPencilLead = Item.create("Mechanical Pencil Lead", 0.10) mechPencil = Item.compose("Mechanical Pencil", mechPencilCasing, mechPencilLead) self.assertEqual(mechPencil.name, "Mechanical Pencil") self.assertAlmostEqual(mechPencil.price, 4.30) self.assertTrue(mechPencil.composite)
def test_create(self): # TODO Implement me! # Do not forget to replace self.fail() statement with # correct assertion method(s)! tipex = Item.create("Tipex", 1.00) self.assertEqual(tipex.name, "Tipex") self.assertAlmostEqual(tipex.price, 1.00) self.assertFalse(tipex.composite)
def test_remove_not_in_composite(self): mysterious = Item.create("Wat", 9.99) with self.assertRaises(ValueError): self.pencilSet.remove(mysterious)
def test_remove_simple(self): lead = Item.create("Lead", 0.05) self.assertFalse(self.pencil.composite) self.pencil.add(lead) self.pencil.remove(lead) self.assertFalse(self.pencil.composite)
def test_add_to_simple(self): lead = Item.create("Lead", 0.05) self.assertFalse(self.pencil.composite) self.pencil.add(lead) self.assertTrue(self.pencil.composite) self.assertAlmostEqual(self.pencil.price, 0.45)