python测试,为什么测试文件的那7,10两行没有覆盖
本帖最后由 kofii 于 2020-3-6 20:28 编辑待测试代码:
# -*- coding: utf-8 -*-
#
# @author Epsirom
import random
class GameMap(object):
"""
The game map, contains a lot of cells.
Each cell has a value, 0 means it is a dead/empty cell, and 1 means it is a live cell.
Attributes:
size:
"""
MAX_MAP_SIZE = 100
MAX_CELL_VALUE = 1
DIRECTIONS = (
(0, 1, ),
(0, -1, ),
(1, 0, ),
(-1, 0, ),
(1, 1),
(1, -1),
(-1, 1),
(-1, -1)
)
def __init__(self, rows, cols):
"""Inits GameMap with row and column count."""
if not isinstance(rows, int):
raise TypeError("rows should be int")
if not isinstance(cols, int):
raise TypeError("cols should be int")
assert 0 < rows <= self.MAX_MAP_SIZE
assert 0 < cols <= self.MAX_MAP_SIZE
self.size = (rows, cols, )
self.cells = [ for row in range(rows)]
@property
def rows(self):
"""获取行数"""
return self.size
测试代码:
from unittest import TestCase
from game_map import GameMap
class TestGameMap(TestCase):
def setUp(self):
self.game_map = GameMap(4, 3)
def test_rows(self):
self.assertEqual(4,self.game_map.rows,"yes")
已经百度了一天了,实在不知道怎么解决 想问问你的注释呢,看的脑阔能
这么多def
页:
[1]