def addGrade(self, cmd, debug = None): ''' Checks if using some parameteres a grade can be added in the repository Parameters: cmd - contains the parts which compose a grade debug - used only for testing ''' parameters = Utility.splitParameters(cmd) if parameters == None: raise ValueError if len(parameters) == 4 and len(parameters[0]) > 0 and len(parameters[1]) == 1 and len(parameters[2]) == 1 and len(parameters[3]) > 0: disc = parameters[0][0] for i in range(1, len(parameters[0])): disc = disc + ' ' + parameters[0][i] name = parameters[3][0] for i in range(1, len(parameters[3])): name = name + ' ' + parameters[0][i] if Controller.isDuplicate(self, disc, "discipline") != -1 and Utility.isConvertableToInt(parameters[1][0]) and Controller.isDuplicate(self, int(parameters[1][0]), "studentID") != -1 and parameters[2][0]: Repository.push(self._repository, Grade(disc, parameters[1][0], name, parameters[2][0])) return elif Controller.isDuplicate(self, disc, "discipline") == -1: raise DuplicateDisciplineError elif Controller.isDuplicate(self, int(parameters[1][0]), "studentID") == -1: raise DuplicateIDError raise ValueError
def _test_utility_splitParameters(self): ''' Tests if splitting parameters works ''' assert Utility.splitParameters(["test", ",", "test2"]) == [["test"], ["test2"]] assert Utility.splitParameters([",", ","]) == [[], []] assert Utility.splitParameters([",", "get"]) == [[], ["get"]] assert Utility.splitParameters(["FP", ",", "1", ",", "5.5", ",", "Arthur"]) == [["FP"], ["1"], ["5.5"], ["Arthur"]] assert Utility.splitParameters([5]) == None
def _test_utility_isFloat(self): ''' Tests if detecting a float works (int is also considered float) ''' assert Utility.isFloat(7.5) == True assert Utility.isFloat(7) == True assert Utility.isFloat("7") == False assert Utility.isFloat(True) == True assert Utility.isFloat(None) == 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
def _test_utility_isConvertableToFloat(self): ''' Tests if convertability to float works ''' assert Utility.isConvertableToFloat("7") == True assert Utility.isConvertableToFloat("7.5") == True assert Utility.isConvertableToFloat("asdas") == False assert Utility.isConvertableToFloat("7.57.5") == False assert Utility.isConvertableToFloat([]) == False assert Utility.isConvertableToFloat(7) == True assert Utility.isConvertableToFloat(7.5) == True assert Utility.isConvertableToFloat("7.") == False
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 setTeacher(self, new_teach): ''' Checks it the teacher's name is a string and sets it, otherwise it does nothing Parameters: new_teach - name of the teacher ''' if Utility.isString(new_teach): self._teacher = new_teach else: return False
def setDiscipline(self, new_disc): ''' Checks if the new discipline is a string and sets it, otherwise it does nothing Parameters: new_disc - discipline ''' if Utility.isString(new_disc) == True: self._discipline = new_disc else: return False
def _test_utility_isString(self): ''' Tests if detecting a string works ''' assert Utility.isString("john") == True assert Utility.isString(1) == False assert Utility.isString("") == True assert Utility.isString(" a ") == True assert Utility.isString([]) == False assert Utility.isString(7.5) == False assert Utility.isString(True) == False
def _test_utility_isConvertableToInt(self): ''' Tests if convertability to int works ''' assert Utility.isConvertableToInt("7") == True assert Utility.isConvertableToInt("7.5") == False assert Utility.isConvertableToInt(7) == True assert Utility.isConvertableToInt("D6B8") == False assert Utility.isConvertableToInt("7.5.5") == False assert Utility.isConvertableToInt([]) == False
def searchDiscipline(self, cmd): ''' Searches for a discipline in the list Parameters: cmd - the name of the discipline ''' parameters = Utility.splitParameters(cmd) if len(parameters) > 0 and len(parameters[0]) > 1: disc = parameters[0][0] for i in range(1, len(parameters[0])): disc = disc + ' ' + parameters[0][i] pos = Controller.isDuplicate(self, disc, "discipline") if pos == -1: raise DuplicateDisciplineError print ("Discipline found!") raise ValueError
def addStudent(self, cmd): ''' Checks if using some parameters a student can be added in the repository Parameters: cmd - contains the parts which compose a student debug - used only for testing ''' parameters = Utility.splitParameters(cmd) if parameters == None: raise ValueError if len(parameters) == 1 and len(parameters[0]) > 0: name = parameters[0][0] for i in range(1, len(parameters[0])): name = name + ' ' + parameters[0][i] Repository.push(self._repository, Student(name, Controller.getID(self))) return raise ValueError
def addDiscipline(self, cmd, debug = None): ''' Checks if using some parameters a discipline can be added in the repository Parameters: cmd - contains the parts which compose a discipline debug - used only for testing ''' parameters = Utility.splitParameters(cmd) if parameters == None: raise ValueError if len(parameters) == 1 and len(parameters[0]) > 0: disc = parameters[0][0] for i in range(1, len(parameters[0])): disc = disc + ' ' + parameters[0][i] if Controller.isDuplicate(self, disc, "discipline") == -1: Repository.push(self._repository, disc) return else: raise DuplicateDisciplineError raise ValueError