def __init__(self, populationSize, individualMaxSize, startingCoordinates, m): self.__populationSize = populationSize self.__map = m # already a map surface self.__individuals = [] for i in range(populationSize): newIndividual = Individual(individualMaxSize, startingCoordinates, self.__map) newIndividual.generateChromosome() self.__individuals.append(newIndividual) self.evaluate()
def test_validator(self): validator = Validator.get_instance() customer = Individual() customer.set_cnp("198121203415") customer.set_last_name("Dan") customer.set_first_name("Popescu") customer.set_phone_number("0756234876") customer.set_email_address("*****@*****.**") item = Item() currency = Currency("$", "dollar", "USD") item.set_name("Apple") item.set_price(2) item.set_discount(0) item.set_currency(currency) company = Company() company.set_company_name("La Gigi") company.set_fiscal_no("RO0123") company.set_registration_number("123456") company.set_email_address("*****@*****.**") company.set_first_name("Ion") company.set_last_name("Bogdan") company.set_phone_number("0752314567") company.set_fiscal_no("0000012345678") company.set_registration_number("RO01923") bill = Bill() bill.set_currency(currency) bill.set_customer(customer) bill.set_issuer(company) bill.set_issue_date("21.12.2020") bill.set_due_date("21.02.2021") bill.add_items(item) validator.validate_bill(bill)
def __load_from_file(self): index = "current_index" list_type = None if self._repo_type == Individual: index = "current_individual_id" list_type = "individual_list" if self._repo_type == Company: index = "current_company_id" list_type = "company_list" file = open(self.__file_name, "r") json_file = json.loads(file.read()) if index in json_file: self._id = json_file[index] if list_type in json_file: for customer in json_file[list_type]: index = customer["id"] first_name = customer["first_name"] last_name = customer["last_name"] phone_number = customer["phone_number"] email_address = customer["email_address"] if self._repo_type == Individual: cnp = customer["cnp"] customer_to_add = Individual() customer_to_add.set_cnp(cnp) customer_to_add.set_id(index) customer_to_add.set_first_name(first_name) customer_to_add.set_last_name(last_name) customer_to_add.set_phone_number(phone_number) customer_to_add.set_email_address(email_address) if self._repo_type == Company: company_name = customer["company_name"] fiscal_no = customer["fiscal_no"] registration_number = customer["registration_number"] customer_to_add = Company() customer_to_add.set_id(index) customer_to_add.set_first_name(first_name) customer_to_add.set_last_name(last_name) customer_to_add.set_phone_number(phone_number) customer_to_add.set_email_address(email_address) customer_to_add.set_company_name(company_name) customer_to_add.set_fiscal_no(fiscal_no) customer_to_add.set_registration_number(registration_number) self._list.append(customer_to_add) file.close()
def test_equal(self): individual = Individual() individual.set_cnp("1991007032565") individual2 = copy.deepcopy(individual) individual2.set_cnp("1980923032456") self.assertNotEqual(individual2, individual)
def test_cnp_getter_and_setter(self): individual = Individual() individual.set_cnp("1991007032565") self.assertEqual(individual.get_cnp(), "1991007032565") individual.set_cnp("1980923032456") self.assertEqual(individual.get_cnp(), "1980923032456")
def test_json_individual(self): individual_repo = JsonCustomerRepo("json_test.json", Individual) individual = Individual() individual.set_first_name("Ion") individual.set_last_name("Radu") individual.set_id(1) individual.set_email_address("*****@*****.**") individual.set_phone_number("0756456452") individual.set_cnp("1991217654455") individual_repo.store(individual) self.assertEqual(individual_repo.get(1), individual) individual.set_last_name("Dan") individual_repo.update(1, individual) individual_repo2 = JsonCustomerRepo("json_test.json", Individual) self.assertEqual(individual_repo.get(1), individual_repo2.get(1)) individual_repo.reset_id() individual_repo.delete(1)
def test_individual_repo(self): individual1 = Individual() individual1.set_cnp("1991212042312") individual1.set_id(1) individual1.set_phone_number("0753123487") individual1.set_first_name("Petre") individual1.set_last_name("Laur") individual1.set_email_address("*****@*****.**") individual_repo = CustomerRepo(Individual) individual_repo.store(individual1) self.assertEqual(len(individual_repo.get_all()), 1) individual2 = Individual() individual2.set_cnp("1981216065431") individual2.set_last_name("Claurentiu") individual2.set_first_name("Petre") individual2.set_phone_number("0753123487") individual2.set_email_address("*****@*****.**") individual_repo.update(individual1.get_id(), individual2) self.assertEqual(individual2, individual_repo.get(1)) individual_repo.delete(individual2.get_id()) self.assertEqual(individual_repo.get_all(), []) self.assertIsNone(individual_repo.get(-1)) with self.assertRaises(TypeError): individual_repo.store(-1) with self.assertRaises(TypeError): individual_repo.update(1, 1)
def test_individual_customer(self): service = CustomerService(CustomerRepo(Individual), CustomerRepo(Company)) individual = Individual() individual.set_id(1) individual.set_cnp("190702123433") individual.set_first_name("Petre") individual.set_last_name("Vasile") individual.set_phone_number("0745321784") individual.set_email_address("*****@*****.**") service.create_customer(individual) self.assertEqual(service.get_individual_customer(1), individual) individual.set_last_name("Miron") individual.set_cnp("191215678876") service.update_customer(1, individual) self.assertEqual(service.get_individual_customer(1), individual) service.delete_customer(individual) self.assertEqual(service.view_all_individual(), [])
def test_invoice_bill(self): service = BillService(BillRepo(Invoice), BillRepo(FiscalBill)) company = Company() company.set_company_name("La Geani") company.set_registration_number("RO0123") company.set_fiscal_no("0000231523647") company.set_email_address("*****@*****.**") company.set_first_name("Ion") company.set_last_name("Bogdan") company.set_phone_number("0752314567") company.set_fiscal_no("0000012345678") company.set_registration_number("RO01923") individual = Individual() individual.set_cnp("1971209075425") individual.set_id(1) individual.set_first_name("Petre") individual.set_last_name("Vasile") individual.set_phone_number("0745321784") individual.set_email_address("*****@*****.**") item = BillItem() currency = Currency("$", "Dollar", "USD") item.set_id(1) item.set_currency(currency) item.set_name("McChicken") item.set_description("Chicken hamburger") item.set_price(2) item.set_discount(0) item.set_quantity(1) invoice = Invoice() invoice.set_customer(individual) invoice.set_currency(currency) invoice.set_items([item]) invoice.set_id(1) invoice.set_issuer(company) invoice.set_issue_date("24.01.2021") invoice.set_due_date("10.02.2021") invoice.set_notes("Platiti la Banca Transilvania") service.create_bill(invoice) invoice.add_items(item) service.update_bill(1, invoice) self.assertEqual(service.get_invoice(1), invoice) bill2 = service.invoice_to_fiscal(1) bill2.set_id(1) self.assertEqual(service.get_fiscal(1), bill2) service.delete_bill(invoice)
def test_service(self): service = Service("json_test.json", "json_test.json", "json_test.json", "json_test.json") # Customer Options company = Company() address = Address() address.set_address("Strada Academiei nr. 7") address.set_county("Bucuresti") address.set_country("Romania") address.set_postal_code("010011") company.set_id(1) company.set_address(address) company.set_company_name("La Geani") company.set_registration_number("RO0123") company.set_fiscal_no("0000231523647") company.set_email_address("*****@*****.**") company.set_first_name("Ion") company.set_last_name("Bogdan") company.set_phone_number("0752314567") company.set_fiscal_no("0000012345678") company.set_registration_number("RO01923") service.create_customer(company) self.assertEqual(service.get_company_customer(1), company) company.set_company_name("Marketplex") service.modify_customer(1, company) self.assertEqual(service.get_company_customer(1), company) service.delete_customer(company) self.assertEqual(service.view_all_company_customer(), []) individual = Individual() individual.set_cnp("1971209075425") individual.set_id(1) individual.set_first_name("Petre") individual.set_last_name("Vasile") individual.set_phone_number("0745321784") individual.set_email_address("*****@*****.**") service.create_customer(individual) self.assertEqual(service.get_individual_customer(1), individual) individual.set_last_name("Gigel") service.modify_customer(1, individual) self.assertEqual(service.get_individual_customer(1), individual) service.delete_customer(individual) self.assertEqual(service.view_all_individual_customer(), []) individual.set_address(address) # Currency Options currency = Currency("$", "Dollar", "USD") currency.set_id(1) currency.set_exchange_rate(4.5) service.create_currency(currency) self.assertEqual(currency, service.get_currency(1)) currency.set_exchange_rate(4.2) service.modify_currency(1, currency) self.assertEqual(currency, service.get_currency(1)) service.delete_currency(1) self.assertEqual(service.view_currency(), []) # Item Options item = Item() item.set_id(1) item.set_currency(currency) item.set_name("McChicken") item.set_description("Chicken hamburger") item.set_price(2) item.set_discount(0) service.create_item(item) self.assertEqual(item, service.choose_item(1)) item.set_price(3) service.modify_item(1, item) self.assertEqual(item, service.choose_item(1)) service.delete_item(1) self.assertEqual(service.view_items(), []) # Bill Options bill_item = BillItem() bill_item.set_id(1) bill_item.set_currency(currency) bill_item.set_name("McChicken") bill_item.set_description("Chicken hamburger") bill_item.set_price(3) bill_item.set_discount(0) bill = Invoice() bill.set_customer(individual) bill.set_currency(currency) bill.set_items([bill_item]) bill.set_id(1) bill.set_issuer(company) bill.set_issue_date("24.01.2021") bill.set_due_date("10.02.2021") bill.set_notes("Platiti la Banca Transilvania") service.create_item(item) service.create_bill(bill) self.assertEqual(service.get_invoice(1), bill) bill.set_notes("asdfge") service.modify_bill(1, bill) self.assertEqual(service.get_invoice(1), bill) service.add_item_to_bill(1, bill) bill.add_items(bill_item) self.assertEqual(service.get_invoice(1), bill) service.invoice_to_fiscal(1) fiscal_bill = FiscalBill() fiscal_bill.set_customer(individual) fiscal_bill.set_currency(currency) bill_item.set_quantity(2) fiscal_bill.set_total(3.0) fiscal_bill.set_items([bill_item]) fiscal_bill.set_id(1) fiscal_bill.set_issuer(company) fiscal_bill.set_issue_date("24.01.2021") fiscal_bill.set_due_date("10.02.2021") fiscal_bill.set_notes("asdfge") self.assertEqual(fiscal_bill, service.get_fiscal(1)) service.delete_bill(bill) file = open("json_test.json", "w") file.truncate(0) file.write("{}") file.close()
def create_individual_customer(self, cnp, last_name, first_name, email_address, phone_number): customer = Individual() customer.set_cnp(cnp) customer.set_last_name(last_name) customer.set_first_name(first_name) customer.set_email_address(email_address) customer.set_phone_number(phone_number) self.__customer = customer
def test_equal(self): company = Company() company.set_company_name("La Geani") company.set_registration_number("RO0123") company.set_fiscal_no("0000231523647") company.set_email_address("*****@*****.**") company.set_first_name("Ion") company.set_last_name("Bogdan") company.set_phone_number("0752314567") company.set_fiscal_no("0000012345678") company.set_registration_number("RO01923") individual = Individual() individual.set_cnp("1971209075425") individual.set_id(1) individual.set_first_name("Petre") individual.set_last_name("Vasile") individual.set_phone_number("0745321784") individual.set_email_address("*****@*****.**") item = BillItem() currency = Currency("$", "Dollar", "USD") item.set_id(1) item.set_currency(currency) item.set_name("McChicken") item.set_description("Chicken hamburger") item.set_price(2) item.set_discount(0) bill = Bill() bill.set_customer(individual) bill.set_currency(currency) bill.set_items([item]) bill.set_id(1) bill.set_total(item.get_price()) bill.set_issuer(company) bill.set_issue_date("24.01.2021") bill.set_due_date("10.02.2021") bill.set_notes("Platiti la Banca Transilvania") bill2 = copy.deepcopy(bill) bill2.set_id(2) self.assertNotEqual(bill, bill2) bill2.set_id(bill.get_id()) currency2 = copy.deepcopy(currency) currency2.set_name("dollar") bill2.set_currency(currency2) self.assertNotEqual(bill, bill2) bill2.set_currency(bill.get_currency()) bill2.set_total(12.0) self.assertNotEqual(bill, bill2) bill2.set_total(bill.get_total()) bill2.set_notes("asdfg") self.assertNotEqual(bill, bill2) bill2.set_notes(bill.get_notes()) bill2.set_items([item, item]) self.assertNotEqual(bill, bill2) bill2.set_items(bill.get_items()) individual2 = copy.deepcopy(individual) individual2.set_cnp("1991212123456") bill2.set_customer(individual2) self.assertNotEqual(bill, bill2) bill2.set_customer(bill.get_customer()) company2 = copy.deepcopy(company) company2.set_last_name("Marcel") bill2.set_issuer(company2) self.assertNotEqual(bill, bill2) bill2.set_issuer(bill.get_issuer()) bill2.set_due_date("adsf") self.assertNotEqual(bill, bill2) bill2.set_due_date(bill.get_due_date()) bill2.set_issue_date("asdf") self.assertNotEqual(bill, bill2)
def test_bill_getters_and_setters(self): company = Company() company.set_company_name("La Geani") company.set_registration_number("RO0123") company.set_fiscal_no("0000231523647") company.set_email_address("*****@*****.**") company.set_first_name("Ion") company.set_last_name("Bogdan") company.set_phone_number("0752314567") company.set_fiscal_no("0000012345678") company.set_registration_number("RO01923") individual = Individual() individual.set_cnp("1971209075425") individual.set_id(1) individual.set_first_name("Petre") individual.set_last_name("Vasile") individual.set_phone_number("0745321784") individual.set_email_address("*****@*****.**") item = BillItem() currency = Currency("$", "Dollar", "USD") item.set_id(1) item.set_currency(currency) item.set_name("McChicken") item.set_description("Chicken hamburger") item.set_price(2) item.set_discount(0) bill = Bill() bill.set_customer(individual) bill.set_currency(currency) bill.set_items([item]) bill.set_id(1) bill.set_total(item.get_price()) bill.set_issuer(company) bill.set_issue_date("24.01.2021") bill.set_due_date("10.02.2021") bill.set_notes("Platiti la Banca Transilvania") self.assertEqual(bill.get_currency(), currency) self.assertEqual(bill.get_total(), 2) self.assertEqual(bill.get_issuer(), company) self.assertEqual(bill.get_items(), [item]) self.assertEqual(bill.get_notes(), "Platiti la Banca Transilvania") self.assertEqual(bill.get_issue_date(), "24.01.2021") self.assertEqual(bill.get_due_date(), "10.02.2021") self.assertEqual(bill.get_customer(), individual) bill.add_items(item) self.assertEqual(bill.get_items(), [item])
def create_individual(self): individual = Individual() individual.set_cnp(input("Cnp: ")) individual.set_first_name(input("First Name: ")) individual.set_last_name(input("Last Name: ")) individual.set_phone_number(input("Phone Number: ")) individual.set_email_address(input("Email Address: ")) address = input("Give address: ") county = input("Give county: ") postal_code = input("Give postal code: ") country = input("Give country: ") customer_address = Address() customer_address.set_address(address) customer_address.set_county(county) customer_address.set_country(country) customer_address.set_postal_code(postal_code) individual.set_address(address) return individual