Beispiel #1
0
    def setUp(self):
        self.repo = StudentRepository()

        s1 = Student(1, "1")
        s2 = Student(2, "2")

        self.repo.add(s1)
        self.repo.add(s2)
Beispiel #2
0
    def test_student_add(self):
        studentToTest = Student(1, "Michael")

        self.studentController.add(1, "Michael")
        self.assertEqual(
            self.studentController.get_repository().get_list()[2].get_ID(),
            studentToTest.get_ID())
        self.assertEqual(
            self.studentController.get_repository().get_list()[2].get_name(),
            studentToTest.get_name())
def testStudentController():
    stuRepo = StudentRepository()
    graRepo = GradeRepository()
    undoCtrl = UndoController()
    ctrl = StudentController(stuRepo, graRepo, undoCtrl)

    s1 = Student(1, "Vasilica")
    s2 = Student(1, "Gheorghidiu")

    assert len(ctrl) == 0

    ctrl.addStudent(s1)
    assert len(ctrl) == 1
    assert ctrl.findStudentByName("Vasilica") == [s1]
    assert ctrl.findStudentByName("John") == []

    try:
        ctrl.addStudent(s1)
        assert False
    except StudentException:
        assert True

    try:
        ctrl.addStudent(s2)
        assert False
    except StudentException:
        assert True

    s2 = Student(2, "Gheorghidiu")
    ctrl.addStudent(s2)
    assert len(ctrl) == 2
    assert ctrl.findStudentByName("Vasilica") == [s1]
    assert ctrl.findStudentByName("Gheorghidiu") == [s2]

    ctrl.updateStudent(2, "Johnny Bravo")

    assert len(ctrl) == 2
    ctrl.removeStudent(1)
    assert len(ctrl) == 1
    assert ctrl.findStudentByName("Johnny Bravo") == [s2]
    assert ctrl.findStudentByName("Vasilica") == []

    try:
        ctrl.removeStudent(1)
        assert False
    except StudentException:
        assert True

    ctrl.removeStudent(2)
    assert len(ctrl) == 0
Beispiel #4
0
    def testStudentController(self):
        stuRepo = StudentRepository()
        graRepo = GradeRepository()
        undoCtrl = UndoController()
        disRepo = DisciplineRepository()
        ctrl = StudentController(stuRepo, graRepo, disRepo, undoCtrl)

        s1 = Student(1, "Putin")
        s2 = Student(1, "Boruto")

        assert len(ctrl) == 0

        ctrl.addStudent(s1)
        assert len(ctrl) == 1
        assert ctrl.searchStudentID(1) == s1

        try:
            ctrl.addStudent(s1)
            assert False
        except StudentException:
            assert True

        try:
            ctrl.addStudent(s2)
            assert False
        except StudentException:
            assert True

        s2 = Student(2, "Naruse")
        ctrl.addStudent(s2)
        assert len(ctrl) == 2
        assert ctrl.searchStringinNameStudent("TIN") == [s1]
        assert ctrl.searchStringinNameStudent("rus") == [s2]

        ctrl.updateStudent(1, "Hagi")

        assert len(ctrl) == 2
        ctrl.removeStudent(1)
        assert len(ctrl) == 1
        assert ctrl.searchStudentID(1) == None
        assert ctrl.searchStudentID(2) == s2

        try:
            ctrl.removeStudent(1)
            assert False
        except StudentException:
            assert True

        ctrl.removeStudent(2)
        assert len(ctrl) == 0
