Пример #1
0
 def test_inventory_total_weight(self):
     i = Inventory()
     for count in range(3):
         i.add_coconut(self.c1)
     for count in range(1):
         i.add_coconut(self.c2)
     for count in range(2):
         i.add_coconut(self.c3)
     self.assertEqual(19, i.total_weight(), "Calculated weight not correct")
Пример #2
0
 def test_add(self):
     inv = Inventory()
     sa = Coconut('south_asian', 3)
     me = Coconut('middle_eastern', 2.5)
     am = Coconut('american', 3.5)
     clist = [sa, sa, me, am, am, am]
     for i in clist:
         inv.add_coconut(i)
     expected = 19.0
     observed = inv.total_weight()
     self.assertEqual(observed, expected)
Пример #3
0
 def test_add(self):
     inv = Inventory()
     sa = Coconut('south_asian', 3)
     me = Coconut('middle_eastern', 2.5)
     am = Coconut('american', 3.5)
     clist = [sa,sa,me,am,am,am]
     for i in clist:
         inv.add_coconut(i)
     expected = 19.0
     observed = inv.total_weight()
     self.assertEqual(observed, expected)
Пример #4
0
    def test_inventory_total_weight(self):
        """
        Test ensuring if 2 South Asian, 1 Middle Eastern, and 3 American coconuts are added to the inventory, 
        the Inventory.total_weight() method returns 19.
        """
        south_asian_coconut = Coconut("South Asian")
        middle_eastern_coconut = Coconut("Middle Eastern")
        american_coconut = Coconut("American")

        inventory = Inventory()
        inventory.add_coconut(south_asian_coconut)
        inventory.add_coconut(south_asian_coconut)
        inventory.add_coconut(middle_eastern_coconut)
        inventory.add_coconut(american_coconut)
        inventory.add_coconut(american_coconut)
        inventory.add_coconut(american_coconut)

        self.assertEqual(
            inventory.total_weight(), 19,
            "Total weight of coconuts is %f but 19 is expected." %
            inventory.total_weight())
Пример #5
0
class TestCoconuts(unittest.TestCase):
    
    def test_weight(self):
        """
        Tests that different coconut types each have a different weight
        """
        # create a coconut of each type
        self.nuts = [Coconut(variety) for variety in ['middle eastern',
                                                      'south asian',
                                                      'american']]
        
        # check that weights are as expected
        self.weights = [2.5, 3.0, 3.5]
        for i in range(0,3):
            self.assertEqual(self.nuts[i]._Coconut__weight,
                             self.weights[i],
                             "The weight is wrong")
    
            
    def test_total_weight(self):
        """
        Tests that the sum of a specified number of coconuts of each type
        returned matches the expected total
        """
        varieties = [Coconut(variety) for variety in ['middle eastern',
                                                      'south asian',
                                                      'south asian',
                                                      'american',
                                                      'american',
                                                      'american']]
        self.inventory = Inventory()
        for variety in varieties:
            self.inventory.add_coconut(variety)
        self.assertEqual(self.inventory.total_weight(),
                         19.00,
                         "Your total weight is wrong")
        
            
    def test_string_attribute_errors(self):
        """
        Tests that a string passed as a coconut to the Inventory class
        throws an AttributeError
        """
        self.inventory = Inventory()
        with self.assertRaises(AttributeError):
            self.inventory.add_coconut('south asian')
Пример #6
0
    def test_inventory_total_weight(self):
        """
        Test ensuring if 2 South Asian, 1 Middle Eastern, and 3 American coconuts are added to the inventory, 
        the Inventory.total_weight() method returns 19.
        """
        south_asian_coconut    = Coconut("South Asian")
        middle_eastern_coconut = Coconut("Middle Eastern")
        american_coconut       = Coconut("American")

        inventory = Inventory()
        inventory.add_coconut(south_asian_coconut)
        inventory.add_coconut(south_asian_coconut)
        inventory.add_coconut(middle_eastern_coconut)
        inventory.add_coconut(american_coconut)
        inventory.add_coconut(american_coconut)
        inventory.add_coconut(american_coconut)
        
        self.assertEqual(inventory.total_weight(), 19, "Total weight of coconuts is %f but 19 is expected." % inventory.total_weight())
Пример #7
0
class Test(unittest.TestCase):
    def setUp(self):
        self.south_asian = Coconut(coconut_type="South Asian", coconut_weight=3)
        self.middle_eastern = Coconut(coconut_type="Middle Eastern", coconut_weight=2.5)
        self.american = Coconut(coconut_type="American", coconut_weight=3.5)
        self.inventory = Inventory()
    
    def test_coconuts(self):
        '''
        Test to ensure that each coconut type have different weight
        '''
        self.assertNotEqual(self.south_asian, self.middle_eastern , "South Asian and Middle Eastern coconuts have the same weight")
        self.assertNotEqual(self.south_asian, self.american, "South Asian and American coconuts have the same weight")
        self.assertNotEqual(self.middle_eastern, self.american, "Middle Eastern and American coconuts have the same weight")
        
    def test_inventory_add_coconut(self):
        '''
        Test inventory add_coconut
        Raise AttributeError if it passes a string
        '''
        self.assertRaises(AttributeError, self.inventory.add_coconut, "Bermuda")
     
    def test_inventory_total_weight(self):
        '''
        Test to ensure that total weight calculation is correct
        '''
        # 2 South Asians
        self.inventory.add_coconut(self.south_asian)
        self.inventory.add_coconut(self.south_asian)
        
        # 1 Middle Easter
        self.inventory.add_coconut(self.middle_eastern)
        
        # 3 American
        self.inventory.add_coconut(self.american)
        self.inventory.add_coconut(self.american)
        self.inventory.add_coconut(self.american)
        
        observed = self.inventory.total_weight()
        expected = (self.south_asian.coconut_weight * 2) + (self.american.coconut_weight * 3) + (self.middle_eastern.coconut_weight)
        
        self.assertEqual(observed, expected)
Пример #8
0
    def test_weight(self):
        """
        Ensures that given defined weights, the total_weight() method 
        returns the correct total weight.
        Add following coconut numbers:  South Asian=2, Middle Eastern=1, 
        American=3
        """
        basket = Inventory()
        drsim = SouthAsian()
        hadji = MiddleEastern()
        jonny = American()

        for n in range(2):
            basket.add_coconut(drsim)
        for n in range(1):
            basket.add_coconut(hadji)
        for n in range(3):
            basket.add_coconut(jonny)

        expected = 19.0
        result = basket.total_weight()
        self.assertEqual(result, expected, "total_weight() is wrong...")