Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
 def test_remove_not_in_composite(self):
     mysterious = Item.create("Wat", 9.99)
     with self.assertRaises(ValueError):
         self.pencilSet.remove(mysterious)
Ejemplo n.º 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)
Ejemplo n.º 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)