Beispiel #5
0
    def testStudentRepository(self):
        repo = StudentRepository()

        s1 = Student(1, "Putin")
        s2 = Student(1, "Chandler")

        assert len(repo) == 0

        repo.add(s1)
        assert len(repo) == 1
        assert repo.findBysID(1) == s1

        assert repo.searchStringinName("ut") == [s1]
        assert repo.searchStringinName("ta") == []

        try:
            repo.add(s1)
            assert False
        except StudentException:
            assert True

        try:
            repo.add(s2)
            assert False
        except StudentException:
            assert True

        s2 = Student(2, "Chandler")
        repo.add(s2)
        assert len(repo) == 2
        assert repo.findBysID(1) == s1
        assert repo.findBysID(2) == s2

        repo.update(2, "Nonaka")

        repo.remove(1)
        assert len(repo) == 1
        assert repo.findBysID(2) == s2
        assert repo.findBysID(1) == None

        try:
            repo.remove(1)
            assert False
        except StudentException:
            assert True

        repo.remove(2)
        assert len(repo) == 0
    def testGradeRepository(self):

        repo = GradeRepository()
        disrepo = DisciplineRepository()
        sturepo = StudentRepository()

        stu = Student(1, "Putin")
        dis = Discipline(1, "Maths")

        sturepo.add(stu)
        disrepo.add(dis)

        assert len(repo) == 0

        gra1 = Grade(1, 1, 10)

        repo.addGrade(gra1, sturepo, disrepo)

        assert len(repo) == 1

        repo.removeGrade(1, 1)

        assert len(repo) == 0

        try:
            repo.removeGrade(1, 1)
            assert False
        except GradeException:
            assert True
def listInit(studentList, assignmentList, gradeList):
    firstName = [
        "James ", "John ", "Robert ", "Michael ", "William ", "Mary ",
        "Patricia ", "Jennifer ", "Linda ", "Elizabeth "
    ]
    lastName = [
        "Smith", "Johnson", "Williams", "Brown", "Jonrs", "Garcia", "Miller",
        "Davis", "Rodriguez", "Martinez"
    ]
    group = [511, 512, 513, 514, 515, 516]
    for i in range(100):
        studentList.addObject(
            Student(i + 1,
                    choice(firstName) + choice(lastName), choice(group)))
    desc1 = [
        "Copper ", "Nitric Acid ", "Potassium Iodide ", "Hydrogen Peroxide ",
        "Alkali Metal "
    ]
    desc2 = [
        "in Water", "reaction", "coloring Fire", "dehydration", "and thermite"
    ]
    deadline = [3, 4, 5, 6]
    for i in range(100):
        assignmentList.addObject(
            Assignment(i + 1,
                       choice(desc1) + choice(desc2), choice(deadline)))
    nr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    for i in range(100):
        gradeList.addObject(Grade(1 + i, 100 - i, choice(nr)))
    def testGradeController(self):

        graRepo = GradeRepository()
        disRepo = DisciplineRepository()
        stuRepo = StudentRepository()
        undoCtrl = UndoController()
        ctrl = GradeController(graRepo, disRepo, stuRepo, undoCtrl)

        assert len(ctrl) == 0
        grade = Grade(1, 1, 9)

        try:
            ctrl.addGrade(grade)
            assert False
        except (DisciplineException, StudentException):
            assert True

        d = Discipline(1, "Japanese")
        s = Student(1, "Naruto")
        disRepo.add(d)
        stuRepo.add(s)

        ctrl.addGrade(grade)

        assert len(ctrl) == 1
Beispiel #9
0
    def testFindByID(self):
        s = self.repo.findByID(1)
        self.assertEqual(s, Student(1, "1"))

        s = self.repo.findByID(169)
        self.assertEqual(s, None)
        self.assertTrue(s == None)
Beispiel #10
0
def testStudentRepository():
    repo = StudentRepository()

    s1 = Student(1, "Vasilica")
    s2 = Student(1, "Gheorghidiu")

    assert len(repo) == 0

    repo.add(s1)
    assert len(repo) == 1
    assert repo.findByID(1) == s1

    try:
        repo.add(s1)
        assert False
    except StudentException:
        assert True

    try:
        repo.add(s2)
        assert False
    except StudentException:
        assert True

    s2 = Student(2, "Gheorghidiu")
    repo.add(s2)
    assert len(repo) == 2
    assert repo.findByID(1) == s1
    assert repo.findByID(2) == s2

    repo.update(2, "Johnny Bravo")

    assert len(repo) == 2
    repo.remove(1)
    assert len(repo) == 1
    assert repo.findByID(2) == s2
    assert repo.findByID(1) == None

    try:
        repo.remove(1)
        assert False
    except StudentException:
        assert True

    repo.remove(2)
    assert len(repo) == 0
    def load_from_text_file(self):
        """
        Description: loads any existing items inside the text_file into the list
        """

        with open(self.__studentFile, "r+") as openStudentFile:
            for line in openStudentFile:
                student = re.findall('"([^"]*)"', line)
                super().add(Student(int(student[0]), student[1]))
