class TestCaseStudentRepositoryClass(unittest.TestCase): def setUp(self): self.st1 = Student("Ion", 21, 1) self.st2 = Student("Ana", 32, 2) self.st3 = Student("Mircea", 14, 3) self.st_repo = StudentInMemoryRepository() self.st_repo.addStudent(self.st1) self.st_repo.addStudent(self.st2) self.st_repo.addStudent(self.st3) def testAddStudent(self): self.st_repo.addStudent(Student("Danut", 22, 6)) self.assertEqual(self.st_repo.getNumberOfStudents(), 4) self.st_repo.addStudent(Student("Mircea", 56, 9)) self.assertEqual(self.st_repo.getNumberOfStudents(), 5) def testRemoveStudent(self): self.st_repo.removeStudent(self.st1.getId()) self.assertEqual(self.st_repo.getNumberOfStudents(), 2) self.st_repo.removeStudent(self.st2.getId()) self.assertEqual(self.st_repo.getNumberOfStudents(), 1) def testGetStudentById(self): self.assertEqual(self.st_repo.getStudentById(self.st1.getId()), self.st1) self.assertEqual(self.st_repo.getStudentById(self.st3.getId()), self.st3) def testUpdateStudent(self): new_st = Student("Marin", 3, 2) self.st_repo.updateStudent(new_st) self.assertEqual(self.st_repo.getStudentById(2).getName(), "Marin") new_st = Student("Ana", 32, 0) self.st_repo.updateStudent(new_st) self.assertEqual(self.st_repo.getStudentById(0).getGroup(), 32)
def test_validateMark(): val = MarkValidator() st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) mrk = Mark(st1, pb1, 11) try: val.validateMark(mrk) assert False except ValueError: assert True mrk = Mark(st2, pb2, 6.5) try: val.validateMark(mrk) assert False except ValueError: assert True mrk = Mark(st2, pb2, "10") try: val.validateMark(mrk) assert False except ValueError: assert True
def test_getStudentWithMostProblemsMarkOver(): st_repo = StudentInMemoryRepository() pb_repo = LabProblemInMemoryRepository() mrk_repo = MarkInMemoryRepository() pb_val = LabProblemValidator() statistics_service = StatisticsService(st_repo, pb_repo, mrk_repo, pb_val) st_repo.addStudent(Student("Ana", 21, 0)) st_repo.addStudent(Student("Ion", 22, 1)) st_repo.addStudent(Student("Mircea", 21, 2)) st_repo.addStudent(Student("Ionel", 56, 3)) pb_repo.addProblem(LabProblem("01_01", "ceva", 3)) pb_repo.addProblem(LabProblem("03_01", "altceva", 6)) pb_repo.addProblem(LabProblem("03_05", "mama", 2)) pb_repo.addProblem(LabProblem("16_01", "dada", 10)) mrk_repo.addMark( Mark(Student("Ana", 21, 0), LabProblem("01_01", "ceva", 3), 8)) mrk_repo.addMark( Mark(Student("Ion", 22, 1), LabProblem("01_01", "ceva", 3), 5)) mrk_repo.addMark( Mark(Student("Ana", 21, 0), LabProblem("16_01", "dada", 10), 8)) mrk_repo.addMark( Mark(Student("Ion", 22, 1), LabProblem("16_01", "dada", 10), 3)) mrk_repo.addMark( Mark(Student("Mircea", 21, 2), LabProblem("01_01", "ceva", 3), 4)) mrk_repo.addMark( Mark(Student("Ionel", 56, 3), LabProblem("03_01", "altceva", 6), 5)) expected = StudentProblemsDTO(0, "Ana", 2) assert statistics_service.getStudentWithMostProblemsMarkOver(5) == expected expected = None assert statistics_service.getStudentWithMostProblemsMarkOver(9) == expected
def test_validateMarkInRepo(): val = MarkValidator() st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) pb3 = LabProblem("06_11", "dada", 2) mrk_repo = MarkInMemoryRepository() mrk1 = Mark(st1, pb1, 10) mrk_repo.addMark(mrk1) mrk2 = Mark(st1, pb2, 6) mrk_repo.addMark(mrk2) mrk3 = Mark(st2, pb2, 9) mrk_repo.addMark(mrk3) mrk = Mark(st1, pb1, 6) try: val.validateMarkInRepo(mrk, mrk_repo) assert False except ValueError: assert True mrk = Mark(st1, pb3, 10) try: val.validateMarkInRepo(mrk, mrk_repo) assert False except ValueError: assert True
def testAddMark(self): self.mrk_repo.addMark( Mark(Student("Ceva", 22, 9), LabProblem("05_07", "dada", 6), 2)) self.assertTrue(self.mrk_repo.getNumberOfMarks() == 4) self.mrk_repo.addMark( Mark(Student("Ceva", 22, 7), LabProblem("08_07", "dada", 6), 6)) self.assertTrue(self.mrk_repo.getNumberOfMarks() == 5)
def test_getMark(): val = MarkValidator() mrk_repo = MarkInMemoryRepository() st_repo = StudentInMemoryRepository() pb_repo = LabProblemInMemoryRepository() st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) st_repo.addStudent(st1) st_repo.addStudent(st2) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) pb3 = LabProblem("01_02", "ma rog", 2) pb_repo.addProblem(pb1) pb_repo.addProblem(pb2) pb_repo.addProblem(pb3) mark_service = MarkService(mrk_repo, st_repo, pb_repo, val) mark_service.addMark(0, "01_01", 10) mark_service.addMark(0, "06_10", 6) mark_service.addMark(1, "01_01", 8) assert mark_service.getMark(0, "01_01").getMark() == 10 assert mark_service.getMark(1, "01_01").getStudent() == st2 try: mark_service.getMark(1, "06_10") assert False except ValueError: assert True
def test_updateMark(): st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) mrk_repo = MarkInMemoryRepository() mrk1 = Mark(st1, pb1, 10) mrk_repo.addMark(mrk1) mrk2 = Mark(st1, pb2, 6) mrk_repo.addMark(mrk2) mrk3 = Mark(st2, pb2, 9) mrk_repo.addMark(mrk3) mrk_new = Mark(st1, pb1, 7) mrk_repo.updateMark(mrk_new) assert mrk_repo.getMarkById(mrk_new.getId()).getMark() == 7 mrk_new = Mark(st2, pb2, 9) mrk_repo.updateMark(mrk_new) assert mrk_repo.getMarkById(mrk_new.getId()).getMark() == 9 mrk_new = Mark(st1, pb2, 8) mrk_repo.updateMark(mrk_new) assert mrk_repo.getMarkById(mrk_new.getId()).getMark() == 8 mrk_new = Mark(st1, pb1, 5) mrk_repo.updateMark(mrk_new) assert mrk_repo.getMarkById(mrk_new.getId()).getMark() == 5
def testUpdateStudent(self): new_st = Student("Marin", 3, 2) self.st_repo.updateStudent(new_st) self.assertEqual(self.st_repo.getStudentById(2).getName(), "Marin") new_st = Student("Ana", 32, 0) self.st_repo.updateStudent(new_st) self.assertEqual(self.st_repo.getStudentById(0).getGroup(), 32)
def setUp(self): self.st1 = Student("ana", 211, 1) self.st2 = Student("mircea", 212, 2) self.pb1 = LabProblem("21_01", "ceva", 3) self.pb2 = LabProblem("01_02", "altceva", 2) self.mark1 = Mark(self.st1, self.pb1, 10) self.mark2 = Mark(self.st2, self.pb1, 5) self.mark3 = Mark(self.st2, self.pb2, 8)
def testUpdateMark(self): mrk_new = Mark(Student("Ana", 21, 0), LabProblem("01_01", "fa ceva", 3), 7) self.mrk_repo.updateMark(mrk_new) self.assertTrue( self.mrk_repo.getMarkById(mrk_new.getId()).getMark() == 7) mrk_new = Mark(Student("Ion", 14, 1), LabProblem("06_10", "altceva", 5), 9) self.mrk_repo.updateMark(mrk_new) self.assertTrue( self.mrk_repo.getMarkById(mrk_new.getId()).getMark() == 9)
def test_getId(): st1 = Student("ana", 211, 1) st2 = Student("mircea", 212, 2) pb1 = LabProblem("21_01", "ceva", 3) pb2 = LabProblem("01_02", "altceva", 2) mark1 = Mark(st1, pb1, 10) mark2 = Mark(st2, pb1, 5) mark3 = Mark(st2, pb2, 8) assert mark1.getId() == "1_21_01" assert mark2.getId() == "2_21_01" assert mark3.getId() == "2_01_02"
def setUp(self): st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) self.mrk_repo = MarkInMemoryRepository() self.mrk1 = Mark(st1, pb1, 10) self.mrk_repo.addMark(self.mrk1) self.mrk2 = Mark(st1, pb2, 6) self.mrk_repo.addMark(self.mrk2) self.mrk3 = Mark(st2, pb2, 9) self.mrk_repo.addMark(self.mrk3)
def test_getMarkById(): st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) mrk_repo = MarkInMemoryRepository() mrk1 = Mark(st1, pb1, 10) mrk_repo.addMark(mrk1) mrk2 = Mark(st1, pb2, 6) mrk_repo.addMark(mrk2) mrk3 = Mark(st2, pb2, 9) mrk_repo.addMark(mrk3) assert mrk_repo.getMarkById(mrk1.getId()).getMark() == 10 assert mrk_repo.getMarkById(mrk2.getId()).getStudent() == st1
def test_addMark(): st1 = Student("Ana", 21, 0) st2 = Student("Ion", 14, 1) pb1 = LabProblem("01_01", "fa ceva", 3) pb2 = LabProblem("06_10", "altceva", 5) mrk_repo = MarkInMemoryRepository() mrk = Mark(st1, pb1, 10) mrk_repo.addMark(mrk) assert mrk_repo.getNumberOfMarks() == 1 mrk = Mark(st1, pb2, 6) mrk_repo.addMark(mrk) assert mrk_repo.getNumberOfMarks() == 2 mrk = Mark(st2, pb2, 9) mrk_repo.addMark(mrk) assert mrk_repo.getNumberOfMarks() == 3
def __getStudentForLine(self, line): ''' Returns a student formed with the information from the given line IN: line - string, got from file, with the format (stId;stName;stGroup) ''' st_id, name, group = line.split(";") st_id = int(st_id) group = int(group) student = Student(name, group, st_id) return student
def addStudent(self, name, group): ''' Creates a student and adds it to the students (student repository) IN: name - string group - integer ''' st_id = self.getAvailableId() st = Student(name, group, st_id) self.__val.validateStudent(st) self.__students.addStudent(st) return "The student was added...\n"
def __removeMarksForProblem(self, problem_number): ''' Removes all the marks with the problem problem_number ''' for mark_key in self.__catalog.getAllMarks(): stud_id, lab_id, pb_id = mark_key.split("_") pb_num = lab_id + "_" + pb_id if pb_num == problem_number: st = Student("", 0, stud_id) pb = self.getProblemByNumber(problem_number) mrk = Mark(st, pb, 0) self.__catalog.removeMark(mrk.getId())
def test_getStudentsForProblem(): st_repo = StudentInMemoryRepository() pb_repo = LabProblemInMemoryRepository() mrk_repo = MarkInMemoryRepository() pb_val = LabProblemValidator() statistics_service = StatisticsService(st_repo, pb_repo, mrk_repo, pb_val) st_repo.addStudent(Student("Ana", 21, 0)) st_repo.addStudent(Student("Ion", 22, 1)) st_repo.addStudent(Student("Mircea", 21, 2)) st_repo.addStudent(Student("Pas", 56, 3)) pb_repo.addProblem(LabProblem("01_01", "ceva", 3)) pb_repo.addProblem(LabProblem("03_01", "altceva", 6)) pb_repo.addProblem(LabProblem("03_05", "mama", 2)) pb_repo.addProblem(LabProblem("16_01", "dada", 10)) mrk_repo.addMark( Mark(Student("Ana", 21, 0), LabProblem("01_01", "ceva", 3), 8)) mrk_repo.addMark( Mark(Student("Ion", 22, 1), LabProblem("01_01", "ceva", 3), 5)) mrk_repo.addMark( Mark(Student("Ana", 21, 0), LabProblem("16_01", "dada", 10), 9)) mrk_repo.addMark( Mark(Student("Ion", 22, 1), LabProblem("16_01", "dada", 10), 3)) mrk_repo.addMark( Mark(Student("Mircea", 21, 2), LabProblem("01_01", "ceva", 3), 4)) mrk_repo.addMark( Mark(Student("Ionel", 56, 3), LabProblem("03_01", "altceva", 6), 5)) assert statistics_service.getStudentsForProblemRecursive("01_01") == [ StudentMarkDTO(mrk_repo.getMarkById("0_01_01")), StudentMarkDTO(mrk_repo.getMarkById("1_01_01")), StudentMarkDTO(mrk_repo.getMarkById("2_01_01")) ] try: statistics_service.getStudentsForProblemRecursive("02_04") assert False except ValueError: assert True
def setUp(self): self.st1 = Student("Ion", 21, 1) self.st2 = Student("Ana", 32, 2) self.st3 = Student("Mircea", 14, 3) self.st_repo = StudentInMemoryRepository() self.st_repo.addStudent(self.st1) self.st_repo.addStudent(self.st2) self.st_repo.addStudent(self.st3)
def test_validateIdInRepo(): st_repo = StudentInMemoryRepository() st1 = Student("ana", 12, 1) st_repo.addStudent(st1) st2 = Student("ion", 131, 0) st_repo.addStudent(st2) st3 = Student("gigi", 14, 5) st_repo.addStudent(st3) val = StudentValidator() st_id = -1 try: val.validateIdInRepo(st_id, st_repo) assert False except ValueError: assert True st_id = "unu" try: val.validateIdInRepo(st_id, st_repo) assert False except ValueError: assert True st_id = 2 try: val.validateIdInRepo(st_id, st_repo) assert False except ValueError: assert True st_id = 1 try: val.validateIdInRepo(st_id, st_repo) assert True except ValueError: assert False
def updateStudent(self, st_id, name, group): ''' Updates the information of a specific student from students Returns all the students in students IN: st_id - integer name - string group - integer ''' self.__val.validateIdInRepo(st_id, self.__students) st = Student(name, group, st_id) self.__val.validateStudent(st) self.__updateMarksForStudent(st, st_id) self.__students.updateStudent(st) return "The student was updated...\n"
def test_getStudentsWithMarksUnder5(): st_repo = StudentInMemoryRepository() pb_repo = LabProblemInMemoryRepository() mrk_repo = MarkInMemoryRepository() pb_val = LabProblemValidator() statistics_service = StatisticsService(st_repo, pb_repo, mrk_repo, pb_val) st_repo.addStudent(Student("Ana", 21, 0)) st_repo.addStudent(Student("Ion", 22, 1)) st_repo.addStudent(Student("Mircea", 21, 2)) st_repo.addStudent(Student("Pas", 56, 3)) pb_repo.addProblem(LabProblem("01_01", "ceva", 3)) pb_repo.addProblem(LabProblem("03_01", "altceva", 6)) pb_repo.addProblem(LabProblem("03_05", "mama", 2)) pb_repo.addProblem(LabProblem("16_01", "dada", 10)) mrk_repo.addMark( Mark(Student("Ana", 21, 0), LabProblem("01_01", "ceva", 3), 8)) mrk_repo.addMark( Mark(Student("Ion", 22, 1), LabProblem("01_01", "ceva", 3), 5)) mrk_repo.addMark( Mark(Student("Ana", 21, 0), LabProblem("16_01", "dada", 10), 9)) mrk_repo.addMark( Mark(Student("Ion", 22, 1), LabProblem("16_01", "dada", 10), 3)) mrk_repo.addMark( Mark(Student("Mircea", 21, 2), LabProblem("01_01", "ceva", 3), 4)) mrk_repo.addMark( Mark(Student("Ionel", 56, 3), LabProblem("03_01", "altceva", 6), 5)) assert statistics_service.getStudentsWithMarksUnder5Recursive() == [ StudentMarkDTO( Mark(st_repo.getStudentById(1), LabProblem("", "", 0), 4.0)), StudentMarkDTO( Mark(st_repo.getStudentById(2), LabProblem("", "", 0), 4.0)) ]
class TestCaseStudentClass(unittest.TestCase): def setUp(self): self.st1 = Student("Ion Popescu", 211, 4) self.st2 = Student("Ana", 415, 5) def testGetName(self): self.assertTrue(self.st1.getName() == "Ion Popescu") self.assertTrue(self.st2.getName() == "An") def testGetGroup(self): self.assertTrue(self.st1.getGroup() == 211) self.assertTrue(self.st2.getGroup() == 415) def testGetId(self): self.assertTrue(self.st1.getId() == 4) self.assertTrue(self.st2.getId() == 5) def testGetInitial(self): self.assertTrue(self.st1.getInitial() == "I") self.assertTrue(self.st2.getInitial() == "A")
def test_valdidateStudent(): val = StudentValidator() try: st1 = Student("Ion Popescu", 211, 12) st2 = Student("Maricica24POpescu", "2", 9) val.validateStudent(st1) assert True val.validateStudent(st2) assert False except ValueError: assert True try: st1 = Student("Marin", "45", 4) val.validateStudent(st1) assert False except ValueError: assert True try: st2 = Student("Marin Preda", False, 5) val.validateStudent(st2) assert False except ValueError: assert True try: st2 = Student("Ion", 2, 4) st1 = Student("Ana", 5, 6) val.validateStudent(st2) assert True val.validateStudent(st1) assert True except ValueError: assert False try: st1 = Student("ion", 21, 3) val.validateStudent(st1) assert False except ValueError: assert True
def testGetMarkById(self): self.assertTrue( self.mrk_repo.getMarkById(self.mrk1.getId()).getMark() == 10) self.assertTrue( self.mrk_repo.getMarkById(self.mrk2.getId()).getStudent() == Student("Ana", 21, 0))
def setUp(self): self.st1 = Student("Ion Popescu", 211, 4) self.st2 = Student("Ana", 415, 5)
def testAddStudent(self): self.st_repo.addStudent(Student("Danut", 22, 6)) self.assertEqual(self.st_repo.getNumberOfStudents(), 4) self.st_repo.addStudent(Student("Mircea", 56, 9)) self.assertEqual(self.st_repo.getNumberOfStudents(), 5)