def addRecord(self, newID, newGender, newAge, newSales, newBMI, newIncome, autoID, overwrite): typeCheckStringERR(newID) preppedID = None invalidID = False origRec = None insertPos = None overwriteSignal = 0 # will become 1 if overwriting will be used try: preppedID = self._prepID(newID) origRec, insertPos = self._prot_findRecord(preppedID) except InvalidIDException: invalidID = True if origRec is not None and overwrite: overwriteSignal = 1 elif (origRec is not None or invalidID) and autoID: preppedID, insertPos = self._autoID() # doNotUse, insertPos = self._prot_findRecord(preppedID) elif origRec is not None: raise DuplicateIDException() elif invalidID: raise InvalidIDException() newRec = Record(preppedID, newGender) self._allMyRecords[insertPos:insertPos + overwriteSignal] = [newRec] newRec.setAge(newAge) newRec.setSales(newSales) newRec.setBMI(newBMI) newRec.setIncome(newIncome)
def test_NoChangeAge02(self): """ Expect age to remain after attempting to set it to 40.5 (decimal) """ expAge = 41 rec = Record(None, "F") """Default values proven in other test""" rec.setAge(expAge) rec.setAge(40.5) self.assertEqual(expAge, rec.getAge())
def test_NoChangeAge01(self): """ Expect age to remain after attempting to set it to 100 (over the limit) """ expAge = 99 rec = Record(None, "M") """Default values proven in other test""" rec.setAge(expAge) rec.setAge(100) self.assertEqual(expAge, rec.getAge())
def test_NoChangeAge03(self): """ Expect age to remain after attempting to set it to "A" String can be used for the method, but "A" represents no number """ expAge = 30 ageStr = str(30) rec = Record(None, "F") """Default values proven in other test""" rec.setAge(ageStr) rec.setAge("A") self.assertEqual(expAge, rec.getAge())