Beispiel #12
0
 def addStudent(self,id,name,group):
     vs = Validator(id,name,group)
     vs.studentValidator()
     if self.checkID(id):
         raise myException("This id is used by another student! \n")
     undo = FunctionCall(self.removeStudent,id)
     redo = FunctionCall(self.addStudent,id, name, group)
     oper = Operation(undo,redo)
     self._undoController.addOperation(oper)
     self._studentList.addObject(Student(id,name,group))
Beispiel #13
0
    def testStatisticsController(self):

        graRepo = GradeRepository()
        stuRepo = StudentRepository()
        disRepo = DisciplineRepository()

        disRepo.add(Discipline(1, "Dragons Language"))
        disRepo.add(Discipline(2, "How to draw anime"))
        disRepo.add(Discipline(3, "Japanese"))

        stuRepo.add(Student(1, "Putin"))
        stuRepo.add(Student(2, "Sheldon Cooper"))
        stuRepo.add(Student(3, "Nietzsche"))
        stuRepo.add(Student(4, "Mio Naruse"))

        graRepo.addGrade(Grade(1, 1, 9.9), stuRepo, disRepo)
        graRepo.addGrade(Grade(2, 1, 4.8), stuRepo, disRepo)
        graRepo.addGrade(Grade(3, 1, 5.7), stuRepo, disRepo)
        graRepo.addGrade(Grade(2, 2, 9.0), stuRepo, disRepo)
        graRepo.addGrade(Grade(1, 3, 6.0), stuRepo, disRepo)
        graRepo.addGrade(Grade(2, 3, 7.3), stuRepo, disRepo)
        graRepo.addGrade(Grade(3, 3, 4.2), stuRepo, disRepo)
        graRepo.addGrade(Grade(3, 3, 7.9), stuRepo, disRepo)

        ctrl = StatisticsController(stuRepo, disRepo, graRepo)

        assert ctrl.byDisciplineAlphabetically(3) == [[3, 'Nietzsche'],
                                                      [1, 'Putin']]
        assert ctrl.byDisciplineAlphabetically(2) == [[3, 'Nietzsche'],
                                                      [1, 'Putin'],
                                                      [2, 'Sheldon Cooper']]
        assert ctrl.failingStudents() == [[1, 'Putin']]
        assert ctrl.topStudents() == [[9.0, 2, 'Sheldon Cooper'],
                                      [6.8, 1, 'Putin'],
                                      [6.45, 3, 'Nietzsche']]
        assert ctrl.topDiscipline() == [[7.95, 1, 'Dragons Language'],
                                        [
                                            7.033333333333334, 2,
                                            'How to draw anime'
                                        ], [5.933333333333334, 3, 'Japanese']]
Beispiel #14
0
    def __addStudentMenu(self):
        """
        adds a Student to the list
        Input: none
        Output: a new Student is read and added (assuming there is no student with the same ID already)
        """
        ID = UI.readPositiveInteger("Please enter the student ID: ")
        name = input("Please enter the student name: ")

        try:
            stu = Student(ID, name)
            self.__stuCtrl.addStudent(stu)
        except StudentException as ex:
            print(ex)
Beispiel #15
0
    def __addStudentMenu(self):
        '''
        adds a Student to the register
        Input: -
        Output: a new Student is read and added (if there is no other Student with the same name)
        '''
        ID = UI.readPositiveInteger("Please enter the Student ID: ")
        name = input("Please enter the Student name: ")

        try:
            stu = Student(ID, name)
            self.__stuCtrl.addStudent(stu)
        except StudentException as ex:
            print(ex)
 def loadFromFile(self):
     try:
         f = open(self.__file, 'r')
     except IOError:
         return
     line = f.readline().strip()
     rez = []
     while line != "":
         list = line.split(",")
         student = Student(list[0], list[1])
         rez.append(student)
         line = f.readline().strip()
     f.close()
     return rez
