コード例 #1
0
    def __init__(
            self, storageType: str,
            studentRepositoryLocation: str,
            gradeRepositoryLocation: str,
            assignmentRepositoryLocation: str
    ):
        if storageType == 'memory':
            self.__studentRepository = Repository(Student)
            self.__gradeRepository = Repository(Grade)
            self.__assignmentRepository = Repository(Assignment)
        elif storageType == 'text':
            self.__studentRepository = TextFileRepository(Student, studentRepositoryLocation)
            self.__gradeRepository = TextFileRepository(Grade, gradeRepositoryLocation)
            self.__assignmentRepository = TextFileRepository(Assignment, assignmentRepositoryLocation)
        elif storageType == 'binary':
            self.__studentRepository = BinaryRepository(Student, studentRepositoryLocation)
            self.__gradeRepository = BinaryRepository(Grade, gradeRepositoryLocation)
            self.__assignmentRepository = BinaryRepository(Assignment, assignmentRepositoryLocation)
        elif storageType == 'json':
            self.__studentRepository = JsonRepository(Student, studentRepositoryLocation)
            self.__gradeRepository = JsonRepository(Grade, gradeRepositoryLocation)
            self.__assignmentRepository = JsonRepository(Assignment, assignmentRepositoryLocation)
        elif storageType == 'sql':
            connection = MySQLConnector().getConnection()

            self.__studentRepository = MySQLRepository(Student, studentRepositoryLocation, connection)
            self.__gradeRepository = MySQLRepository(Grade, gradeRepositoryLocation, connection)
            self.__assignmentRepository = MySQLRepository(Assignment, assignmentRepositoryLocation, connection)

        self.__repositories = {
            Student: self.__studentRepository,
            Grade: self.__gradeRepository,
            Assignment: self.__assignmentRepository
        }
コード例 #2
0
    def solve(self, noChrom, noIter, cross, mutation):
        for i in range(0, noChrom):
            self.repo.add(Chromosome(self.problParam))

        self.repo.sort()
        p = Repository()
        #print(self.repo.get(0))
        for i in range(0, noIter):
            repo1 = Repository()
            #repo1.add(self.repo.get(0))
            for j in range(0, noChrom):
                if random.uniform(0, 1) <= cross:
                    parents = self.selectParents(noChrom)
                    c = parents[0].crossover(parents[1])
                    if random.uniform(0, 1) <= mutation:
                        c.mutation()
                else:
                    c = self.repo.get(j).clone()
                    if random.uniform(0, 1) <= mutation:
                        c.mutation()
                repo1.add(c)
            repo1.sort()
            self.repo = repo1
            p.add(self.repo.get(0))
        return p
コード例 #3
0
ファイル: TestGradeController.py プロジェクト: andidh/Python
 def setUp(self):
     TestCase.setUp(self)
     self.controller = ControllerGrade(Repository(), Repository(),
                                       Repository(), ValidatorGrade(),
                                       UndoController())
     # put here test logic
     self.controller.add_grade(1, 1, 1, 9)
     self.controller.add_grade(2, 1, 2, 4)
     self.controller.add_grade(3, 1, 3, 3)
コード例 #4
0
def undoExampleMedium():
    undoController = UndoController()
    clientRepo = Repository()
    carRepo = Repository()

    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentValidator = RentalValidator()
    rentController = RentalController(undoController, rentValidator, rentRepo, carRepo, clientRepo)
    
    '''
    Start client Controller
    '''
    clientValidator = ClientValidator()
    clientController = ClientController(undoController, rentController, clientValidator, clientRepo)
    
    '''
    Start car Controller
    '''
    carValidator = CarValidator()
    carController = CarController(undoController, rentController, carValidator, carRepo)

    '''
    We add 3 clients
    '''
    clientSophia = clientController.create(103, "2990511035588", "Sophia")
    clientCarol = clientController.create(104, "2670511035588", "Carol")
    clientBob = clientController.create(105, "2590411035588", "Bob")    
    printReposWithMessage("We added 3 clients", clientRepo, None, None)

    '''
    We delete 2 of the clients
    '''
    clientController.delete(103)
    clientController.delete(105)
    printReposWithMessage("Deleted Sophia and Bob", clientRepo, None, None)

    '''
    We undo twice
    '''
    undoController.undo()
    printReposWithMessage("1 undo, so Bob is back", clientRepo, None, None)
    undoController.undo()
    printReposWithMessage("Another undo, so Sophia is back too", clientRepo, None, None)
    
    '''
    We redo once
    '''
    undoController.redo()
    printReposWithMessage("1 redo, so Sophia is again deleted", clientRepo, None, None)
