def _test_utility_isInt(self): ''' Tests if detecting a integer works ''' assert Utility.isInt(7) == True assert Utility.isInt("7") == False assert Utility.isInt([]) == False assert Utility.isInt(7.5) == False assert Utility.isInt([7]) == False assert Utility.isInt(True) == True assert Utility.isInt(None) == False assert Utility.isInt("") == False
def setGrade(self, new_gr): ''' Checks if the grade is an integer from 0 to 10 and sets it, otherwise it does nothing Parameters: new_gr - the grade received ''' if (Utility.isInt(new_gr) or Utility.isFloat(new_gr)) and new_gr >= 0 and new_gr <= 10.0: self._grade = new_gr elif Utility.isConvertableToFloat(new_gr) and float(new_gr) >= 0 and float(new_gr) <= 10.0: self._grade = float(new_gr) else: return False
def setStudentID(self, new_st_id): ''' Checks if the student ID is an integer and sets it, otherwise it does nothing Parameters: new_st_id - new student id ''' if Utility.isInt(new_st_id) == True and new_st_id > 0: self._studentID = new_st_id elif Utility.isConvertableToInt(new_st_id) == True and int(new_st_id) > 0: self._studentID = int(new_st_id) else: return False