Beispiel #17
0
class StudentDomainTestCase(unittest.TestCase):
    '''
    unit test for StudentDomain
    '''
    def setUp(self):
        self.stu = Student(1, "John")
    
    def testGetters(self):
        self.assertEqual(self.stu.getID(), 1)
        self.assertEqual(self.stu.getName(), "John")
        
    def testSetters(self):
        self.stu.setID(2)
        self.stu.setName("Mike")
        
        self.assertEqual(self.stu.getID(), 2)
        self.assertEqual(self.stu.getName(), "Mike")
 def _loadFromFile(self):
     '''
     loads information from the file
     Input: -
     Output: loaded information
     '''
     try:
         f = open(self._fName, "r")
     except IOError:
         print("de")
         return
     line = f.readline().strip()
     while line != "":
         t = line.split(";")
         stu = Student(int(t[0]), t[1])
         self.add(stu)
         line = f.readline().strip()
     f.close()
Beispiel #19
0
 def addS (self, id, name, group):
     s = Student(id, name, group)
     self.__rep.addStudent(s)
     return s
     
Beispiel #20
0
    repoGrade = FileGradeRepository()

else:
    repoDiscipline = DisciplineRepository()
    repoStudent = StudentRepository()
    repoGrade = GradeRepository()
    
    # add initial data
    repoDiscipline.add(Discipline("Algebra", "Crivei"))
    repoDiscipline.add(Discipline("Analysis", "no ideea"))
    repoDiscipline.add(Discipline("Computational Logic", "Lupea"))
    repoDiscipline.add(Discipline("Computational Systems Architecture", "Vancea"))
    repoDiscipline.add(Discipline("Fundamentals of Programming", "Arthur"))
    repoDiscipline.add(Discipline("Communication and Personal Development in Computer Science", "Motogna"))
    
    repoStudent.add(Student(1, "Harap-Alb"))
    repoStudent.add(Student(2, "Bestia"))
    repoStudent.add(Student(3, "Luceafarul"))
    repoStudent.add(Student(4, "Afrodita"))
    repoStudent.add(Student(5, "Shrek"))
    repoStudent.add(Student(6, "Bula"))
    
    repoGrade.addStudentToDiscipline("Algebra", 1)
    repoGrade.addStudentToDiscipline("Analysis", 1)
    repoGrade.addStudentToDiscipline("Computational Logic", 1)
    repoGrade.addStudentToDiscipline("Computational Systems Architecture", 1)
    repoGrade.addStudentToDiscipline("Fundamentals of Programming", 1)
    repoGrade.addStudentToDiscipline("Communication and Personal Development in Computer Science", 1)
    repoGrade.addStudentToDiscipline("Algebra", 2)
    repoGrade.addStudentToDiscipline("Analysis", 2)
    repoGrade.addStudentToDiscipline("Computational Logic", 2)
Beispiel #21
0
 def testUpdate(self):
     upS = Student(2, "8")
     self.repo.update(2, "8")
     s = self.repo.findByID(2)
     self.assertEqual(s, upS)
Beispiel #22
0
    def testAdd(self):
        s = Student(3, "3")
        self.repo.add(s)
        self.assertEqual(len(self.repo), 3)

        self.assertRaises(StudentException, self.repo.add, s)
Beispiel #23
0
def testGradeController():
    graRepo = GradeRepository()
    disRepo = DisciplineRepository()
    stuRepo = StudentRepository()
    undoCtrl = UndoController()
    ctrl = GradeController(graRepo, disRepo, stuRepo, undoCtrl)

    assert len(ctrl) == 0

    try:
        ctrl.addStudentToDiscipline("maths", 1)
        assert False
    except (DisciplineException, StudentException):
        assert True

    try:
        ctrl.updateGrade("maths", 1, 0)
        assert False
    except (DisciplineException, StudentException):
        assert True

    try:
        ctrl.removeStudentFromDiscipline("maths", 1)
        assert False
    except (DisciplineException, StudentException):
        assert True

    d1 = Discipline("maths", "Andrea")
    disRepo.add(d1)
    assert disRepo.findByName("maths") == d1
    s1 = Student(1, "Harap-Alb")
    stuRepo.add(s1)
    assert stuRepo.findByID(1) == s1

    ctrl.addStudentToDiscipline("maths", 1)

    assert len(ctrl) == 1

    try:
        ctrl.addStudentToDiscipline("maths", 1)
        assert False
    except GradeException:
        assert True

    try:
        ctrl.updateGrade("maths", 8, 10)
        assert False
    except (GradeException, DisciplineException, StudentException):
        assert True

    ctrl.updateGrade("maths", 1, 10)
    assert len(ctrl) == 1

    ctrl.removeStudentFromDiscipline("maths", 1)
    assert len(ctrl) == 0

    try:
        ctrl.removeStudentFromDiscipline("maths", 1)
        assert False
    except GradeException:
        assert True
