def testDifferentHeightBoardsHasMultipleEntries(self): self.board1 = Board(8,8) self.board2 = Board(8,9) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 2, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 1, 'Entry for board1 should be 1') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be 2')
def testSameMemoryObjectSinglePiecesBoardEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) self.board1.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('h1', white_rook) self.assertEqual(self.board1, self.board2, 'Boards are set up the same')
class TestNearlyEmptyBoard(unittest.TestCase): def setUp(self): self.board = Board() def test_is_empty(self): self.board[(0, 0)] = 'X' self.assertFalse(self.board.is_empty(0, 0)) def test_is_occupied(self): self.board[(0, 0)] = 'X' self.assertTrue(self.board.is_occupied(0, 0))
class TestCornersSidesAndCenter(unittest.TestCase): def setUp(self): self.board = Board('\n'.join(['XOX', 'O O', 'XOX'])) def test_corners(self): self.assertEqual(self.board.corners().values().count('X'), 4) def test_sides(self): self.assertEqual(self.board.sides().values().count('O'), 4) def test_center(self): self.assertEqual(self.board.center().values(), [' '])
def testSameMemoryObjectSinglePiecesBoardDictEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) self.board1.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('h1', white_rook) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 1, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 2, 'Entry for board1 should be same as entry for board2 (2)') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be same as entry for board1 (2)')
def testSameMemoryObjectMultiplePiecesBoardEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) white_queen = Queen(colors.WHITE) black_pawn = Pawn(colors.BLACK) self.board1.set_square_to_piece('h1', white_rook) self.board1.set_square_to_piece('c3', white_queen) self.board1.set_square_to_piece('e7', black_pawn) self.board2.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('c3', white_queen) self.board2.set_square_to_piece('e7', black_pawn) self.assertEqual(self.board1, self.board2, 'Boards are set up the same')
def new_board(self, board_name): """ Create a new board with name *board_name*. :param board_name: The name you want the board to have. :returns: A Board class, with name attribute *board_name*. """ return Board(board_name)
class TestOpposite(unittest.TestCase): def setUp(self): self.board = Board(''' 123 456 789 ''') def test_upper_left_and_lower_right_corners(self): coords = (0, 0) self.assertEqual(self.board[coords], '1') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '9') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '1') def test_upper_right_and_lower_left_corners(self): coords = (2, 0) self.assertEqual(self.board[coords], '3') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '7') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '3') def test_upper_and_lower_sides(self): coords = (1, 0) self.assertEqual(self.board[coords], '2') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '8') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '2') def test_left_and_right_sides(self): coords = (0, 1) self.assertEqual(self.board[coords], '4') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '6') coords = self.board.opposite(*coords) self.assertEqual(self.board[coords], '4') def test_center(self): self.assertEqual((1, 1), self.board.opposite(1, 1))
def get_board(self, board_name): """ Get the board that has the name *board_name*. :param board_name: The name of the board you want to get. :returns: A Board class, with Board.board populated with board data. """ board_data = self._operator.get_board(board_name) return Board(board_name, board_data)
class TestEmptyBoard(unittest.TestCase): def setUp(self): self.board = Board() def test_getitem(self): for x in xrange(3): for y in xrange(3): self.assertEqual(self.board[(x, y)], ' ') def test_setitem(self): for x in xrange(3): for y in xrange(3): self.board[(x, y)] = 'X' self.assertEqual(self.board[(x, y)], 'X') def test_out_of_bounds(self): for x in range(-2, 0) + range(3, 5): for y in range(-2, 0) + range(3, 5): with self.assertRaises(IndexError): self.board[(x, y)] = 'X' def test_is_out_of_bounds(self): for x in range(-2, 0) + range(3, 5): for y in range(-2, 0) + range(3, 5): self.assertTrue(self.board.is_out_of_bounds(x, y)) def test_iter(self): self.assertTrue(all(cell == ' ' for (coords, cell) in self.board)) def test_contains(self): self.assertTrue(' ' in self.board) self.assertFalse('X' in self.board) self.assertFalse('O' in self.board) def test_is_empty(self): self.assertTrue(all(self.board.is_empty(x, y) for x in xrange(3) for y in xrange(3))) def test_is_occupied(self): self.assertFalse(any(self.board.is_occupied(x, y) for x in xrange(3) for y in xrange(3)))
class TestLines(unittest.TestCase): def setUp(self): self.board = Board('\n'.join(['XXX', 'OOO', 'ZZZ'])) def test_horizontals(self): self.assertItemsEqual(self.board.horizontals().values(), (('X', 'X', 'X'), ('O', 'O', 'O'), ('Z', 'Z', 'Z'))) def test_verticals(self): self.assertItemsEqual(self.board.verticals().values(), (('X', 'O', 'Z'), ('X', 'O', 'Z'), ('X', 'O', 'Z'))) def test_diagonals(self): self.assertItemsEqual(self.board.diagonals().values(), (('X', 'O', 'Z'), ('X', 'O', 'Z')))
def __init__(self, screen): # Config self.tps = 60.00 # Initialization pygame.init() self.screen = screen self._clock = pygame.time.Clock() self._delta = 0.0 self.If_not_next = True self.win = None self.txt = None self.number_level = 0 self.lev = Board(self.number_level) for enemy in self.lev.enemy: enemy.take_level(self.lev) self.End = True self.player = gracz(self)
def level(self, number_of_level, nextlevel=False): if (nextlevel): self.lev = Board(number_of_level) for wall in self.lev.walls: self.screen.blit(wall.ImgWall, [wall.pos.x, wall.pos.y]) self.win = self.lev.nextLevel() self.screen.blit(self.win.my_exit, [self.win.pos.x, self.win.pos.y]) for cheese in self.lev.cheeses: self.screen.blit(cheese.img_cheese, [cheese.pos.x, cheese.pos.y]) for trap in self.lev.traps: self.screen.blit(trap.img_trap, [trap.pos.x, trap.pos.y]) for door in self.lev.doors: self.screen.blit(door.img_door, [door.pos.x, door.pos.y]) for triger in self.lev.trigers: self.screen.blit(triger.img_door, [triger.pos.x, triger.pos.y]) for enemy in self.lev.enemy: enemy.take_level(self.lev) self.player.update_level(self.lev, self.win, self.lev.positon_of_gamer)
class TestTextualRepresentation(unittest.TestCase): def setUp(self): self.text = (''' XOX O O XOX ''') self.pretty_text = (''' +---+ |XOX| |O O| |XOX| +---+ ''') self.board = Board(self.text) def test_as_string(self): self.assertEqual('\n%s\n' % self.board.as_string(), self.text) def test_as_pretty_string(self): self.assertEqual('\n%s\n' % self.board.as_string(pretty=True), self.pretty_text)
def setUp(self): self.text = (''' XOX O O XOX ''') self.pretty_text = (''' +---+ |XOX| |O O| |XOX| +---+ ''') self.board = Board(self.text)
def testDifferentMemoryObjectMultiplePiecesBoardEqualityModify(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook1 = Rook(colors.WHITE) white_rook2 = Rook(colors.WHITE) white_queen1 = Queen(colors.WHITE) white_queen2 = Queen(colors.WHITE) black_pawn1 = Pawn(colors.BLACK) black_pawn2 = Pawn(colors.BLACK) self.board1.set_square_to_piece('h1', white_rook1) self.board1.set_square_to_piece('c3', white_queen1) self.board2.set_square_to_piece('h1', white_rook2) self.board2.set_square_to_piece('c3', white_queen2) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') self.board1.set_square_to_piece('e7', black_pawn1) self.board2.set_square_to_piece('e7', black_pawn2) self.assertEqual(self.board1, self.board2, 'Boards are set up the same')
def create_board(grid, size): """ This function puts the four attributes of each vehicle in an array and loads them into the class board """ vehicles = [] for count in range(len(grid)): if size > 20: #with this number of cars, we can assume that we are dealing with a 9x9 or 12x12 x = Vehicle_2(int(grid[count][0]), int(grid[count][1]), int(grid[count][2]), int(grid[count][3])) vehicles.append(x) else: x = Vehicle(int(grid[count][0]), int(grid[count][1]), int(grid[count][2]), int(grid[count][3])) vehicles.append(x) new_board = Board(vehicles) return new_board
def setUp(self): self.board = Board('\n'.join(['XOX', 'O O', 'XOX']))
def setUp(self): self.board = Board()
class TestCoordinateToAlgebraicConversions(unittest.TestCase): def setUp(self): self.board = Board(8,8) def tearDown(self): pass def testConvertCoordinateToAlgebraicSquare(self): letters = ['a','b','c','d','e','f','g','h'] for i in range(8): for j in range(8): alg = '%s%s' % (letters[i], j+1) conv = self.board.coordinate_to_algebraic_square((j,i)) self.assertEqual(alg, conv, '%s should be %s' % (conv, alg)) def testConvertAlgebraicToCoordinateSquare(self): letters = ['a','b','c','d','e','f','g','h'] for i in range(len(letters)): for j in range(8): coords = (j,i) conv = self.board.algebraic_to_coordinate_square('%s%s' % (letters[i], j+1)) self.assertEqual(conv, coords, '%s should be %s' % (conv, coords)) def testConvertCoordinateToAlgebraicMoveOnly(self): self.board.pieces[(0,6)] = Knight(colors.WHITE) knight = self.board.get_coordinate_piece_tuple(0,6) f3 = self.board.get_coordinate_piece_tuple(2,5) correct_move = 'Nf3' converted_move = self.board.coordinate_to_algebraic_move(f3, knight) self.assertEqual(correct_move, converted_move, 'Move notation %s should be %s' % (converted_move, correct_move)) def testConvertCoordinateToAlgebraicMoveOnlyPawn(self): self.skipTest('Not implemented') def testConvertCoordinateToAlgebraicWithCapture(self): self.board.pieces[(0,7)] = Rook(colors.WHITE) self.board.pieces[(3,7)] = Pawn(colors.BLACK) rook = self.board.get_coordinate_piece_tuple(0,7) pawn = self.board.get_coordinate_piece_tuple(3,7) correct_move = 'Rxh4' converted_move = self.board.coordinate_to_algebraic_move(pawn, rook) self.assertEqual(correct_move, converted_move, 'Move notation %s should be %s' % (converted_move, correct_move)) def testConvertCoordinateToAlgebraicWithCapturePawn(self): self.skipTest('Not implemented') def testConvertCoordinateToAlgebraicWithAmbiguousMove(self): self.skipTest('Not implemented') def testConvertCoordinateToAlgebraicWithAmbiguousCapture(self): self.skipTest('Not implemented') def testConvertCoordinateToAlgebraicEnPassant(self): self.skipTest('Not implemented') def testConvertCoordinateToAlgebraicPawnPromotion(self): self.skipTest('Not implemented')
def testDifferentWidthBoardsAreNotEqual(self): self.board1 = Board(8,8) self.board2 = Board(9,8) self.assertNotEqual(self.board1, self.board2, 'Boards widths are different size')
class Game: def __init__(self, screen): # Config self.tps = 60.00 # Initialization pygame.init() self.screen = screen self._clock = pygame.time.Clock() self._delta = 0.0 self.If_not_next = True self.win = None self.txt = None self.number_level = 0 self.lev = Board(self.number_level) for enemy in self.lev.enemy: enemy.take_level(self.lev) self.End = True self.player = gracz(self) def gameLoop(self, number_level=0): while self.End: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: pygame.quit() sys.exit(0) # Ticking self._delta += self._clock.tick() / 1000 while self._delta > 1 / self.tps: self.tick() self._delta -= 1 / self.tps if self.If_not_next: self.screen.background_color(color.lightsteelblue()) self.level(number_level) self.draw() if self.txt != None: x, y = self.screen.getSizeScreen self.screen.blit(self.txt, [x / 2, y / 2]) if self.End: self.screen.refresh else: self.number_level += 1 self.level(self.number_level, True) self.If_not_next = True # del(self.player) self.screen.refresh def tick(self): self.player.tick() for enemy in self.lev.enemy: enemy.tick() #self.lev.player(self.player) def draw(self): self.player.draw() for enemy in self.lev.enemy: image, polozenie = enemy.draw() self.screen.blit(image, polozenie) def level(self, number_of_level, nextlevel=False): if (nextlevel): self.lev = Board(number_of_level) for wall in self.lev.walls: self.screen.blit(wall.ImgWall, [wall.pos.x, wall.pos.y]) self.win = self.lev.nextLevel() self.screen.blit(self.win.my_exit, [self.win.pos.x, self.win.pos.y]) for cheese in self.lev.cheeses: self.screen.blit(cheese.img_cheese, [cheese.pos.x, cheese.pos.y]) for trap in self.lev.traps: self.screen.blit(trap.img_trap, [trap.pos.x, trap.pos.y]) for door in self.lev.doors: self.screen.blit(door.img_door, [door.pos.x, door.pos.y]) for triger in self.lev.trigers: self.screen.blit(triger.img_door, [triger.pos.x, triger.pos.y]) for enemy in self.lev.enemy: enemy.take_level(self.lev) self.player.update_level(self.lev, self.win, self.lev.positon_of_gamer) def next_level(self): self.If_not_next = False def player_death(self): tekst = Statement("GAME OVER!", "Verdena", 50, (0, 0, 0)) # print(self.screen.getSizeScreen) self.txt = tekst.draw self.screen.refresh self.End = False
from dl_cmdline import DisplayLegacyCmdline logging.basicConfig(filename="log", format="[%(lineno)d]%(asctime)s:%(levelname)s:%(message)s", level=logging.DEBUG) if __name__ == "__main__": if len(sys.argv) > 1: if os.path.exists(sys.argv[1]): cfg = config.Config(sys.argv[1]) else: # Change it so it at least tries to read default path/values first. print("Invalid configuration file path.") cfg = config.Config() else: cfg = config.Config() board = Board(config=cfg) c = config.Colors() # terminal colors object marker = Marker() dl = DisplayLegacy(cfg, board, c, marker) # Command line legacy interface - used by default if cfg.display_legacy in ("True", "true"): screen = DisplayLegacyCmdline(board, c, cfg, dl, marker) screen.run() # urwid GUI else: screen = display.Display(cfg, board) screen.run()
def __init__(self): self.name = input("What's your name captain? ") self.board = Board() self.attempted_shots = []
def __init__(self): # 初始化 pygame.init() pygame.display.set_caption("Seva") self.settings = Settings() self.screen = pygame.display.set_mode( (self.settings.screen_width, self.settings.screen_height)) self.screen.fill(self.settings.bg_color) self.screen_rect = self.screen.get_rect() self.screen_height = self.screen.get_height() self.screen_width = self.screen.get_width() # 进入与退出选择标志 self.option_type = 2 # 当前图片绘制标志 self.screen_type = 0 # 主题选择标志 self.theme_type = 0 self.theme_read() self.door = Door(self) self.rains = Group() self.character = Character(self) self.polluted = Polluted(self) self.score = Score(self.screen) self.rains_drop = True self.rain_height = 0 self.grasses1 = Group() self.grasses1.add(Grass(self.screen, 1000, 460)) self.grasses1.add(Grass(self.screen, 100, 160)) self.grasses1.add(Grass(self.screen, 1150, 675)) self.grasses1.add(Grass(self.screen, 100, 675)) self.grasses1.add(Grass(self.screen, 150, 675)) self.grasses1.add(Grass(self.screen, 200, 675)) self.grasses2 = Group() self.grasses2.add(Grass(self.screen, 800, 400)) self.boards1 = [ Board(self.screen, 100, 40, 1000, 500), Board(self.screen, 40, 40, 600, 500), Board(self.screen, 200, 20, 650, 600), Board(self.screen, 200, 40, 300, 380), Board(self.screen, 200, 40, 80, 200), Board(self.screen, 150, 45, 650, 200), Board(self.screen, 200, 50, 1000, 100) ] self.boards2 = [ Board(self.screen, 300, 20, 800, 600), Board(self.screen, 100, 40, 500, 550), Board(self.screen, 50, 20, 900, 250), # 炸弹右 Board(self.screen, 30, 10, 250, 450), # 炸弹左 Board(self.screen, 80, 10, 170, 450, True), Board(self.screen, 250, 20, 500, 350), Board(self.screen, 200, 40, 1000, 100), Board(self.screen, 200, 10, 100, 200) ] self.boards3 = [ Board(self.screen, 150, 40, 800, 600), Board(self.screen, 400, 20, 500, 450), Board(self.screen, 400, 20, 100, 250), Board(self.screen, 100, 40, 650, 170), Board(self.screen, 500, 40, 900, 250), Board(self.screen, 200, 50, 1000, 100) ] self.boards4 = [ Board(self.screen, 400, 30, 450, 600), Board(self.screen, 150, 20, 600, 450), Board(self.screen, 300, 20, 400, 300), Board(self.screen, 100, 10, 300, 170), Board(self.screen, 80, 10, 620, 150), Board(self.screen, 300, 40, 900, 400), Board(self.screen, 200, 50, 1000, 100) ] self.boards = self.boards1 self.polluted_up = False
def testDifferentHeightBoardsAreNotEqual(self): self.board1 = Board(8,8) self.board2 = Board(8,9) self.assertNotEqual(self.board1, self.board2, 'Boards heights are different size')
def setUp(self): """This method sets up default board and cell to use for the tests""" self.board = Board(8, 8) self.cell = Cell((2, 4), self.board)
def setUp(self): self.board = Board('\n'.join(['XXX', 'OOO', 'ZZZ']))
def setUp(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.d = {}
def setUp(self): self.board = Board(''' 123 456 789 ''')
class TestBoardEqualityAndHashing(unittest.TestCase): def setUp(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.d = {} def tearDown(self): pass def testFullBoardEquality(self): self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testFullAndEmptyBoardInequality(self): self.board2.clear_board() self.assertNotEqual(self.board1, self.board2, 'Boards are not set up the same') def testSameMemoryObjectSinglePiecesBoardEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) self.board1.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('h1', white_rook) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testDifferentMemoryObjectSinglePiecesBoardEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook1 = Rook(colors.WHITE) white_rook2 = Rook(colors.WHITE) self.board1.set_square_to_piece('h1', white_rook1) self.board2.set_square_to_piece('h1', white_rook2) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testSameMemoryObjectMultiplePiecesBoardEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) white_queen = Queen(colors.WHITE) black_pawn = Pawn(colors.BLACK) self.board1.set_square_to_piece('h1', white_rook) self.board1.set_square_to_piece('c3', white_queen) self.board1.set_square_to_piece('e7', black_pawn) self.board2.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('c3', white_queen) self.board2.set_square_to_piece('e7', black_pawn) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testDifferentMemoryObjectMultiplePiecesBoardEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook1 = Rook(colors.WHITE) white_rook2 = Rook(colors.WHITE) white_queen1 = Queen(colors.WHITE) white_queen2 = Queen(colors.WHITE) black_pawn1 = Pawn(colors.BLACK) black_pawn2 = Pawn(colors.BLACK) self.board1.set_square_to_piece('h1', white_rook1) self.board1.set_square_to_piece('c3', white_queen1) self.board1.set_square_to_piece('e7', black_pawn1) self.board2.set_square_to_piece('h1', white_rook2) self.board2.set_square_to_piece('c3', white_queen2) self.board2.set_square_to_piece('e7', black_pawn2) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testSameMemoryObjectMultiplePiecesBoardEqualityModify(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) white_queen = Queen(colors.WHITE) black_pawn = Pawn(colors.BLACK) self.board1.set_square_to_piece('h1', white_rook) self.board1.set_square_to_piece('c3', white_queen) self.board2.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('c3', white_queen) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') self.board1.set_square_to_piece('e7', black_pawn) self.board2.set_square_to_piece('e7', black_pawn) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testDifferentMemoryObjectMultiplePiecesBoardEqualityModify(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook1 = Rook(colors.WHITE) white_rook2 = Rook(colors.WHITE) white_queen1 = Queen(colors.WHITE) white_queen2 = Queen(colors.WHITE) black_pawn1 = Pawn(colors.BLACK) black_pawn2 = Pawn(colors.BLACK) self.board1.set_square_to_piece('h1', white_rook1) self.board1.set_square_to_piece('c3', white_queen1) self.board2.set_square_to_piece('h1', white_rook2) self.board2.set_square_to_piece('c3', white_queen2) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') self.board1.set_square_to_piece('e7', black_pawn1) self.board2.set_square_to_piece('e7', black_pawn2) self.assertEqual(self.board1, self.board2, 'Boards are set up the same') def testDifferentSizedBoardsAreNotEqual(self): self.board1 = Board(8,8) self.board2 = Board(9,9) self.assertNotEqual(self.board1, self.board2, 'Boards are different dimensions') def testDifferentWidthBoardsAreNotEqual(self): self.board1 = Board(8,8) self.board2 = Board(9,8) self.assertNotEqual(self.board1, self.board2, 'Boards widths are different size') def testDifferentHeightBoardsAreNotEqual(self): self.board1 = Board(8,8) self.board2 = Board(8,9) self.assertNotEqual(self.board1, self.board2, 'Boards heights are different size') def testDictWithEqualBoardsHasOneEntry(self): self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 1, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 2, 'Entry for board1 should be same as entry for board2 (2)') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be same as entry for board1 (2)') def testDictWithNotEqualBoardsHasMultipleEntries(self): self.board1.clear_board() self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 2, 'Dict should only have two entries') self.assertEqual(self.d[self.board1], 1, 'Entry for board1 should be 1') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be 2') def testSameMemoryObjectSinglePiecesBoardDictEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook = Rook(colors.WHITE) self.board1.set_square_to_piece('h1', white_rook) self.board2.set_square_to_piece('h1', white_rook) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 1, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 2, 'Entry for board1 should be same as entry for board2 (2)') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be same as entry for board1 (2)') def testDifferentMemoryObjectSinglePiecesBoardDictEquality(self): self.board1 = ClassicBoard() self.board2 = ClassicBoard() self.board1.clear_board() self.board2.clear_board() white_rook1 = Rook(colors.WHITE) white_rook2 = Rook(colors.WHITE) self.board1.set_square_to_piece('h1', white_rook1) self.board2.set_square_to_piece('h1', white_rook2) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 1, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 2, 'Entry for board1 should be same as entry for board2 (2)') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be same as entry for board1 (2)') def testDictWithDifferentSizedBoardsHasMultipleEntries(self): self.board1 = Board(8,8) self.board2 = Board(9,9) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 2, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 1, 'Entry for board1 should be 1') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be 2') def testDictDifferentWidthBoardsHasMultipleEntries(self): self.board1 = Board(8,8) self.board2 = Board(9,8) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 2, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 1, 'Entry for board1 should be 1') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be 2') def testDifferentHeightBoardsHasMultipleEntries(self): self.board1 = Board(8,8) self.board2 = Board(8,9) self.d[self.board1] = 1 self.d[self.board2] = 2 self.assertEqual(len(self.d), 2, 'Dict should only have a single entry') self.assertEqual(self.d[self.board1], 1, 'Entry for board1 should be 1') self.assertEqual(self.d[self.board2], 2, 'Entry for board2 should be 2')
with open(conf_path, 'w') as f: json.dump(defaults, f, indent=4) cfg = Config(conf_path) else: # Or just go with default /etc/sshchan.conf. with open("/etc/sshchan.conf", 'w') as f: json.dump(defaults, f, indent=4) cfg = Config() print("Creating directories and files...") print("rootdir: {}".format(cfg.root)) print("boardlist: {}".format(cfg.boardlist_path)) print("postnums: {}".format(cfg.postnums_path)) print("motd: {}".format(cfg.motd)) print("boards: {}".format(os.path.join(cfg.root, "boards"))) try: os.makedirs(cfg.root) os.makedirs(os.path.join(cfg.root, "boards")) except FileExistsError: pass cfg.set_boardlist({}) cfg.set_postnums({}) print("Creating default board /meta/...") meta = Board("meta", "Meta discussion", cfg) print("All done. Run admin.py to modify and administer your textboard, or dive\ straight in with sshchan.py!") sys.exit(0)
def testDifferentSizedBoardsAreNotEqual(self): self.board1 = Board(8,8) self.board2 = Board(9,9) self.assertNotEqual(self.board1, self.board2, 'Boards are different dimensions')