コード例 #1
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)
コード例 #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_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")
コード例 #4
0
    def testInventoryWeight(self):
        """
        Gimme 2 South Asian, 1 Middle Eastern, and 3 American coconuts weighing 19 units
        Also check that adding invalid instance of Coconut raises an error
        """
        inv = Inventory()
        inv.addCoconut(self.southAsian)
        inv.addCoconut(self.southAsian)
        inv.addCoconut(self.middleEastern)
        inv.addCoconut(self.american)
        inv.addCoconut(self.american)
        inv.addCoconut(self.american)

        observed = inv.totalWeight()
        self.assertEqual(observed, 19.0)
        
        self.assertRaises(TypeError, inv.addCoconut, 'Dodecelsulfate')
コード例 #5
0
ファイル: test_coconuts.py プロジェクト: jmwoloso/Python_3
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
ファイル: test_coconuts.py プロジェクト: jmwoloso/Python_3
 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')
コード例 #7
0
ファイル: testCoconuts.py プロジェクト: kobaltkween/python3
 def setUp(self):
     """
     Create an inventory and coconuts to add to the inventory.
     """
     self.inv = Inventory()
     self.coco1 = Coconut("South Asian")
     self.coco2 = Coconut("American")
     self.coco3 = Coconut("Middle Eastern")
コード例 #8
0
ファイル: testCoconuts.py プロジェクト: kobaltkween/python3
class TestCoconuts(unittest.TestCase):

    def setUp(self):
        """
        Create an inventory and coconuts to add to the inventory.
        """
        self.inv = Inventory()
        self.coco1 = Coconut("South Asian")
        self.coco2 = Coconut("American")
        self.coco3 = Coconut("Middle Eastern")
    
    def testCoconuts(self):
        """
        Make sure each type of coconut has the right weight property
        """
        self.assertEqual(self.coco1.weight, 3, "South Asian coconuts should weigh 3")
        self.assertEqual(self.coco2.weight, 3.5, "American coconuts should weigh 3.5")
        self.assertEqual(self.coco3.weight, 2.5, "Middle Eastern coconuts should weigh 2.5")
        self.assertRaises(AttributeError, Coconut, "Pacific Island")
        
    def testAddCoconut(self):
        """
        Make sure that the addCoconut method of the Inventory class raises an exception when trying to add something other than coconuts.
        """
        self.assertRaises(AttributeError, self.inv.addCoconut, "foobar")
        
    def testTotalWeight(self):
        """
        Verify that the addCoconut method adds coconuts to the inventory properly and that Inventory's totalWeight method adds properly.
        """
        self.inv.addCoconut(self.coco1, 2)
        self.inv.addCoconut(self.coco3)
        self.inv.addCoconut(self.coco2, 3)
        self.assertEqual(self.inv.totalWeight(), 19, "The total weight of the inventoray should now by 19.")
コード例 #9
0
ファイル: test_coconuts.py プロジェクト: AquaGirl/Python3
    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())
コード例 #10
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)
コード例 #11
0
ファイル: test_coconuts.py プロジェクト: jmwoloso/Python_3
 def test_total_weight(self):
     """
     Tests that the sum of a specified number of coconuts of each type
     returned matches the expected total
     """
     varieties = [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(),
                      'Total weight: 19.0',
                      "Your total weight is wrong")
コード例 #12
0
ファイル: test_coconuts.py プロジェクト: jmwoloso/Python_3
 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")
コード例 #13
0
ファイル: test_coconuts.py プロジェクト: deepbsd/OST_Python
    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...")
コード例 #14
0
 def test_inventory_attribute(self):
     """
     Test ensuring if a string object is passed to the Inventory.add_coconut method, an AttributeError is thrown. 
     """
     inv = Inventory()
     self.assertRaises(AttributeError, inv.add_coconut, "South Asian")
コード例 #15
0
 def test_string_error(self):
     inv = Inventory()
     self.assertRaises(AttributeError, inv.add_coconut, 'american')
コード例 #16
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())
コード例 #17
0
 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()