コード例 #5
0
 def __init__(self, fileName):
     self.__repository = Repository(fileName)
     network, [parameters, sizePopulation] = self.__repository.getData()
     self.__ga = GA(sizePopulation, parameters, network)
     self.__ga.initialisation()
     self.__ga.evaluation()
     self.__network = network
コード例 #6
0
ファイル: tests.py プロジェクト: biancapitic/University
 def testUpdateMovieParameters_ValidInput_UpdateParameter(self):
     repo = Repository()
     service = MovieService(repo)
     service.add_movie(1, 'Title', 'Descr', 'Gen')
     service.update_movie_parameters(1, 'title', 'New Title')
     movie = repo.get_elements_list[1]
     self.assertEqual(movie.title, 'New Title')
コード例 #7
0
ファイル: tests.py プロジェクト: biancapitic/University
 def testUpdateClientParameter_ValidInput_UpdateParameter(self):
     repo = Repository()
     service = ClientService(repo)
     service.add_client(1, 'New Client')
     service.update_client_parameters(1, 'name', 'New Name')
     client = repo.get_elements_list[1]
     self.assertEqual(client.name, 'New Name')
コード例 #8
0
def testClient():
    c_repo = Repository()

    c_repo.add(Client(2, "Sandu Ciorba"))
    c_repo.add(Client(12, "Ada Milea"))

    return c_repo
コード例 #9
0
def testBook():
    b_repo = Repository()

    b_repo.add(Book(1, "Charlie and the chocolate factory", "nice storry", "Roald Dalh"))
    b_repo.add(Book(3, "Ciresarii", "tat felu de aventuri", "Constantin Chirita"))

    return b_repo
コード例 #10
0
 def setUp(self):
     TestCase.setUp(self)
     self.controller = ControllerAssignment(Repository(), ValidatorAssign(),
                                            UndoController())
     # put here test logic
     self.controller.add_assignment(1, "ASC", "May")
     self.controller.add_assignment(2, "FP", "March")
     self.controller.add_assignment(3, "Logic", "April")
コード例 #11
0
 def setUp(self):
     TestCase.setUp(self)
     self.controller = ControllerStudent(Repository(), ValidatorStudent(),
                                         UndoController())
     # put here test logic
     self.controller.add_student(1, "A", 1)
     self.controller.add_student(2, "B", 2)
     self.controller.add_student(3, "C", 3)
コード例 #12
0
 def initialize_movie_repository():
     if Settings.repository_type == 'memory':
         movie_repository = Repository()
     elif Settings.repository_type == 'file':
         movie_repository = FileRepository('movies.txt', Movie.read_movie,
                                           Movie.write_movie)
     elif Settings.repository_type == 'binaryfile':
         movie_repository = BinaryFileRepository('movies_binary.txt')
     return movie_repository
コード例 #13
0
 def initialize_rental_repository():
     if Settings.repository_type == 'memory':
         rental_repository = Repository()
     elif Settings.repository_type == 'file':
         rental_repository = FileRepository('rentals.txt',
                                            Rental.read_rental,
                                            Rental.write_rental)
     elif Settings.repository_type == 'binaryfile':
         rental_repository = BinaryFileRepository('rentals_binary.txt')
     return rental_repository
コード例 #14
0
 def initialize_client_repository():
     if Settings.repository_type == 'memory':
         client_repository = Repository()
     elif Settings.repository_type == 'file':
         client_repository = FileRepository('clients.txt',
                                            Client.read_client,
                                            Client.write_client)
     elif Settings.repository_type == 'binaryfile':
         client_repository = BinaryFileRepository('clients_binary.txt')
     return client_repository
