class StockItemTest(unittest.TestCase): def setUp(self): print '*Entering setUp method*' '''This will create a StockItem instance that can be used throughout the StockItemTest class.''' self.Stock1 = StockItem() def test__add__(self): print '*Entering test__add__ method*' '''This will create a new StockItem instance that the user should input the purchase price as 1. This function will then check that __add__ method makes 1 + 1 = 2''' Stock2 = StockItem() addition = self.Stock1.__add__(Stock2) self.assertEqual(addition, 2) def test_storageCost (self): print '*Entering test_storageCost method*' '''Please input purchase price as 1. This method will then check that storage cost is 5% of 1.''' storage = self.Stock1.calculateStorageCost() self.assertEqual(storage,0.05) def test_mul (self): print '*Entering test_mul method*' '''Make sure that user inputs 1 as unit price for this method to properly be able to test __mul__ method''' multi = self.Stock1.__mul__(2.2) self.assertAlmostEquals(multi,2.2) def tearDown(self): print '*Entering tearDown method*' pass
def __mul__(self, x): print '**Entering __mul__ CD method**' '''Method to return the price of multiple copies of a CD with a 10% discount for bulk buying.''' price = StockItem.__mul__(self, x) discount = price * 0.1 newPrice = price - discount return newPrice