Example #1
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_updateStudent():
    sts = StudentInMemoryRepository()
    val = StudentValidator()
    st_service = StudentService(sts, val)
    
    st_service.addStudent("Cami", 2)
    st_service.addStudent("Ana", 211)
    st_service.addStudent("Ioana", 214)
    
    st_service.updateStudent(0, "Ciocarlia", 44)
    assert sts.getStudentById(0).getName() == "Ciocarlia"
    
    st_service.updateStudent(2, "Madona", 0)
    assert sts.getStudentById(2).getGroup() == 0
    
    try:
        st_service.updateStudent(1, "12", "56")
        assert False
    except ValueError:
        assert True
        
    try:
        st_service.updateStudent(3, "mn", 55)
        assert False
    except ValueError:
        assert True
Example #3
0
 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_generateRandomStudents():
    sts = StudentInMemoryRepository()
    val = StudentValidator()
    st_service = StudentService(sts, val)
    st_service.generateRandomStudents(10)
    assert len(sts.getAllStudents()) == 10
    
    st_service.generateRandomStudents(4)
    assert len(sts.getAllStudents()) == 14
def test_addStudent():
    sts = StudentInMemoryRepository()
    val = StudentValidator()
    st_service = StudentService(sts, val)
    
    st_service.addStudent("Ana", 211)
    assert len(sts.getAllStudents()) == 1
    
    st_service.addStudent("Cami", 2)
    assert len(sts.getAllStudents()) == 2
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_removeStudent():
    sts = StudentInMemoryRepository()
    val = StudentValidator()
    st_service = StudentService(sts, val)
    
    st_service.addStudent("Cami", 2)
    st_service.addStudent("Ana", 211)
    st_service.addStudent("Ioana", 214)
    
    st_service.removeStudent(0)
    assert sts.getNumberOfStudents() == 2
    
    st_service.removeStudent(2)
    assert sts.getNumberOfStudents() == 1
    
    try:
        st_service.removeStudent(0)
        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_getStudentById():
    sts = StudentInMemoryRepository()
    val = StudentValidator()
    st_service = StudentService(sts, val)
    
    st_service.addStudent("Cami", 2)
    st_service.addStudent("Ana", 211)
    st_service.addStudent("Ioana", 214)
    
    st = st_service.getStudentById(1)
    assert st.getName() == "Ana"
    assert st.getGroup() == 211
    
    st = st_service.getStudentById(0)
    assert st.getGroup() == 2
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
Example #11
0
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
Example #12
0
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)