def test_updateProblem(): pbs = LabProblemInMemoryRepository() val = LabProblemValidator() pb_service = LabProblemService(pbs, val) pb_service.addProblem(21, "fa ceva", 2) pb_service.addProblem(1, "nu aia", 2) pb_service.addProblem(21, "dada", 5) pb_service.updateProblem("21_01", "fa altceva", 4) assert pbs.getProblemByNumber("21_01").getDescription() == "fa altceva" assert pbs.getProblemByNumber("21_01").getDeadline() == 4 pb_service.updateProblem("01_01", "da aia", 2) assert pbs.getProblemByNumber("01_01").getDescription() == "da aia" try: pb_service.updateProblem("01_02", "daa", 2) assert False except ValueError: assert True try: pb_service.updateProblem("1", "neah", 7) 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_removeProblem(): pbs = LabProblemInMemoryRepository() val = LabProblemValidator() pb_service = LabProblemService(pbs, val) pb_service.addProblem(21, "fa ceva", 2) pb_service.addProblem(1, "nu aia", 2) pb_service.addProblem(21, "dada", 5) pb_service.removeProblem("21_01") assert pbs.getNumberOfProblems() == 2 pb_service.removeProblem("21_02") assert pbs.getNumberOfProblems() == 1 try: pb_service.removeProblem("02_02") assert False except ValueError: assert True try: pb_service.removeProblem("1_22") assert False except ValueError: assert True
def setUp(self): self.pbs = LabProblemInMemoryRepository() self.val = LabProblemValidator() self.pb_service = LabProblemService(self.pbs, self.val) self.pb_service.addProblem(21, "fa ceva", 2) self.pb_service.addProblem(1, "nu aia", 2) self.pb_service.addProblem(21, "dada", 5)
def test_generateRandomProblems(): pbs = LabProblemInMemoryRepository() val = LabProblemValidator() pb_service = LabProblemService(pbs, val) pb_service.generateRandomProblems(6) assert pbs.getNumberOfProblems() == 6 pb_service.generateRandomProblems(5) assert pbs.getNumberOfProblems() == 11
def test_addProblem(): pb_repo = LabProblemInMemoryRepository() val = LabProblemValidator() pb_service = LabProblemService(pb_repo, val) pb_service.addProblem(1, "ceva", 2) assert pb_repo.getProblemByNumber("01_01").getDescription() == "ceva" pb_service.addProblem(1, "altceva", 5) assert pb_repo.getProblemByNumber("01_02").getDeadline() == 5 pb_service.addProblem(4, "ceva1", 2) assert pb_repo.getProblemByNumber("04_01").getDescription() == "ceva1"
class TestCaseLabProblemService(unittest.TestCase): def setUp(self): self.pbs = LabProblemInMemoryRepository() self.val = LabProblemValidator() self.pb_service = LabProblemService(self.pbs, self.val) self.pb_service.addProblem(21, "fa ceva", 2) self.pb_service.addProblem(1, "nu aia", 2) self.pb_service.addProblem(21, "dada", 5) def testUpdateProblem(self): ''' Example of BlackBox testing ''' self.pb_service.updateProblem("21_01", "fa altceva", 6) self.assertTrue( self.pbs.getProblemByNumber("21_01").getDeadline() == 6) self.assertRaises(ValueError, self.pb_service.updateProblem, "1_2", "altceva", 5) self.assertRaises(ValueError, self.pb_service.updateProblem, 12, "altceva", 5) self.assertRaises(ValueError, self.pb_service.updateProblem, "21_01", "", 5) self.assertRaises(ValueError, self.pb_service.updateProblem, "21_01", "altceva", "") self.assertRaises(ValueError, self.pb_service.updateProblem, "123_02", "altceva", 5) self.assertRaises(ValueError, self.pb_service.updateProblem, "21_04", "altceva", 5) self.assertRaises(ValueError, self.pb_service.updateProblem, "21_02", "altceva", -5)
def test_validateProblemNumber(): pb1 = LabProblem("01_02", "ceva", 2) pb2 = LabProblem("00_33", "ceva2", 4) pb3 = LabProblem("22_04", "ceva3") pb_repo = LabProblemInMemoryRepository() pb_repo.addProblem(pb1) pb_repo.addProblem(pb2) pb_repo.addProblem(pb3) val = LabProblemValidator() try: pb_num = "01_15" val.validateProblemNumber(pb_num, pb_repo) assert False except ValueError: assert True try: pb_num = "" val.validateProblemNumber(pb_num, pb_repo) assert False except ValueError: assert True try: pb_num = 12 val.validateProblemNumber(pb_num, pb_repo) assert False except ValueError: assert True
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 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_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)) ]
def test_getProblem(): pbs = LabProblemInMemoryRepository() val = LabProblemValidator() pb_service = LabProblemService(pbs, val) pb_service.addProblem(21, "fa ceva", 2) pb_service.addProblem(1, "nu aia", 2) pb_service.addProblem(21, "dada", 5) pb = pb_service.getProblemByNumber("01_01") assert pb.getDescription() == "nu aia" assert pb.getDeadline() == 2 pb = pb_service.getProblemByNumber("21_01") assert pb.getDeadline() == 2 try: pb = pb_service.getProblemByNumber("_2101") assert False except ValueError: assert True