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
예제 #2
0
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_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_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_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))
    ]