コード例 #15
0
def testDisciplineController():
    disciplineRepository = Repository()
    disciplineValidator = DisciplineValidator()
    dc = DisciplineController(disciplineRepository, disciplineValidator)
    dc.addDiscipline("1", "Math")
    assert len(dc.getDisciplines()) == 1
    try:
        dc.addDiscipline("1", "Spanish")
        assert False
    except:
        assert True
コード例 #16
0
 def setUp(self):
     # setUp method will be executed before every test
     TestCase.setUp(self)
     self.repository = Repository()
     # add mock students to repo
     stud1 = Student(1, "A", 1)
     stud2 = Student(2, "B", 2)
     stud3 = Student(3, "C", 3)
     self.repository.add_item(stud1)
     self.repository.add_item(stud2)
     self.repository.add_item(stud3)
コード例 #17
0
    def testController(self):

        repo = Repository()
        controller = Controller(repo)

        myList = controller.displayAllStudents('M')
        assert len(myList) == 3

        myList = controller.displayStudentsOrderedByGrades()
        assert myList[0].getGrade() == 10
        assert myList[1].getGrade() == 9
        assert myList[0].getName() == 'Ionela'
コード例 #18
0
    def setUp(self):
        self.undoController = UndoController()

        self.studentRepo = Repository()
        self.studentValidator = StudentValidator()
        self.studentController = StudentController(self.studentValidator,
                                                   self.studentRepo,
                                                   self.undoController)

        self.disciplineRepo = Repository()
        self.disciplineValidator = DisciplineValidator()
        self.disciplineController = DisciplineController(
            self.disciplineValidator, self.disciplineRepo, self.undoController)

        self.gradeRepo = Repository()
        self.gradeValidator = GradeValidator()
        self.gradeController = GradeController(self.gradeValidator,
                                               self.gradeRepo,
                                               self.disciplineRepo,
                                               self.studentRepo,
                                               self.undoController)
コード例 #19
0
 def obtainPersistencySource():
     with open("./local.settings", "r") as f:
         lines = f.readlines()
         repo_type = lines[0].strip().split('=')[1]
     if repo_type == "inmemory":
         return Repository(), Repository(), GradeRepository()
     if repo_type == "file":
         students_repo_file = lines[1].strip().split('=')[1]
         discipline_repo_file = lines[2].strip().split('=')[1]
         grade_repo_file = lines[3].strip().split('=')[1]
         return FileRepository(students_repo_file, Student), FileRepository(discipline_repo_file, Discipline), FileGradeRepository(grade_repo_file, Grade)
     if repo_type == "binary":
         students_repo_file = lines[1].strip().split('=')[1]
         discipline_repo_file = lines[2].strip().split('=')[1]
         grade_repo_file = lines[3].strip().split('=')[1]
         return PickleRepository(students_repo_file), PickleRepository(discipline_repo_file), PickleGradeRepository(grade_repo_file)
     if repo_type == "sql":
         students_repo_file = lines[1].strip().split('=')[1]
         discipline_repo_file = lines[2].strip().split('=')[1]
         grade_repo_file = lines[3].strip().split('=')[1]
         return SQL_Repo(students_repo_file, Student), SQL_Repo(discipline_repo_file, Discipline), SQL_GradeRepo(grade_repo_file, Grade)
コード例 #20
0
def testRepository():
	repository = Repository()
	holiday1 = Holiday(0, "Madrid", "seaside", 342)
	holiday2 = Holiday(1, "Quebec", "city-break", 342)	

	assert repository.addElement(holiday1) == True
	assert repository.addElement(holiday1) == False
	assert repository.addElement(holiday2) == True

	assert len(repository.getElements()) > 0
	assert len(repository.getElements()) == 2

	return True
コード例 #21
0
ファイル: tests.py プロジェクト: rzvpop/lab4
    def test_search(self):
        book_repo = Repository()
        client_repo = Repository()
        rental_repo = Repository()
        book_repo.add(Book(1, "Iona", "teatru postbelic", "Marin Sorescu"))
        book_repo.add(Book(2, "Amintiri din copilarie", "proza",
                           "Ion Creanga"))
        book_repo.add(Book(3, "1984", "roman", "George Orwell"))

        st_ctrl = StatisticsController(book_repo, client_repo, rental_repo)

        l = []
        st_ctrl.search(book_repo, "author", "re", l)
        self.assertTrue(len(l) == 2)

        rental_repo.add(
            Rental(2, 2, 10, date.today(),
                   date.today() + timedelta(days=10), False))
        most_rented = st_ctrl.mostRentedBooks()
        self.assertTrue(
            most_rented[0] ==
            [Book(2, "Amintiri din copilarie", "proza", "Ion Creanga"), 1])
