2048小游戏测试用例
时间: 2023-12-09 09:35:59 浏览: 92
2048小游戏测试用例可以包括以下几个方面:
1.测试棋盘向左移动是否成功:
```python
if __name__ == "__main__":
try:
assert is_move_left([[0, 0, 0, 0], [0, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 4]]) == True, "棋盘向左移动失败"
except AssertionError as e:
print(e)
else:
print("棋盘向左移动测试用例完成.....")
```
2.测试行向左移动是否成功:
```python
if __name__ == "__main__":
try:
assert is_row_left([2, 2, 2, 2]) == True, '行向左移动失败'
assert is_row_left([2, 4, 2, 4]) == False, '行向左移动失败'
except AssertionError as e:
print(e)
else:
print("行向左移动测试用例完成.....")
```
3.测试棋盘是否能够成功翻转:
```python
if __name__ == '__main__':
try:
assert invert([[0, 0, 0, 0], [0, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 4]]) == [[0, 0, 0, 0], [0, 0, 2, 0], [0, 0, 0, 0], [4, 0, 0, 0]], '棋盘翻转失败'
except AssertionError as e:
print(e)
else:
print("棋盘翻转测试用例完成.....")
```
阅读全文