Ejemplo n.º 1
0
 def test_Negative_BudgetItem(self):
     """
     This method tests using negative numbers in the constructor.
     Numbers are by defeault set to zero, therefore total will be zero
     """
     item = BudgetItem("Negative", "Negative Description", -1, 5)
     self.assertEqual(0, item.total() )
Ejemplo n.º 2
0
 def test_BudgetGroup_Empty_Adding(self):
     """
     The method tests if a BudgetItem can be added correctly if the
     BudgetGroup was initially empty.
     """
     budgetgroup = self.construct_Empty_BudgetGroup()
     self.assertIsNone(budgetgroup.add(BudgetItem()))
Ejemplo n.º 3
0
 def construct_Single_Item_BudgetGroup(self):
     """
     The method constructs a BudgetGroup object containing one BudgetItem.
     """
     group = BudgetGroup("BGTestName", "BGTestDescription")
     group.add (BudgetItem("ItemName", "ItemDescription", 5, 2))
     return group
Ejemplo n.º 4
0
 def test_BudgetGroup_Empty_Deleting(self):
     """
     The method tests if BudgetGroup returns the correct output if an object
     that doesnt exist in the set is attempted to be removed from it.
     """
     budgetgroup = self.construct_Empty_BudgetGroup()
     self.assertEqual("Not in set.", budgetgroup.delete(BudgetItem()))
Ejemplo n.º 5
0
 def test_BudgetGroup_Multiple_Cost(self):
     """
     The method tests if the costs are calculated correctly with more
     than one BudgetItem in it.
     """
     budgetgroup = self.construct_Single_Item_BudgetGroup()
     budgetgroup.add(BudgetItem("SecondName", "SecondDescription", 10, 3))
     self.assertEqual(40, budgetgroup.subtotal())
Ejemplo n.º 6
0
 def test_BudgetGroup_Multiple_Strings(self):
     """
     The method checks the object prints out correctly
     with BudgetItems in it.
     """
     budgetgroup = self.construct_Single_Item_BudgetGroup()
     budgetgroup.add(BudgetItem("SecondName", "SecondDescription", 10, 3))
     self.assertEqual("BGTestName: BGTestDescription\n\t\t"+
                      "ItemName: ItemDescription\n\t\t"+
                      "SecondName: SecondDescription", str(budgetgroup))
Ejemplo n.º 7
0
    def construct_Multiple_Project(self):
        """
        This method constucts a Project with two of each
        of the objects from the hierarchy and returns it.
        """ 
        project = Project("PojectTestName", "ProjectTestDescription")
        groupone = BudgetGroup("BGTestName", "BGTestDescription")
        grouptwo = BudgetGroup("BGTestNameTwo", "BG Test Description Two")
        itemone = BudgetItem("BITestName", "BITestDescription", 2, 5)
        itemtwo = BudgetItem("BITestNameTwo", "BI Test Description Two", 10, 3)
        itemthree = BudgetItem("BITestNameThree", "BI Test Description Three", 5, 4)
        itemfour = BudgetItem("BITestNameFour", "BI Test Description Four", 2, 5)
                        
        groupone.add(itemone)
        groupone.add(itemtwo)
        grouptwo.add(itemthree)
        grouptwo.add(itemfour)
                        
        project.add(groupone)
        project.add(grouptwo)

        return project
Ejemplo n.º 8
0
    def construct_Single_Project(self):
        """
        This method constucts a Project with one of each
        of the objects from the hierarchy and returns it.
        """ 
        project = Project("PojectTestName", "ProjectTestDescription")
        groupone = BudgetGroup("BGTestName", "BGTestDescription")
        itemone = BudgetItem("BITestName", "BITestDescription", 2, 5)

        groupone.add(itemone)              
        project.add(groupone)

        return project
Ejemplo n.º 9
0
 def construct_BudgetItem(self):
     """The method returns a BudgetITem object with some values."""
     return BudgetItem("BITestName", "BITestDescription", 2, 5)
Ejemplo n.º 10
0
 def test_BudgetGroup_Single_Deleting(self):
     """The method tests deleting an object from the set."""
     budgetgroup = self.construct_Single_Item_BudgetGroup()
     self.assertEqual("Confirmed.", budgetgroup.delete
                      (BudgetItem("ItemName", "ItemDescription", 5, 2)))
Ejemplo n.º 11
0
def addData():
    # Enter data for constructing the objects.
    name = raw_input("\nEnter Project Name:\n")
    desc = raw_input("\nEnter Project Description:\n")

    # Instantiate a Project
    project = Project(name, desc)

    # Loop while adding groups and items
    while True:
        # The user has to enter "0" to stop the loop
        if "0" == raw_input ("\nEnter 0 to stop adding BudgetGroups: "):
                break
        
        name = raw_input("\nEnter BudgetGroup Name:\n")
        desc = raw_input("\nEnter BudgetGroup Description:\n")

        # Instantiate a BudgetGroup object
        group = BudgetGroup(name, desc)

        # Loop and add multiple Items
        while True:
            # The user has to enter "0" to stop the loop
            if "0" == raw_input ("\nEnter 0 to stop adding BudgetItems: "):
                break
            
            name = raw_input("\nEnter BudgetItem Name:\n")
            desc = raw_input("\nEnter BudgetItem Description:\n")
            
            # Ensure quantities are not negative or letters.
            # If the input is letters catch the error and set quantity to
            # -1 so it goes into the loop.
            try:
                quan = int(raw_input("\nEnter BudgetItem Quantity:\n") )
            except ValueError:
                quan = -1             
            while quan < 0:
                try:
                    quan = int(raw_input("\nQuantity can't be negative or letters. "+
                                     "Enter BudgetItem Quantity:\n"))
                except ValueError:
                    quan = -1
                    
            # Ensure rates are not negative.
            # If the input is letters catch the error and set rate to
            # -1 so it goes into the loop.
            try:
                rate = int(raw_input("\nEnter BudgetItem Rate:\n"))
            except ValueError:
                rate = -1
            while rate < 0:
                try:
                    rate = int(raw_input("\nRate can't be negative or letters. "+
                                     "Enter BudgetItem Rate:\n"))
                except ValueError:
                    rate = -1

            # Instantiate a BudgetItem.
            item = BudgetItem (name, desc, quan, rate)
            group.add(item)
            
        project.add(group)
        

    # Return the Project will all the objects in it
    return project