Beispiel #24
0
repoDiscipline.add(Discipline(2, "Japanese"))
repoDiscipline.add(Discipline(3, "Philosophy"))
repoDiscipline.add(Discipline(4, "Anime"))
repoDiscipline.add(Discipline(5, "Algebra"))
repoDiscipline.add(Discipline(6, "Introduction to Economics"))
repoDiscipline.add(Discipline(7, "Mathematical Analysis"))
repoDiscipline.add(Discipline(8, "Football"))
repoDiscipline.add(Discipline(9, "Table Tennis"))
repoDiscipline.add(Discipline(10, "Tennis"))
repoDiscipline.add(Discipline(11, "Introduction to Algorithms"))
repoDiscipline.add(Discipline(12, "Dragons Language"))
repoDiscipline.add(
    Discipline(13, "Introduction to How not to be a Social Outcast"))
repoDiscipline.add(Discipline(14, "Game Theory"))

repoStudent.add(Student(1, "Mio Naruse"))
repoStudent.add(Student(2, "Sheldon Cooper"))
repoStudent.add(Student(3, "Joey Tribbiani"))
repoStudent.add(Student(4, "Monica Bing"))
repoStudent.add(Student(5, "Chandler Bing"))
repoStudent.add(Student(6, "Natsu Dragneel"))
repoStudent.add(Student(7, "Akeno Himejima"))
repoStudent.add(Student(8, "Donald Trump"))
repoStudent.add(Student(9, "Friedrich Nietzsche"))
repoStudent.add(Student(10, "Immanuel Kant"))
repoStudent.add(Student(11, "Emmanuele Macron"))
repoStudent.add(Student(12, "Aine Chidorigafuchi"))
repoStudent.add(Student(13, "Sterling Archer"))
repoStudent.add(Student(14, "Kylian Mbappe Lottin"))
repoStudent.add(Student(15, "Ross Barkley"))
repoStudent.add(Student(16, "Adam Smith"))
Beispiel #25
0
from Repositories.Repository import GenericRepository
from Repositories.RentalRepository import RentalRepository
from Controller.StudentController import StudentController
from Controller.AssignmentController import AssignmentController
from Controller.RentalController import RentalController
from UI.Console import Console
from Domain.Student import Student
from Domain.Assignment import Assignment
from Repositories.StudentRepository import StudentRepository
from Repositories.AssignmentsRepository import AssignmentRepository
from Controller.UndoController import UndoController
from Domain.Rental import Rental
from Domain.RentalDTO import RentalDTO

repo_students = StudentRepository()
repo_students.add(Student("1", "student1","100"))
repo_students.add(Student("2", "student2","200"))
repo_students.add(Student("3", "student3","300"))

repo_assignments = AssignmentRepository()
repo_assignments.add(Assignment("1", "car1"))
repo_assignments.add(Assignment("2", "car2"))
repo_assignments.add(Assignment("3", "car3"))

repo_rentals = RentalRepository()
repo_rentals.add(RentalDTO("1", "1", 1))
repo_rentals.add(RentalDTO("2", "1", 2))
repo_rentals.add(RentalDTO("3", "1", 3))

ctrl_undo = UndoController()
ctrl_students = StudentController(ctrl_undo, repo_rentals, repo_students)
Beispiel #26
0
 def setUp(self):
     self.stu = Student(1, "John")