def __init__(self, frame, window): super().__init__(frame) Title(master=self, text="Exemplul 3") SubTitle(master=self, text="G₁") Text(master=self, text=get_result(epsilon, h, 3, 1)) SubTitle(master=self, text="G₂") Text(master=self, text=get_result(epsilon, h, 3, 2)) Button(master=self, text="Mergi inapoi", command=lambda: window.show_frame(Menu))
def test_empty_transactions(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:00:00', 'USD', 'GBP', '0.71'), ('2018-04-01 01:02:00', 'EUR', 'GBP', '1.62'), ('2018-04-01 05:22:00', 'EUR', 'HUF', '0.062'), ]) assert get_result(conn, 'GBP') == []
def test_transactions_without_timestamp(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:20:00', 'USD', 'GBP', '1.5'), ]) db_data(conn, 'transactions', [ (None, 2, 'USD', '2'), ]) assert get_result(conn, 'GBP') == []
def test_exchange_rate_to_gbp_without_rate(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:00:00', 'USD', 'GBP', None), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:30:00', 2, 'USD', 2.45), ]) assert get_result(conn, 'GBP') == []
def test_exchange_rates_for_given_transactions_are_absent( self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 23:00:00', 'USD', 'GBP', '1.5'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:30:00', 2, 'USD', 2.45), ]) assert get_result(conn, 'GBP') == []
def test_transactions_to_gbp_without_amount(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:20:00', 'USD', 'GBP', '1.5'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:30:00', 3, 'GBP', None), ]) expected = [ (3, round_number_to_decimal(0, 3)), ] assert get_result(conn, 'GBP') == expected
def test_use_equal_exchange_rate_timestamp(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:19:59', 'USD', 'GBP', '2.5'), ('2018-04-01 00:20:00', 'USD', 'GBP', '1.5'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:20:00', 3, 'USD', '2'), ]) expected = [ (3, round_number_to_decimal(2 * 1.5, 3)), ] assert get_result(conn, 'GBP') == expected
def res(request): path = f"tests/{request.param}" with open(os.path.join(path, "gpu_location.txt"), "r") as f: gpu_flag = f.readline() has_dedicated_gpu = False gpu_in_cpu = False if gpu_flag == "cpu": gpu_in_cpu = True elif gpu_flag == "gpu": has_dedicated_gpu = True return get_result(directory=path, has_dedicated_gpu=has_dedicated_gpu, gpu_in_cpu=gpu_in_cpu, gui=False)
def test_initial_data(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:00:00', 'USD', 'GBP', '0.71'), ('2018-04-01 00:00:05', 'USD', 'GBP', '0.82'), ('2018-04-01 00:01:00', 'USD', 'GBP', '0.92'), ('2018-04-01 01:02:00', 'USD', 'GBP', '0.62'), ('2018-04-01 02:00:00', 'USD', 'GBP', '0.71'), ('2018-04-01 03:00:05', 'USD', 'GBP', '0.82'), ('2018-04-01 04:01:00', 'USD', 'GBP', '0.92'), ('2018-04-01 04:22:00', 'USD', 'GBP', '0.62'), ('2018-04-01 00:00:00', 'EUR', 'GBP', '1.71'), ('2018-04-01 01:00:05', 'EUR', 'GBP', '1.82'), ('2018-04-01 01:01:00', 'EUR', 'GBP', '1.92'), ('2018-04-01 01:02:00', 'EUR', 'GBP', '1.62'), ('2018-04-01 02:00:00', 'EUR', 'GBP', '1.71'), ('2018-04-01 03:00:05', 'EUR', 'GBP', '1.82'), ('2018-04-01 04:01:00', 'EUR', 'GBP', '1.92'), ('2018-04-01 05:22:00', 'EUR', 'GBP', '1.62'), ('2018-04-01 05:22:00', 'EUR', 'HUF', '0.062'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:00:00', 1, 'EUR', 2.45), ('2018-04-01 01:00:00', 1, 'EUR', 8.45), ('2018-04-01 01:30:00', 1, 'USD', 3.5), ('2018-04-01 20:00:00', 1, 'EUR', 2.45), ('2018-04-01 00:30:00', 2, 'USD', 2.45), ('2018-04-01 01:20:00', 2, 'USD', 0.45), ('2018-04-01 01:40:00', 2, 'USD', 33.5), ('2018-04-01 18:00:00', 2, 'EUR', 12.45), ('2018-04-01 18:01:00', 3, 'GBP', 2), ('2018-04-01 00:01:00', 4, 'USD', 2), ('2018-04-01 00:01:00', 4, 'GBP', 2), ]) expected = [ (1, round_number_to_decimal( 2.45 * 1.71 + 8.45 * 1.71 + 3.5 * 0.62 + 2.45 * 1.62, 3)), (2, round_number_to_decimal( 2.45 * 0.92 + 0.45 * 0.62 + 33.5 * 0.62 + 12.45 * 1.62, 3)), (3, round_number_to_decimal(2 * 1, 3)), (4, round_number_to_decimal(2 * 0.92 + 2 * 1, 3)), ] assert get_result(conn, 'GBP') == expected
def test_closest_exchange_rate_has_empty_rate_then_work_with_the_next_closest_not_empty_rate( self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:00:00', 'USD', 'GBP', '1.5'), ('2018-04-01 00:50:00', 'USD', 'GBP', None), ]) db_data(conn, 'transactions', [ ('2018-04-01 01:20:00', 2, 'USD', 0.4), ]) expected = [ (2, round_number_to_decimal(0.4 * 1.5, 3)), ] assert get_result(conn, 'GBP') == expected
def test_transactions_only_to_gbp(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:20:00', 'USD', 'GBP', '1.5'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:30:00', 3, 'GBP', '2'), ('2018-04-01 00:35:00', 3, 'GBP', '3'), ('2018-04-01 00:45:00', 2, 'GBP', '4'), ]) expected = [ (2, round_number_to_decimal(4 * 1, 3)), (3, round_number_to_decimal((2 + 3) * 1, 3)), ] assert get_result(conn, 'GBP') == expected
def test_several_exchange_rates_with_the_same_timestamp( self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:20:00', 'USD', 'GBP', '1.5'), ('2018-04-01 00:20:00', 'EUR', 'GBP', '2.5'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:30:00', 3, 'USD', '2'), ('2018-04-01 00:35:00', 2, 'EUR', '3'), ]) expected = [ (2, round_number_to_decimal(3 * 2.5, 3)), (3, round_number_to_decimal(2 * 1.5, 3)), ] assert get_result(conn, 'GBP') == expected
def test_exchange_rates_to_gbp_are_absent(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: db_data(conn, 'exchange_rates', [ ('2018-04-01 00:00:00', 'USD', 'EUR', '0.71'), ('2018-04-01 01:02:00', 'EUR', 'HUF', '1.62'), ('2018-04-01 05:22:00', 'EUR', 'HUF', '0.062'), ]) db_data(conn, 'transactions', [ ('2018-04-01 00:00:00', 1, 'EUR', 2.45), ('2018-04-01 00:30:00', 2, 'USD', 2.45), ('2018-04-01 01:20:00', 2, 'USD', 0.45), ('2018-04-01 18:01:00', 3, 'GBP', 2), ]) expected = [ (2, round_number_to_decimal(0, 3)), (3, round_number_to_decimal(2 * 1, 3)), ] assert get_result(conn, 'GBP') == expected
def test_more_than_one_way(self): self.assertEqual(get_result(GRID, 'CSEE'), True) self.assertEqual(get_result(GRID, 'CSEC'), True) self.assertEqual(get_result(GRID, 'SECB'), True) self.assertEqual(get_result(GRID, 'SEED'), True) self.assertEqual(get_result(GRID, 'SECC'), True)
def test_negative_already_used_letters(self): self.assertEqual(get_result(GRID, 'ABA'), False) self.assertEqual(get_result(GRID, 'FDF'), False)
def test_negative_one_letter(self): self.assertEqual(get_result(GRID, 'Q'), False) self.assertEqual(get_result(GRID, 'W'), False)
def test_positive_one_letter(self): self.assertEqual(get_result(GRID, 'A'), True) self.assertEqual(get_result(GRID, 'C'), True) self.assertEqual(get_result(GRID, 'E'), True)
def test_negative_diagonale(self): self.assertEqual(get_result(GRID, 'AF'), False) self.assertEqual(get_result(GRID, 'FE'), False)
def test_negative_from_first_letter(self): self.assertEqual(get_result(GRID, 'ABCEQ'), False) self.assertEqual(get_result(GRID, 'ASAW'), False)
def test_positive_from_first_letter(self): self.assertEqual(get_result(GRID, 'ABCE'), True) self.assertEqual(get_result(GRID, 'ASA'), True) self.assertEqual(get_result(GRID, 'ASFC'), True) self.assertEqual(get_result(GRID, 'ASFCSEEDA'), True)
mondays = WeekdayLocator(MONDAY) # major ticks on the mondays alldays = DayLocator() # minor ticks on the days # weekFormatter = DateFormatter('%b %d') # e.g., Jan 12 dayFormatter = DateFormatter('%b %d') # e.g., 12 # Get historical data for ticker between date1 and date2. # quotes = quotes_historical_yahoo_ohlc('INTC', date1, date2) # if len(quotes) == 0: # raise SystemExit # with open('EURUSD240.csv', 'r') as csvfile: # datareader = list(csv.reader(csvfile)) import main datareader = main.get_result() def parse_time(date, hour): year, month, day = map(lambda x: int(x), date.split('.')) hour, minutes = map(lambda x: int(x), hour.split(':')) return datetime(year, month, day, hour, minutes) def parse(row): time = parse_time(row[0], row[1]) # print(time) return [date2num(time), float(row[2]), float(row[3]), float(row[4]), float(row[5])] datareader2 = [] for x in datareader: datareader2.append(parse(x))
def test_empty_transactions_and_exchange_rates(self, db_migrations, db_data): db_conn = db_migrations(settings.MIGRATION_INITIAL) with closing(db_conn) as conn: assert get_result(conn, 'GBP') == []
def test_1(): data = [ line for line in pathlib.Path("input_test1.txt").read_text().split("\n") ] assert get_result(data) == 37
def test_1(): data = [ line for line in pathlib.Path("input_test.txt").read_text().split("\n") ] assert get_result(data, preamble=5) == 127