コード例 #1
0
 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()
コード例 #2
0
    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)
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
0
 def test_remove_not_in_composite(self):
     mysterious = Item.create("Wat", 9.99)
     with self.assertRaises(ValueError):
         self.pencilSet.remove(mysterious)
コード例 #6
0
 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)
コード例 #7
0
 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)