コード例 #22
0
 def testSwap(self):        
     repo = Repository()
     
     controller = Controller(repo)
     
     controller._guess = controller.getAll()[0]
     
     assert controller._guess[1] == 'c'
     assert controller._guess[2] == 'r'
     
     controller.swap(0, 1, 0, 2)
     
     assert controller._guess[1] == 'r'
     assert controller._guess[2] == 'c'
コード例 #23
0
    def testRepo(self):
        repo = Repository()
        assert repo.add(Student('1', 'Mihai Ionut', 10, 10)) == False
        assert repo.add(Student('2', 'Mihai Ionut', 10, 10)) == False
        assert repo.add(Student('3', 'Mihai Ionut', 10, 10)) == False

        repo.addBonus(Student('1', 'Mihai', 13, 9), 1)
        repo.addBonus(Student('2', 'Ionut', 5, 8), 1)
        for i in repo.getAll():
            if i.getID() == 1:
                assert i.getGrade() == 10
            if i.getID() == 2:
                assert i.getGrade() == 9

        assert len(repo.getAll()) == 10
コード例 #24
0
def testRent():
    b_repo = testBook()
    c_repo = testClient()
    r_repo = Repository()

    ctrl = Controller(b_repo, c_repo, r_repo)

    ctrl.addRental(["1", "3", "12"])
    try:
        ctrl.addRental(["2", "4", "42"])
    except LibraryException:
        pass

    rentals = r_repo.getAll()

    assert(rentals[0] == Rental(1, 4, 12, date.today(), date.today() + timedelta(days=10), False))
コード例 #25
0
    def __testRepository(self):

        students = Repository()
        students.store(Student(123, 'Andrei Stefan'))
        students.store(Student(124, 'Cosmin Iordache'))
        students.store(Student(125, 'Simon Claudiu'))

        # len of repository
        assert len(students) == 3

        # findByName2 function tests
        assert students.findByName2('Andrei Stefan') == 123
        assert students.findByName2('Cosmin Iordache') == 124
        assert students.findByName2('Simon Claudiu') == 125

        #find tests
        assert students.find(133) == False
        assert students.find(134) == False
        assert students.find(135) == False

        #store tests
        assert students.store(Student(123, 'Cosmin')) == False
        assert students.store(Student(125, 'Geanina')) == False
        assert students.store(Student(124, 'Mihai')) == False

        #update test
        assert students.update(Student(133, 'Cosmin')) == False
        assert students.update(Student(155, 'Geanina')) == False
        assert students.update(Student(175, 'Ionut')) == False

        students.store(Student(126, 'Arthur Mihai'))
        students.store(Student(127, 'George Ionut'))

        # test store and delete
        assert len(students) == 5
        students.delete(123)
        assert len(students) == 4
        assert students.delete(1664) == False
コード例 #26
0
def testController():
	repository = Repository()	
	holiday1 = Holiday(0, "Madrid", "seaside", 342)
	holiday2 = Holiday(1, "Quebec", "city-break", 342)
	holiday3 = Holiday(2, "Quebec", "seaside", 333)	
	controller = HolidayController(repository)

	assert repository.addElement(holiday1) == True
	assert repository.addElement(holiday2) == True
	assert repository.addElement(holiday3) == True

	assert len(controller.getHolidays())	== 3
	assert len(controller.getAllResorts()) 	== 2
	assert len(controller.getAllTypes())	== 2

	assert len(controller.searchByResort("Quebec")) == 2
	assert len(controller.searchByResort("Madrid")) == 1

	assert len(controller.searchByType("seaside"))	   == 2
	assert len(controller.searchByType("city-break"))  == 1

	assert controller.loadFromFile("database.txt") == True

	return True
コード例 #27
0
ファイル: RepositoryTest.py プロジェクト: denisvieriu/College
 def setUp(self):
     self._repo = Repository()
コード例 #28
0
 def __init__(self, param):
     self.problParam = param
     self.repo = Repository()
