def setUp(self): self.conn = connection.get(**s.get('test_db')) self.test_table = Table('Test') self.test_table.connection = self.conn # create test table sql = """ CREATE TABLE Test( c1 INT PRIMARY KEY, c2 VARCHAR(50) NOT NULL, c3 DATETIME NOT NULL, c4 BIT NOT NULL ) """ cursor = self.conn.cursor() cursor.execute(sql) # insert records into Test table sql = """ INSERT INTO Test(c1, c2, c3, c4) VALUES (?, ?, ?, ?) """ self.records = [ [i, 'test{}'.format(i), datetime.now(), True] for i in range(1, 11) ] cursor.executemany(sql, self.records) cursor.close() self.conn.commit()
def lab_1(): # the path of the atoms table file ATOMS_FILE_PATH = '../data/atoms.txt' # the path of the file to be analyzed and executed SOURCE_FILE_PATH = '../data/p1.txt' # separators file path SEPARATORS_FILE_PATH = '../data/separators.txt' # Reading the source file with open(SOURCE_FILE_PATH, 'r') as input_file: # content = the content of the source file which will be analyzed & executed content = input_file.read() # Reading the symbol table atoms_table = Table() with open(ATOMS_FILE_PATH) as atoms_file: for index, line in enumerate(atoms_file): atoms_table.put(line.strip(), index) # Reading the separators separators = [] with open(SEPARATORS_FILE_PATH, 'r') as input_file: for line in input_file: separators.append(line.strip()) internal_program_form, id_symbol_table, const_symbol_table = lexical_analyze( content, atoms_table, separators) print('Internal program form:\n' + str(internal_program_form)) print('Id table:\n' + str(id_symbol_table)) print('Const table:\n' + str(const_symbol_table))
def __init__(self): super().__init__() # tables self.category = Table('GroupKala', _('Category')) self.category_map = Table('CategoryMap', _('CategoryMap')) # woocommerce api self.woocommerce = wc.get(wc_api.get(), 'products/categories')
def test_check_insert(self): fields = [Field('id', 'int', primary_key=True), Field('name', 'str')] table = Table('users', fields) table.insert(id=1, name='Pierre') self.assertTrue(len(table.values) == 1)
class Restaurant: def __init__(self): self.__customer_number = 0 self.__table = Table(20) self.__cook = Cook() self.waiting = [] self.food_name = {1: "스테이크", 2: "스파게티", 3: "마카로니", 4: "그라탱"} self.cooking_time = {1: 30, 2: 20, 3: 10, 4: 15} self.eating_time = {1: 30, 2: 20, 3: 15, 4: 10} self.time = 0 def new_customer(self): time = randrange(15, 41) if not self.__table.is_waitable(waitable_time=time, waiting_amount=len(self.waiting)): Printer.add( f'손님이 기다릴 수 없어 돌아갑니다. 현재대기시간 {self.__table.waitable_time}분 / 대기가능시간 {time}분' ) return self.__customer_number += 1 self.waiting.append(self.__customer_number) Printer.add( f'{self.__customer_number}번째 손님이 시각 {self.time}분에 레스토랑에 도착했습니다.') def update(self): self.__table.update() self.__cook.update() sittable = self.__table.empty() while self.waiting and sittable: table_num, food_num = sittable.pop(0), randrange(1, 5) info = CustomerInfo(self.waiting.pop(0), table_num, food_num) cooking_time = self.cooking_time[food_num] total_time = self.__cook.waiting_time( ) + self.eating_time[food_num] + cooking_time self.__cook.order_time.append(cooking_time) self.__table.table[table_num] = Customer( info, self.eating_time[food_num], total_time) Printer.add( f'{info[0]}번 손님이 {info[1]}번 테이블에 앉습니다. {info[2]}번 요리({self.food_name[info[2]]})를 주문합니다.' ) def run(self): Printer.init() period = 2 self.time = 1 while self.time < 721: Printer.add(f'[현재시각 : {self.time}분]') is_remained = self.time % period if not is_remained: self.new_customer() self.update() Printer.output() self.time += 1
def test_get_state_method_works_correct_in_all_cells_alive_condition(self): # given table = Table(3, 3) # then self.assertEqual( table.get_state(), [[True, True, True], [True, True, True], [True, True, True]])
def test_if_size_of_input_state_not_suit_size_of_table_then_raise_exception( self): # given table = Table(3, 3) state = [[True]] with self.assertRaises(ValueError): table.set_state(state)
def test_check_no_exception_if_nullable_field_missing(self): fields = [ Field('id', 'int', primary_key=True), Field('name', 'str'), Field('age', 'int', nullable=True) ] table = Table('users', fields) table.insert(id=5, name='Pierre')
def test_get_num_of_alive_neighbor_works_correct_if_location_is_not_on_the_border( self): # given table = Table(3, 3) state = [[True, False, True], [True, False, True], [True, False, True]] # when table.set_state(state) # then self.assertEqual(table.num_of_alive_neighbor(1, 1), 6)
def test_set_state_method_works_correct_if_given_correct_state(self): # given table = Table(3, 3) state = [[True, False, True], [True, False, True], [True, False, True]] # when table.set_state(state) # then self.assertEqual(table.get_state(), state)
def __init__(self): self.__customer_number = 0 self.__table = Table(20) self.__cook = Cook() self.waiting = [] self.food_name = {1: "스테이크", 2: "스파게티", 3: "마카로니", 4: "그라탱"} self.cooking_time = {1: 30, 2: 20, 3: 10, 4: 15} self.eating_time = {1: 30, 2: 20, 3: 15, 4: 10} self.time = 0
class Game: def __init__(self): player1 = Player(0, 'Winston') player1.small_blind = True player2 = bot(1, 'Adolf') player2.big_blind = True player3 = bot(2, 'Franklin') player4 = bot(3, 'Joseph') player5 = bot(4, 'Benito') self.status = "dude" self.is_starting = True self.table = Table([player1, player2, player3, player4, player5]) self.is_dead = False def start_game(self): ans = self.table.change_blind() self.table.take_blind(ans[0], ans[1]) self.table.take_cards() self.table.pre_flop() self.table.flop() #{self.status = "player_turn" self.status = "game_cards_taken" #self.status = "bot_turn" #if self.table.playerturn: self.status = "player_turn"
def export_this_table(self, table_name: str, table_metadata: dict): """ Export the contents of a particular table to a csv text file. :param table_name: :param table_metadata: :return: """ self.env.msg.info(f"Exporting table '{table_name}' from group '{table_metadata['group']}'") table = Table(self.env, table_name, table_metadata) self.env.msg.debug(table.export_filepath) table.export()
def __init__(self): player1 = Player(0, 'Winston') player1.small_blind = True player2 = bot(1, 'Adolf') player2.big_blind = True player3 = bot(2, 'Franklin') player4 = bot(3, 'Joseph') player5 = bot(4, 'Benito') self.status = "dude" self.is_starting = True self.table = Table([player1, player2, player3, player4, player5]) self.is_dead = False
def test_get_with_non_matching_search(self): field = mock.Mock(spec=Field) field.primary_key = True table = Table('users', [field]) table.values = [{ 'id': 1, 'name': 'Pascal' }, { 'id': 2, 'name': 'Martine' }] self.assertEqual(table.get_with_values(name='José'), [])
def test_instanciation_with_bad_primary_key_config(self): fields = [Field('name', 'str')] # No primary key with self.assertRaises(Exception): table = Table('table_name', [Field('name', 'str')]) # Several primary keys with self.assertRaises(Exception): table = Table('table_name', [ Field('id_1', 'int', primary_key=True), Field('id_2', 'int', primary_key=True) ])
def move(self, unit=1): ''' Move command ''' if self._is_on_table: x_y_vec = Table.calc_x_y_vec(self._direction) new_x = self._x + x_y_vec[0]*unit new_y = self._y + x_y_vec[1]*unit if not Table.is_within_boundary(new_x, new_y): # Ignore movement if move outside boundary of the table return self._x = new_x self._y = new_y
class TestParseInput(): ''' This class will be used to test the ParseInput. ''' parse_input = ParseInput() table = Table() #used for thorough testing robot = ToyRobot(table) #used for thorough testing full way through def test_place_parse(self): ''' Testing the 'place' command. checking if it returns the expected ''' cmd = self.parse_input.parse("place 1,2,east") assert cmd.value == "place" assert cmd.args == ["1", "2", "east"] def test_case_insensitive_place(self): ''' Ensuring the place command is case insensitive ''' cmd = self.parse_input.parse("PLaCE 1,2,EaST") assert cmd.value == "place" assert cmd.args == ["1", "2", "east"] def test_move_parse(self): ''' Testing if the 'move' command is successfully parsed as expected ''' cmd = self.parse_input.parse("move") assert cmd.value == "move" def test_thorough_move_robot(self): ''' This test will be a thorough test, with a few different components to see if they all work well together ''' cmd = self.parse_input.parse("place 1,2,east") cmd.execute(self.robot) ## check the parse assert cmd.value == "place" assert cmd.args == ["1", "2", "east"] ## check the robot assert self.robot.coordinate == Coordinate(1,2) assert self.robot.direction == Direction("east") def test_cmd_not_found(self): ''' This function aims to test an invalid command ''' with pytest.raises(CommandNotFoundError): cmd = self.parse_input.parse("autocomplete_code")
def test_if_init_state_is_not_given_then_set_all_cell_to_alive(self): # given table = Table(3, 3) # then for row in table._cells: self.assertTrue(all(cell.state for cell in row))
def setUp(self): table = Table(200) self.player = MartingalePlayer(table) self.player.stake = 100 wheel = Wheel(NonRandom()) # bin_builder = BinBuilder() # bin_builder.build_bins(wheel) self.game = Game(wheel, table)
def setUp(self): table = Table(100) rng = NonRandom() wheel = Wheel(rng) self.game = Game(wheel, table) self.player = MartingalePlayer(table) self.player.stake = 1000 self.player.rounds_to_go = 10 self.outcomes = [Outcome("Black", 1), Outcome("Red", 1)]
def init(self): self.table = Table(20) for i, time in zip(range(1, 21), self.time_data): self.table.table[i] = Customer(CustomerInfo(number=i, table=i, food=1), eating_time=0, total_time=time) self.table.table[i].eating = True return self.table
def setUp(self): table = Table(100) rng_wheel = NonRandom() wheel = Wheel(rng_wheel) self.initial_player_stake = 1000 self.table = table self.game = Game(wheel, table) self.player = PlayerFibonacci(table) self.player.stake = self.initial_player_stake self.player.rounds_to_go = 1 self.outcomes = [Outcome("Black", 1), Outcome("Red", 1)]
def setUp(self): table = Table(100) rng = NonRandom() wheel = Wheel(rng) self.inital_player_stake = 1000 self.table = table self.game = Game(wheel, table) self.player = SevenRedsPlayer(table) self.player.stake = self.inital_player_stake self.player.rounds_to_go = 10 self.outcomes = Outcome("Black", 1)
def place(self, x, y, direction): ''' Place command ''' if not Table.is_within_boundary(int(x), int(y)): return if not self._is_on_table: self._is_on_table = True self._x = int(x) self._y = int(y) self._direction = direction.upper()
def __init__(self): super(Root, self).__init__() self._keyboard = Window.request_keyboard(self._keyboard_closed, self) self._keyboard.bind(on_key_down=self._on_keyboard_down) self.my_table = Table() self.my_table.cols = 2 self.my_table.label_panel.labels[ 0].text = "Description" # heading text self.my_table.label_panel.labels[1].text = "Category" # heading text self.add_widget(self.my_table) self.load_table()
def setUp(self): table = Table(100) rng_wheel = NonRandom() wheel = Wheel(rng_wheel) rng_player = NonRandom() self.initial_player_stake = 1000 self.table = table self.game = Game(wheel, table) self.player = RandomPlayer(table, rng_player) self.player.stake = self.initial_player_stake self.player.rounds_to_go = 10 possible_outcomes = [] for bin in wheel.bin_iterator(): for outcome in bin: possible_outcomes.append(outcome) self.player.set_possible_outcomes(possible_outcomes)
def test_table_next_state_correct_in_case_2(self): # given # X X X X X X X X # X O O X => X O O X # X O O X X O O X # X X X X X X X X table = Table(4, 4) state = [[False, False, False, False], [False, True, True, False], [False, True, True, False], [False, False, False, False]] table.set_state(state) # when table.next() # then self.assertEqual(table.get_state(), state)
def test_table_next_state_correct_in_case_1(self): # given # X O X X X X # X O X => O O O # X O X X X X table = Table(3, 3) state = [[False, True, False], [False, True, False], [False, True, False]] table.set_state(state) # when table.next() # then self.assertEqual( table.get_state(), [[False, False, False], [True, True, True], [False, False, False]])
def build_this_table(self, table_name: str, table_metadata: dict): self.env.msg.info(f"Building table '{table_name}' from data in group '{table_metadata['group']}'") table = Table(self.env, table_name, table_metadata) self.env.msg.debug(table.ddl_filepath) self.env.msg.debug(table.data_filepath) if os.path.isfile(table.data_filepath): table.create_table() table.populate_table() else: self.env.msg.warning([ f"'{table_name}.csv' not found in '{table_metadata['group']}'", 'No changes have been made to the existing table structure or data.' ])