コード例 #1
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)
コード例 #2
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")