Example #1
0
    def wrap(self, table, E, x, y):
        if x != E[0] and y != E[1] and abs(x - E[0]) != abs(y - E[1]):
            raise ValidError('Cannot wrap at ' + chr(ord(str(x)) + 16) +
                             str(y) + '!\n')

        if table[x][y] == '*':
            raise ValidError('Star crushing!')

        for a in range(min(x, E[0]), max(x, E[0])):
            if table[a][y] == '*':
                raise ValidError('Star crushing!')

        for a in range(min(y, E[1]), max(y, E[1])):
            if table[x][a] == '*':
                raise ValidError('Star crushing!')
 def validate(self, student):
     errors = ''
     if type(student.id) != int:
         errors += 'Wrong ID!\n'
     if type(student.name) != str or student.name == '':
         errors += 'Wrong name!\n'
     if type(student.group) != str or student.group == '':
         errors += 'Wrong group!\n'
     if errors != '':
         raise ValidError(errors)
Example #3
0
 def grade(self, studentId, laboratoryNo, val):
     grade = Grades(None, None, None, val)
     self.__validateGrades.validate(grade)
     student = Student(studentId, None, None)
     if student not in self.studentRepo.getAll():
         raise ValidError('The student does not exist!')
     for grade in self.gradeRepo.getAll(studentId):
         if grade.labNo == laboratoryNo:
             grade.value = val
             self.gradeRepo.update()
    def validate(self, sentence):
        errors = ''
        if len(sentence.words) < 1:
            errors += 'The sentence must conrain at least one word!\n'

        for word in sentence.words:
            if len(word) < 3:
                errors += 'Every word in the sentence must contain at least 3 letters!\n'

        if len(errors) != 0:
            raise ValidError(errors)
Example #5
0
 def validate_client(self, client):
     """
     this is the function which validates a client input
     it verifies the id,title,description,genre of the client
     """
     errors = ""
     if client.get_clientid() < 1:
         errors += "Invalid id!\n"
     if client.get_name() == "":
         errors += "Invalid name!\n"
     if len(errors) > 0:
         raise ValidError(errors)
Example #6
0
 def validate_movie(self, movie):
     """
     this is the function which validates a movie input
     it verifies the id,title,description,genre of a movie
     """
     errors = ""
     if movie.get_movieid() < 1:
         errors += "Invalid id!\n"
     if movie.get_title() == "":
         errors += "Invalid title!\n"
     if movie.get_description() == "":
         errors += "Invalid description!\n"
     if movie.get_genre() == "":
         errors += "Invalid genre!\n"
     if len(errors) > 0:
         raise ValidError(errors)
Example #7
0
 def validate_return(self, rent, l):
     self.__months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
     errors = ""
     if rent.get_rentalid() < 1:
         errors += "Invalid client id!\n"
     returned_date = rent.get_returned_date()
     if int(returned_date[0]) > int(
             self.__months[int(returned_date[1]) - 1]) or int(
                 returned_date[0]) <= 0:
         errors += "Invalid day rent!\n"
     if int(returned_date[1]) <= 0 or int(returned_date[1]) > 12:
         errors += "Invalid month rent!\n"
     returned_date = rent.get_returned_date()
     rented_date = rent.get_rented_date()
     if int(returned_date[1]) < int(rented_date[1]) or (
             int(returned_date[1]) == int(rented_date[1])
             and int(returned_date[0]) < int(rented_date[0])):
         errors += "Invalid date!\n"
     if len(errors) > 0:
         raise ValidError(errors)
Example #8
0
 def validate(point):
     if chr(ord(point.x)) < 'A' or chr(ord(point.x)) > 'F' or chr(
             ord(point.y)) < '0' or chr(ord(point.y)) > '6':
         raise ValidError('Point out of grid!')
Example #9
0
    def validate(p1, p2, p3):

        if not(p1.x == p2.x == p3.x and abs(ord(p1.y) - ord(p2.y)) == abs(ord(p2.y) - ord(p3.y)) == 1\
            or p1.y == p2.y == p3.y and abs(ord(p1.x) - ord(p2.x)) == abs(ord(p2.x) - ord(p3.x)) == 1):
            raise ValidError('Wrong shape!')
