Best Python code snippet using keyboard
test_broker.py
Source:test_broker.py
1import unittest2from gym_trading.utils.broker import Broker3from gym_trading.utils.decorator import debugging4from gym_trading.utils.order import LimitOrder, MarketOrder5class MarketOrderTestCases(unittest.TestCase):6 @debugging7 def test_case_one(self):8 print('\nTest_Case_One')9 test_position = Broker()10 midpoint = 100.11 fee = .00312 order_open = MarketOrder(ccy='BTC-USD', side='long', price=midpoint, step=1)13 test_position.add(order=order_open)14 self.assertEqual(1, test_position.long_inventory.position_count)15 print('LONG Unrealized_pnl: %f' % test_position.long_inventory.get_unrealized_pnl(16 price=midpoint))17 self.assertEqual(0, test_position.short_inventory.position_count)18 self.assertEqual(0., test_position.short_inventory.get_unrealized_pnl(19 price=midpoint))20 order_close = MarketOrder(ccy='BTC-USD', side='long',21 price=midpoint + (midpoint * fee * 5), step=100)22 test_position.remove(order=order_close)23 self.assertEqual(0, test_position.long_inventory.position_count)24 print('LONG Unrealized_pnl: %f' % test_position.long_inventory.get_unrealized_pnl(25 price=midpoint))26 self.assertEqual(test_position.short_inventory.position_count, 0)27 self.assertEqual(28 test_position.short_inventory.get_unrealized_pnl(price=midpoint), 0.)29 print('LONG Realized_pnl: %f' % test_position.realized_pnl)30 @debugging31 def test_case_two(self):32 print('\nTest_Case_Two')33 test_position = Broker()34 midpoint = 100.35 fee = .00336 order_open = MarketOrder(ccy='BTC-USD', side='short', price=midpoint, step=1)37 test_position.add(order=order_open)38 self.assertEqual(1, test_position.short_inventory.position_count)39 self.assertEqual(0, test_position.long_inventory.position_count)40 self.assertEqual(0., test_position.long_inventory.get_unrealized_pnl(41 price=midpoint))42 print(43 'SHORT Unrealized_pnl: %f' % test_position.short_inventory.get_unrealized_pnl(44 price=midpoint))45 order_close = MarketOrder(ccy='BTC-USD', side='short',46 price=midpoint - (midpoint * fee * 15), step=100)47 test_position.remove(order=order_close)48 self.assertEqual(0, test_position.short_inventory.position_count)49 self.assertEqual(0, test_position.long_inventory.position_count)50 self.assertEqual(0., test_position.long_inventory.get_unrealized_pnl(51 price=midpoint))52 print(53 'SHORT Unrealized_pnl: %f' % test_position.short_inventory.get_unrealized_pnl(54 price=midpoint))55 print('SHORT Realized_pnl: %f' % test_position.realized_pnl)56 @debugging57 def test_case_three(self):58 print('\nTest_Case_Three')59 test_position = Broker(5)60 midpoint = 100.61 for i in range(10):62 order_open = MarketOrder(ccy='BTC-USD', side='long', price=midpoint - i, step=i)63 test_position.add(order=order_open)64 self.assertEqual(5, test_position.long_inventory.position_count)65 self.assertEqual(0, test_position.short_inventory.position_count)66 print('Confirm we have 5 positions: %i' % test_position.long_inventory.position_count)67 for i in range(10):68 order_open = MarketOrder(ccy='BTC-USD', side='long', price=midpoint + i, step=i)69 test_position.remove(order=order_open)70 self.assertEqual(0, test_position.long_inventory.position_count)71 self.assertEqual(0, test_position.short_inventory.position_count)72class LimitOrderTestCases(unittest.TestCase):73 @debugging74 def test_long_pnl(self):75 test_position = Broker()76 step = 077 bid_price = 101.78 ask_price = 102.79 buy_volume = 10080 sell_volume = 10081 pnl = 0.82 def walk_forward(pnl, step, bid_price, ask_price, buy_volume, sell_volume, down=True):83 for i in range(50):84 step += 185 if down:86 bid_price *= 0.9987 ask_price *= 0.9988 else:89 bid_price *= 1.0190 ask_price *= 1.0191 pnl, is_long_order_filled, is_short_order_filled = \92 test_position.step_limit_order_pnl(93 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,94 sell_volume=sell_volume, step=step)95 pnl += pnl96 if i % 10 == 0:97 print('bid_price={:.2f} | ask_price={:.2f}'.format(bid_price,98 ask_price))99 return step, bid_price, ask_price, buy_volume, sell_volume, pnl100 test_position.add(101 order=LimitOrder(ccy='BTC-USD', side='long', price=100., step=step,102 queue_ahead=1000))103 step, _, _, buy_volume, sell_volume, pnl = walk_forward(pnl, step, bid_price,104 ask_price, buy_volume,105 sell_volume, down=True)106 self.assertEqual(1, test_position.long_inventory_count)107 test_position.add(108 order=LimitOrder(ccy='BTC-USD', side='short', price=105., step=step,109 queue_ahead=0))110 _, _, _, _, _, pnl = walk_forward(pnl, step, bid_price, ask_price, buy_volume,111 sell_volume, down=False)112 realized_pnl = round(test_position.realized_pnl, 3)113 self.assertEqual(0.05, realized_pnl,114 "Expected Realized PnL of 0.5 and got {}".format(realized_pnl))115 self.assertEqual(0,116 test_position.short_inventory_count +117 test_position.long_inventory_count)118 print("PnL: {}".format(pnl))119 @debugging120 def test_avg_exe(self):121 test_position = Broker()122 # perform a partial fill on the first order123 step = 0124 bid_price = 101.125 ask_price = 102.126 buy_volume = 500127 sell_volume = 500128 test_position.add(129 order=LimitOrder(ccy='BTC-USD', side='long', price=bid_price, step=step,130 queue_ahead=0))131 print("taking first step...")132 step += 1133 pnl, is_long_order_filled, is_short_order_filled = \134 test_position.step_limit_order_pnl(135 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,136 sell_volume=sell_volume, step=step)137 pnl += pnl138 self.assertEqual(500, test_position.long_inventory.order.executed)139 self.assertEqual(0, test_position.long_inventory_count)140 # if order gets filled with a bid below the order's price, the order should NOT141 # receive any price improvement during the execution.142 bid_price = 99.143 ask_price = 100.144 test_position.add(145 order=LimitOrder(ccy='BTC-USD', side='long', price=bid_price, step=step,146 queue_ahead=0))147 print("taking second step...")148 step += 1149 pnl, is_long_order_filled, is_short_order_filled = \150 test_position.step_limit_order_pnl(151 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,152 sell_volume=sell_volume, step=step)153 pnl += pnl154 self.assertEqual(1, test_position.long_inventory_count)155 self.assertEqual(100., test_position.long_inventory.average_price)156 print("PnL: {}".format(pnl))157 @debugging158 def test_lob_queuing(self):159 test_position = Broker()160 # perform a partial fill on the first order161 step = 0162 bid_price = 102.163 ask_price = 103.164 buy_volume = 500165 sell_volume = 500166 queue_ahead = 800167 order_open = LimitOrder(ccy='BTC-USD', side='long', price=bid_price, step=step,168 queue_ahead=queue_ahead)169 test_position.add(order=order_open)170 step += 1171 pnl, is_long_order_filled, is_short_order_filled = \172 test_position.step_limit_order_pnl(173 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,174 sell_volume=sell_volume, step=step)175 pnl += pnl176 print("#1 long_inventory.order = \n{}".format(test_position.long_inventory.order))177 self.assertEqual(300, test_position.long_inventory.order.queue_ahead)178 self.assertEqual(0, test_position.long_inventory.order.executed)179 self.assertEqual(0, test_position.long_inventory_count)180 step += 1181 pnl, is_long_order_filled, is_short_order_filled = \182 test_position.step_limit_order_pnl(183 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,184 sell_volume=sell_volume, step=step)185 pnl += pnl186 print("#2 long_inventory.order = \n{}".format(test_position.long_inventory.order))187 self.assertEqual(200, test_position.long_inventory.order.executed)188 self.assertEqual(0, test_position.long_inventory_count)189 # if order gets filled with a bid below the order's price, the order should NOT190 # receive any price improvement during the execution.191 bid_price = 100.192 ask_price = 102.193 order_open = LimitOrder(ccy='BTC-USD', side='long', price=bid_price, step=step,194 queue_ahead=queue_ahead)195 test_position.add(order=order_open)196 print("#3 long_inventory.order = \n{}".format(test_position.long_inventory.order))197 self.assertEqual(0, test_position.long_inventory_count)198 bid_price = 100.199 for i in range(5):200 step += 1201 pnl, is_long_order_filled, is_short_order_filled = \202 test_position.step_limit_order_pnl(203 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,204 sell_volume=sell_volume, step=step)205 pnl += pnl206 self.assertEqual(1, test_position.long_inventory_count)207 self.assertEqual(100.40, round(test_position.long_inventory.average_price, 2))208 print("PnL: {}".format(pnl))209 @debugging210 def test_queues_ahead_features(self):211 test_position = Broker()212 # perform a partial fill on the first order213 step = 0214 bid_price = 100.215 ask_price = 200.216 buy_volume = 0217 sell_volume = 0218 order_open_long = LimitOrder(ccy='BTC-USD', side='long', price=bid_price,219 step=step, queue_ahead=0)220 order_open_short = LimitOrder(ccy='BTC-USD', side='short', price=ask_price,221 step=step, queue_ahead=2000)222 print('opening long position = {}'.format(order_open_long))223 test_position.add(order=order_open_long)224 print('opening short position = {}'.format(order_open_short))225 test_position.add(order=order_open_short)226 print('\ntaking first step...')227 step += 1228 pnl, is_long_order_filled, is_short_order_filled = \229 test_position.step_limit_order_pnl(230 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,231 sell_volume=sell_volume, step=step)232 pnl += pnl233 print("#1 long_inventory.order = \n{}".format(test_position.long_inventory.order))234 print(235 "#1 short_inventory.order = \n{}".format(test_position.short_inventory.order))236 bid_queue, ask_queue = test_position.get_queues_ahead_features()237 print("#1 get_queues_ahead_features:\nbid_queue={} || ask_queue={}".format(238 bid_queue, ask_queue))239 self.assertEqual(0., bid_queue)240 self.assertEqual(-0.67, round(ask_queue, 2))241 print('\ntaking second step...')242 buy_volume = 500243 sell_volume = 500244 step += 1245 pnl, is_long_order_filled, is_short_order_filled = \246 test_position.step_limit_order_pnl(247 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,248 sell_volume=sell_volume, step=step)249 pnl += pnl250 print("#2 long_inventory.order = \n{}".format(test_position.long_inventory.order))251 print(252 "#2 short_inventory.order = \n{}".format(test_position.short_inventory.order))253 bid_queue, ask_queue = test_position.get_queues_ahead_features()254 print("#2 get_queues_ahead_features:\nbid_queue={} || ask_queue={}".format(255 bid_queue, ask_queue))256 self.assertEqual(0.5, bid_queue)257 self.assertEqual(-0.6, round(ask_queue, 2))258 print('\ntaking third step...')259 buy_volume = 500260 sell_volume = 499261 step += 1262 pnl, is_long_order_filled, is_short_order_filled = \263 test_position.step_limit_order_pnl(264 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,265 sell_volume=sell_volume, step=step)266 pnl += pnl267 print("#3 long_inventory.order = \n{}".format(test_position.long_inventory.order))268 print(269 "#3 short_inventory.order = \n{}".format(test_position.short_inventory.order))270 bid_queue, ask_queue = test_position.get_queues_ahead_features()271 print("#3 get_queues_ahead_features:\nbid_queue={} || ask_queue={}".format(272 bid_queue, ask_queue))273 self.assertEqual(0.999, bid_queue)274 self.assertEqual(-0.5, round(ask_queue, 2))275 print('\ntaking fourth step...')276 buy_volume = 500277 sell_volume = 500278 step += 1279 pnl, is_long_order_filled, is_short_order_filled = \280 test_position.step_limit_order_pnl(281 bid_price=bid_price, ask_price=ask_price, buy_volume=buy_volume,282 sell_volume=sell_volume, step=step)283 pnl += pnl284 print("#4 long_inventory.order = \n{}".format(test_position.long_inventory.order))285 print(286 "#4 short_inventory.order = \n{}".format(test_position.short_inventory.order))287 bid_queue, ask_queue = test_position.get_queues_ahead_features()288 print("#4 get_queues_ahead_features:\nbid_queue={} || ask_queue={}".format(289 bid_queue, ask_queue))290 self.assertEqual(0.0, bid_queue)291 self.assertEqual(-0.33, round(ask_queue, 2))292 print("PnL: {}".format(pnl))293if __name__ == '__main__':...
tetris.py
Source:tetris.py
1import sys2import copy3from PyQt5 import QtGui4from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QMainWindow, QApplication, QMessageBox5from PyQt5.QtCore import QTimer, Qt6from random import choice7class Window(QMainWindow):8 def __init__(self):9 super(Window, self).__init__()10 # initialize values11 self.rows = 2012 self.columns = 1013 self.point_piece = 1014 self.points_line = 10015 self.label = {}16 self.score = 017 self.lines = 018 self.board = []19 self.game_running = False20 self.message = "New game is loaded"21 # set title22 self.setWindowTitle("Tetris")23 # set icon24 self.setWindowIcon(QtGui.QIcon('favicon.png'))25 # load page at startup26 self.main_page()27 # set timer event28 self.timer = QTimer()29 self.timer.timeout.connect(self.timer_event)30 # start game31 self.start_game()32 def main_page(self):33 # create central widget34 central_widget = QWidget()35 self.setCentralWidget(central_widget)36 # horizontal layout with 2 columns, later we can add scores,... in the other column37 horizontal_layout = QHBoxLayout(central_widget)38 horizontal_layout.setSpacing(50)39 # layout board (playing field)40 vertical_board = QVBoxLayout()41 horizontal_layout.addLayout(vertical_board)42 for row in range(0, self.rows):43 horizontal_board = QHBoxLayout()44 horizontal_board.setSpacing(0)45 for column in range(0, self.columns):46 self.label[row, column] = QLabel(self)47 self.label[row, column].setFixedHeight(40)48 self.label[row, column].setFixedWidth(40)49 self.label[row, column].setStyleSheet("background-color:lightGrey;border: 1px inset darkGrey")50 horizontal_board.addWidget(self.label[row, column])51 vertical_board.addLayout(horizontal_board)52 vertical_board.setSpacing(0)53 # display everything54 self.show()55 # set screen to fixed size56 self.setFixedSize(self.size())57 58 def start_game(self):59 # initialization60 self.score = 061 self.lines = 062 self.board = []63 self.init_board()64 # add first piece to board65 self.add_new_piece()66 # display piece on board67 self.update_piece()68 # display existing lines on the board69 self.update_board()70 # game running is used for Pause, if False=>Pause is active71 self.game_running = True72 def delete_piece(self):73 # delete piece on board (draw in default color)74 sheet = "background-color:lightGrey;border: 1px inset darkGrey"75 origin_rows, origin_columns = self.new_piece.get_origin()76 for item in self.new_piece.get_relative_positions():77 self.label[origin_rows+item[0], origin_columns+item[1]].setStyleSheet(sheet)78 def update_piece(self):79 # display piece on board80 sheet = "background-color:" + self.new_piece.get_color() + ";border: 1px inset darkGrey"81 origin_rows, origin_columns = self.new_piece.get_origin()82 for item in self.new_piece.get_relative_positions():83 self.label[origin_rows+item[0], origin_columns+item[1]].setStyleSheet(sheet)84 def check_move_down(self):85 ''' moving down is something special, if we can't move further down, the piece is in its final position.86 Now we need to copy the piece to the board, check for full lines and check if the game is over.87 The game is over when the newly added piece is in (partly) in the same position as a piece that is already on88 the board '''89 self.delete_piece()90 # check if the piece can move further down91 if self.new_piece.move_down(self.rows, self.columns, self.board):92 # if the piece has reached its final position93 self.add_piece_to_board()94 self.check_full_lines()95 self.add_new_piece()96 self.update_piece()97 self.update_board()98 # check when the board is full99 test_position = copy.deepcopy(self.new_piece.piece)100 test_position[4][0] += 1101 if self.new_piece.check_existing_pieces(test_position, self.board) is False:102 self.game_over()103 # otherwise we just update the piece104 self.update_piece()105 def timer_event(self):106 if self.game_running is True:107 self.check_move_down()108 def keyPressEvent(self, event):109 pressedkey = event.key()110 if pressedkey == Qt.Key_P:111 if self.game_running is True:112 self.game_running = False113 else:114 self.game_running = True115 event.accept()116 if self.game_running is True:117 if pressedkey == Qt.Key_Up:118 self.delete_piece()119 self.new_piece.rotate(self.rows, self.columns, self.board)120 self.update_piece()121 event.accept()122 elif pressedkey == Qt.Key_Down:123 self.check_move_down()124 event.accept()125 elif pressedkey == Qt.Key_Left:126 self.delete_piece()127 self.new_piece.move_left(self.rows, self.columns, self.board)128 self.update_piece()129 event.accept()130 elif pressedkey == Qt.Key_Right:131 self.delete_piece()132 self.new_piece.move_right(self.rows, self.columns, self.board)133 self.update_piece()134 event.accept()135 else:136 event.ignore()137 def add_new_piece(self):138 # add new piece to board139 self.score += self.point_piece140 self.update_statusbar()141 self.new_piece = Piece()142 def init_board(self):143 ''' create an empty list of list with None values, as soon as a piece is in it's final position,144 the color is added to the list'''145 for row in range(self.rows):146 line = [None]*self.columns147 self.board.append(line)148 def add_piece_to_board(self):149 # the piece is in its final position and the color of the piece is added to the board150 origin_rows, origin_columns = self.new_piece.get_origin()151 for item in self.new_piece.get_relative_positions():152 self.board[item[0]+origin_rows][item[1]+origin_columns] = self.new_piece.get_color()153 def update_board(self):154 # draw the values of the board155 for counter_row, row in enumerate(self.board):156 for counter_column, column in enumerate(row):157 if column is not None:158 sheet = "background-color:"+column+";border: 1px inset darkGrey"159 self.label[counter_row, counter_column].setStyleSheet(sheet)160 else:161 sheet = "background-color:lightGrey;border: 1px inset darkGrey"162 self.label[counter_row, counter_column].setStyleSheet(sheet)163 def check_full_lines(self):164 # a line is full when all the values in the list have a color value (not None)165 counter_row = self.rows-1166 # we start checking the board from the bottom to the top167 for row in reversed(self.board):168 if None not in row:169 for i in range(counter_row):170 self.board[counter_row-i] = copy.deepcopy(self.board[counter_row-1-i])171 self.board[0] = [None]*self.columns172 self.check_full_lines()173 self.score += self.points_line174 self.lines += 1175 self.update_statusbar()176 counter_row -= 1177 def update_statusbar(self):178 speed = int(1000*(1-(self.lines//5/10)))179 self.message = 'Score:' + str(self.score) + ' Number of lines:'+str(self.lines)180 self.statusBar().showMessage(self.message)181 self.timer.start(speed)182 def game_over(self):183 # stop the game184 self.game_running = False185 # create 'Game over' messagebox with score,etc186 game_over = QMessageBox()187 game_over.setIcon(QMessageBox.Information)188 game_over.setText("Game over")189 game_over.setInformativeText("Score: "+str(self.score)+'\nNumber of lines: '+str(self.lines))190 game_over.setWindowTitle("Game over")191 game_over.setStandardButtons(QMessageBox.Ok)192 game_over.buttonClicked.connect(self.start_game)193 game_over.exec_()194class Piece:195 def __init__(self):196 '''197 T shape198 long199 square200 L right201 L left202 S shape203 Z shape204 '''205 shapes = [[[0, -1], [0, 0], [0, 1], [1, 0], [0, 4], 'cyan'],206 [[0, -1], [0, 0], [0, 1], [0, 2], [0, 4], 'red'],207 [[0, 0], [0, 1], [1, 0], [1, 1], [0, 4], 'blue'],208 [[0, -1], [0, 0], [0, 1], [1, 1], [0, 4], 'green'],209 [[0, -1], [0, 0], [0, 1], [1, -1], [0, 4], 'magenta'],210 [[0, -1], [0, 0], [1, 0], [1, 1], [0, 4], 'yellow'],211 [[1, -1], [1, 0], [0, 0], [0, 1], [0, 4], 'black'],212 ]213 self.piece = choice(shapes)214 def __str__(self):215 return 'Positions: {}, {}, {}, {}, Origin: {}, Color: {}'.format(self.piece[0], self.piece[1], self.piece[2], self.piece[3], self.piece[4], self.piece[5])216 def __repr__(self):217 return 'Piece: '+str(self.piece)218 def move_down(self, rows, columns, board):219 test_position = copy.deepcopy(self.piece)220 test_position[4][0] += 1221 if self.check_position(test_position, rows, columns) and self.check_existing_pieces(test_position, board):222 self.piece = copy.deepcopy(test_position)223 else:224 return True225 def move_right(self, rows, columns, board):226 test_position = copy.deepcopy(self.piece)227 test_position[4][1] += 1228 if self.check_position(test_position, rows, columns):229 if self.check_existing_pieces(test_position, board):230 self.piece = copy.deepcopy(test_position)231 def move_left(self, rows, columns, board):232 test_position = copy.deepcopy(self.piece)233 test_position[4][1] -= 1234 if self.check_position(test_position, rows, columns):235 if self.check_existing_pieces(test_position, board):236 self.piece = copy.deepcopy(test_position)237 def rotate(self, rows, columns, board):238 if self.piece[-1] != 'blue':239 test_position = copy.deepcopy(self.piece)240 for item in test_position[:-2]:241 item[0], item[1] = item[1], -item[0]242 if self.check_position(test_position, rows, columns):243 if self.check_existing_pieces(test_position, board):244 self.piece = copy.deepcopy(test_position)245 def check_position(self, test_position, rows, columns):246 origin_rows = test_position[-2][0]247 origin_columns = test_position[-2][1]248 for item in test_position[:-2]:249 if origin_columns+item[1] < 0:250 return False251 elif origin_columns+item[1] > columns-1:252 return False253 elif origin_rows+item[0] < 0:254 return False255 elif origin_rows+item[0] > rows-1:256 return False257 return True258 def check_existing_pieces(self, test_position, board):259 origin_rows = test_position[-2][0]260 origin_columns = test_position[-2][1]261 for item in test_position[:-2]:262 if board[origin_rows+item[0]][origin_columns+item[1]] is not None:263 return False264 return True265 def get_origin(self):266 return self.piece[-2][0], self.piece[-2][1]267 def get_color(self):268 return self.piece[-1]269 def get_relative_positions(self):270 return self.piece[:-2]271if __name__ == '__main__':272 app = QApplication(sys.argv)273 ex = Window()...
board_position_test.py
Source:board_position_test.py
1#!/usr/bin/env python32#pylint: disable=import-error3"""4Project: TicTacToe - class exercise, OOPs version5"""6from tictactoe.classes.board_position import BoardPosition7from tictactoe.classes.game_board import GameBoard8from tictactoe.classes.player import Player9class BoardPositionTest:10 """11 Board Position test harness.12 """13 test_board = GameBoard()14 test_player = Player('X', True)15 def init_corners_test(self):16 """17 Test the creation of the corner positions.18 """19 corner_idxs = [0, 2, 6, 8]20 for idx in corner_idxs:21 test_position = BoardPosition(idx, self.test_board.BOARD_WIDTH)22 assert test_position.is_corner()23 assert test_position.is_available_corner()24 assert not test_position.is_marked()25 assert test_position.position_display == str(idx + 1)26 def init_non_corners_test(self):27 """28 Test the creation of the non-corner positions.29 """30 non_corner_idxs = [1, 3, 4, 5, 7]31 for idx in non_corner_idxs:32 test_position = BoardPosition(idx, self.test_board.BOARD_WIDTH)33 assert not test_position.is_available_corner()34 assert not test_position.is_corner()35 assert not test_position.is_marked()36 assert test_position.is_available()37 assert test_position.position_display == str(idx + 1)38 def init_center_position_test(self):39 """40 Test that instantiation of a game board correctly instantiates41 the center position.42 """43 test_center_position = BoardPosition(4, self.test_board.BOARD_WIDTH)44 center_position = self.test_board.get_center_position()45 assert test_center_position.position_display ==\46 center_position.position_display47 def marked_by_test(self):48 """49 Test indicating that a player has selected (AKA marked) a position.50 """51 test_position = BoardPosition(4, self.test_board.BOARD_WIDTH)52 test_position.set_marked_by(self.test_player)53 assert not test_position.is_available()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!