コード例 #29
0
def undoExampleHardest():
    undoController = UndoController()
    clientRepo = Repository()
    carRepo = Repository()
    '''
    Start rental Controller
    '''
    rentRepo = Repository()
    rentController = RentalController(undoController, rentRepo, carRepo,
                                      clientRepo)
    '''
    Start client Controller
    '''
    clientController = ClientController(undoController, rentController,
                                        clientRepo)
    '''
    Start car Controller
    '''
    carController = CarController(undoController, rentController, carRepo)
    '''
    We add 1 client, 1 car and 2 rentals
    '''
    clientSophia = clientController.create(103, "2990511035588", "Sophia")
    carHyundaiTucson = carController.create(201, "CJ 02 TWD", "Hyundai",
                                            "Tucson")
    rentController.createRental(301, clientSophia, carHyundaiTucson,
                                date(2016, 11, 1), date(2016, 11, 30))
    rentController.createRental(302, clientSophia, carHyundaiTucson,
                                date(2016, 12, 1), date(2016, 12, 31))

    printReposWithMessage("We added Sophia, the Hyundai and its 2 rentals",
                          clientRepo, carRepo, rentRepo)

    carController.delete(201)
    printReposWithMessage("Delete the Hyundai (also deletes its rentals)",
                          clientRepo, carRepo, rentRepo)
    '''
    Now undo the performed operations, one by one
    '''
    undoController.undo()
    printReposWithMessage("1 undo, the Hyundai and its rentals are back",
                          clientRepo, carRepo, rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the second rental", clientRepo,
                          carRepo, rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the first rental", clientRepo,
                          carRepo, rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the Hyundai", clientRepo, carRepo,
                          rentRepo)
    '''
    After 5 undos, all repos should be empty, as we did 5 operations in total
    '''
    undoController.undo()
    printReposWithMessage("1 undo deletes Sophia (no more undos)", clientRepo,
                          carRepo, rentRepo)
    '''
    Redos start here
    '''
    undoController.redo()
    printReposWithMessage("1 redo and Sophia is added", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo adds the Hyundai", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo adds the first rental", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo adds the second rental", clientRepo, carRepo,
                          rentRepo)

    undoController.redo()
    printReposWithMessage("1 redo deletes the Hyundai and its rentals (again)",
                          clientRepo, carRepo, rentRepo)
    '''
    Let's do a few undos again...
    '''
    undoController.undo()
    undoController.undo()
    undoController.undo()

    printReposWithMessage("3 undos later, we have Sophia and the Hyundai",
                          clientRepo, carRepo, rentRepo)
    '''
    Now we try something new - let's add another car!
    
    NB!
        A new operation must invalidate the history for redo() operations
    '''
    carController.create(202, "CJ 02 SSE", "Dacia", "Sandero")
    print("\n Do we have a redo? -", undoController.redo(), "\n")
    '''
    Now we should have 2 cars
    '''
    printReposWithMessage("After adding the Dacia, there is no redo ",
                          clientRepo, carRepo, rentRepo)
    '''
    However, undos is still available !
    '''
    undoController.undo()
    printReposWithMessage("1 undo deletes the Dacia", clientRepo, carRepo,
                          rentRepo)

    undoController.undo()
    printReposWithMessage("1 undo deletes the Hyundai", clientRepo, carRepo,
                          rentRepo)
コード例 #30
0
        if i == '"':
            flag = 1
        if flag == 1:
            result += i

    return result[1:-1]


f = open("settings.properties", "r")

whatRepo = f.readline().strip()
whatRepo = whatRepo.split('=')
whatRepo = whatRepo[1].strip()

if whatRepo == 'inmemory':
    studentsRepository = Repository()
    disciplineRepository = Repository()
    gradesRepository = RepositoryGrades()

elif whatRepo == 'textfiles':
    fileName = extractName(f.readline().strip())
    studentsRepository = StudentsFileRepository(fileName)

    fileName = extractName(f.readline().strip())
    disciplineRepository = DisciplinesFileRepository(fileName)

    fileName = extractName(f.readline().strip())
    gradesRepository = GradesFileRepository(fileName)

elif whatRepo == 'binaryfiles':
    fileName = extractName(f.readline().strip())