Esempio n. 1
0
 def _test_repository_pushremove(self):
     '''
     Tests if the functions push and remove from the repository work
     '''
     repository = Repository()
     Repository.push(repository, "5", 0)
     Repository.push(repository, 2)        
     Repository.push(repository, True, 3)
     Repository.push(repository, 7.5)
     
     assert Repository.getList(repository) == ["5", 2, 7.5]
     
     Repository.remove(repository, 3)
     Repository.remove(repository, 1)
     
     assert Repository.getList(repository) == ["5", 7.5]
     
     Repository.remove(repository, 0)
     
     assert Repository.getList(repository) == [7.5]
     
     Repository.remove(repository, 0)
     Repository.remove(repository, 0)
     
     assert Repository.getList(repository) == []
Esempio n. 2
0
 def searchID(self, criteria, debug):
     '''
     Searches a student in the list based on their ID
     
     Parameters:
     criteria - the id of the student
     debug - used for debugging to check if command is detected
     '''
     pos = Controller.isDuplicate(self, criteria, "studentID")
     if pos == -1:
         raise DuplicateIDError
     else:
         print (Repository.getList(self._repository)[pos])
Esempio n. 3
0
 def printElements(self, elem_type, debug = None):
     '''
     Prints the elements in the list
     
     Parameters:
     elem_type - what type of elements should be printed
     debug - used only for testing
     '''
     print ("List of " + elem_type + ': ')
     lst = Repository.getList(self._repository)
     for i in range(len(lst)):
         if elem_type == "students" and isinstance(lst[i], Student) == True:
             print (str(lst[i]))
         elif elem_type == "grades" and isinstance(lst[i], Grade) == True:
             print (str(lst[i]))
         elif elem_type == "disciplines" and isinstance(lst[i], str) == True:
             print (' * ' + str(lst[i]))
     print ("---------------------")  
Esempio n. 4
0
 def isDuplicate(self, criteria, check_type):
     '''
     Check if there is a student with id = criteria
     
     Parameters:
     criteria - what to search in the list
     check_type - what type of elements need to be compared
     '''
     lst = Repository.getList(self._repository)
     if check_type == "studentID" and isinstance(criteria, int):
         for i in range(len(lst)):
             if isinstance(lst[i], Student) and lst[i].getID() == criteria:
                 return i
     
     '''
     Checks whether criteria is a discipline found in the list
     '''
     
     if check_type == "discipline" and isinstance(criteria, str):
         for i in range(len(lst)):
             if isinstance(lst[i], str) and lst[i] == criteria:
                 return i
                     
     return -1