Exemple #1
0
class UI:
    def __init__(self):
        self.repo = TextRepository()
        self.studentController = StudentController(self.repo)

    def show_menu(self):
        print("1. Add student")
        print("2. Give bonus")
        print("3. Display all students including a string")
        print("0. Exit")

    def startup(self):
        self.show_menu()
        while True:
            try:
                n = int(input(">>"))
            except ValueError as e:
                print(e)
                continue

            if n == 0:
                break

            elif n == 1:
                _id = int(input("id: "))
                name = input("name: ")
                attendance = int(input("attendance: "))
                grade = int(input("grade: "))

                try:
                    self.studentController.add_student(
                        Student(_id, name, attendance, grade))
                except ValueError as e:
                    print(e)

            elif n == 2:
                p = int(input("p: "))
                b = int(input("b: "))

                self.studentController.give_bonus(p, b)

            elif n == 3:
                string = input("string: ").lower()
                _list = self.repo.get_all()
                new = []

                for s in _list:
                    if string in s.name.lower():
                        new.append(s)

                for s in sorted(new):
                    print(s)

            else:
                print("[ERROR] Invalid Command!")
    def test_student(self):
        s = Student(0, "Ana Maria", 9, 10)
        self.assertEqual(s.name, "Ana Maria")
        repo = Repository()
        cont = StudentController(repo)

        cont.add_student(s)
        self.assertRaises(ValueError, cont.add_student,
                          Student(0, "New Name", 0, 0))
        self.assertRaises(ValueError, cont.add_student,
                          Student(1, "Invalid", 0, 0))
        self.assertRaises(ValueError, cont.add_student,
                          Student(1, "New Name", -1, 0))
        self.assertRaises(ValueError, cont.add_student,
                          Student(1, "New Name", 0, 12))
        cont.add_student(Student(1, "New Name", 0, 0))
        self.assertEqual(len(repo), 2)
Exemple #3
0
 def setUp(self):
     self.controller=StudentController(StudentRepository(),undoController(),RedoController())
     st=self.controller.add(Students(1,"Dan",5))
Exemple #4
0
class TestCase(unittest.TestCase):


    def setUp(self):
        self.controller=StudentController(StudentRepository(),undoController(),RedoController())
        st=self.controller.add(Students(1,"Dan",5))

    
    def tearDown(self):
        pass
    
    def testAdd(self):
        self.assertTrue(self.controller.getNumberOfStudents()==1)
        self.controller.add(Students(2,"Ion",4))
        self.assertTrue(self.controller.getNumberOfStudents()==2)

        
        #assert adding a student with an id that already exists - error expected
        
        try:
            self.controller.add(Students(1,"Ion",6))
            assert False
        except ValueError:
            pass
        
    def testRemove(self):
        self.controller.add(Students(2,"Radu",6))
        self.controller.removeStudent(1)
        self.assertTrue(self.controller.getNumberOfStudents()==1)
        
        self.controller.add(Students(2,"Radu",6))
        try:
            self.controller.removeStudent(4)
            assert False
        except ValueError:
            pass
        
    def testUpdate(self):
        try:
            self.controller.updateStudent(1,Students(1,"Ionut",8))
            assert False
        except ValueError:
            pass
        
        try:
            self.controller.updateStudent(5,Students(3,"Emil",9))
            assert False
        except ValueError:
            pass
Exemple #5
0
 def __init__(self):
     self.repo = TextRepository()
     self.studentController = StudentController(self.repo)