本文整理汇总了Python中term2048.board.Board.filled方法的典型用法代码示例。如果您正苦于以下问题:Python Board.filled方法的具体用法?Python Board.filled怎么用?Python Board.filled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类term2048.board.Board
的用法示例。
在下文中一共展示了Board.filled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBoard
# 需要导入模块: from term2048.board import Board [as 别名]
# 或者: from term2048.board.Board import filled [as 别名]
class TestBoard(unittest.TestCase):
def setUp(self):
self.b = Board()
# == init == #
def test_init_dimensions(self):
self.assertEqual(len(self.b.cells), Board.SIZE)
self.assertEqual(len(self.b.cells[0]), Board.SIZE)
if Board.SIZE > 1:
self.assertEqual(len(self.b.cells[1]), Board.SIZE)
def test_init_dimensions_1(self):
b = Board(size=1)
c = b.cells[0][0]
self.assertTrue(c in [2, 4])
def test_init_dimensions_3_goal_4(self):
b = Board(size=3, goal=4)
self.assertEqual(b.size(), 3)
def test_init_only_two_tiles(self):
t = 0
for x in xrange(Board.SIZE):
for y in xrange(Board.SIZE):
c = self.b.cells[y][x]
if not c == 0:
t += 1
else:
self.assertEqual(c, 0, 'board[%d][%d] should be 0' % (y, x))
self.assertEqual(t, 2)
def test_init_not_won(self):
self.assertFalse(self.b.won())
def test_init_not_filled(self):
self.assertFalse(self.b.filled())
# == .size == #
def test_size(self):
s = 42
b = Board(size=s)
self.assertEqual(b.size(), s)
# == .won == #
def test_won(self):
self.b._Board__won = True
self.assertTrue(self.b.won())
self.b._Board__won = False
self.assertFalse(self.b.won())
# == .canMove == #
def test_canMove_no_empty_cell(self):
b = Board(size=1)
b.setCell(0, 0, 42)
self.assertFalse(b.canMove())
def test_canMove_empty_cell(self):
b = Board(size=2)
self.assertTrue(b.canMove())
def test_canMove_no_empty_cell_can_collapse(self):
b = Board(size=2)
b.cells = [
[2, 2],
[4, 8]
]
self.assertTrue(b.canMove())
# == .filled == #
def test_filled(self):
self.b.cells = [[1]*Board.SIZE for _ in xrange(Board.SIZE)]
self.assertTrue(self.b.filled())
# == .addTile == #
def test_addTile(self):
b = Board(size=1)
b.cells = [[0]]
b.addTile(value=42)
self.assertEqual(b.cells[0][0], 42)
# == .getCell == #
def test_getCell(self):
x, y = 3, 1
v = 42
self.b.cells[y][x] = v
self.assertEqual(self.b.getCell(x, y), v)
# == .setCell == #
def test_setCell(self):
x, y = 2, 3
v = 42
self.b.setCell(x, y, v)
self.assertEqual(self.b.cells[y][x], v)
# == .getLine == #
def test_getLine(self):
b = Board(size=4)
l = [42, 17, 12, 3]
#.........这里部分代码省略.........