Example #10
0
 def fire(self, x, y):
     if x < 1 or x > 7 or y < 1 or y > 7:
         raise ValidError('Invalid Point!')
 def  validate(self, grade):
     errors = ''
     if grade.value < 0 or grade.value > 10:
         errors += 'Invalid grade!\n'
     if errors != '':
         raise ValidError(errors)
Example #12
0
 def validate_rent(self, rent, movies, clients):
     self.__months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
     errors = ""
     if rent.get_clientid() < 1:
         errors += "Invalid client id!\n"
     if rent.get_movieid() < 1:
         errors += "Invalid movie id!\n"
     if rent.get_rentalid() < 1:
         errors += "Invalid rental id!\n"
     rental_date = rent.get_rented_date()
     if int(rental_date[1]) <= 0 or int(rental_date[1]) > 12:
         errors += "Invalid month rent!\n"
     if len(errors) > 0:
         raise ValidError(errors)
     if int(rental_date[0]) > self.__months[int(rental_date[1]) - 1] or int(
             rental_date[0]) <= 0:
         errors += "Invalid day rent!\n"
     due_date = rent.get_due_date()
     if int(due_date[0]) > self.__months[int(due_date[1]) - 1] or int(
             due_date[0]) <= 0:
         errors += "Invalid day rent!\n"
     if int(due_date[1]) <= 0 or int(due_date[1]) > 12:
         errors += "Invalid month rent!\n"
     if int(rental_date[1]) > int(due_date[1]):
         errors += "Invalid date!\n"
     if int(rental_date[1]) == int(due_date[1]):
         if int(rental_date[0]) > int(due_date[0]):
             errors += "Invalid date!\n"
     if len(errors) > 0:
         raise ValidError(errors)
     else:
         for i in range(len(movies)):
             returned_date = movies[i].get_returned_date()
             if type(returned_date) == str:
                 due_date = movies[i].get_due_date()
                 rental_date = movies[i].get_rented_date()
                 rent_due = rent.get_due_date()
                 rent_rental = rent.get_rented_date()
                 if due_date[1] > rent_due[1]:
                     if rental_date[1] < rent_due[1]:
                         errors += "Invalid movie!\n"
                 if due_date[1] > rent_rental[1]:
                     if rental_date[1] < rent_rental[1]:
                         errors += "Invalid movie!\n"
                 if due_date[1] == rent_due[1] and due_date[0] >= rent_due[
                         0] and rental_date[1] <= rent_due[1]:
                     errors += "Invalid movie!\n"
                 if due_date[1] == rent_rental[
                         1] and due_date[0] >= rent_rental[
                             0] and rental_date[1] <= rent_rental[1]:
                     errors += "Invalid movie!\n"
             else:
                 returned_date = movies[i].get_returned_date()
                 rental_date = movies[i].get_rented_date()
                 rent_due = rent.get_due_date()
                 rent_rental = rent.get_rented_date()
                 if returned_date[1] > rent_due[1]:
                     if rental_date[1] < rent_due[1]:
                         errors += "Invalid movie!\n"
                 if returned_date[1] > rent_rental[1]:
                     if rental_date[1] < rent_rental[1]:
                         errors += "Invalid movie!\n"
                 if returned_date[1] == rent_due[1] and returned_date[
                         0] >= rent_due[0] and rental_date[1] <= rent_due[1]:
                     errors += "Invalid movie!\n"
                 if returned_date[1] == rent_rental[
                         1] and returned_date[0] >= rent_rental[
                             0] and rental_date[1] <= rent_rental[1]:
                     errors += "Invalid movie!\n"
         for i in range(len(clients)):
             returned_date = clients[i].get_returned_date()
             if type(returned_date) == list:
                 returned_date = clients[i].get_returned_date()
                 due_date = clients[i].get_due_date()
                 if due_date[1] < returned_date[1]:
                     errors += "Invalid client!\n"
                 if int(due_date[1]) == int(returned_date[1]) and int(
                         due_date[0]) < int(returned_date[0]):
                     errors += "Invalid client!\n"
         if len(errors) > 0:
             raise ValidError(errors)
Example #13
0
 def assignLab(self, studentId, labNo, labProblemNo):
     student = Student(studentId, None, None)
     if student not in self.studentRepo.getAll():
         raise ValidError('The student does not exist!')
     lab = Grades(studentId, labNo, labProblemNo, 0)
     self.gradeRepo.store(lab)