本文整理汇总了Python中field.Field.is_correct方法的典型用法代码示例。如果您正苦于以下问题:Python Field.is_correct方法的具体用法?Python Field.is_correct怎么用?Python Field.is_correct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field.Field
的用法示例。
在下文中一共展示了Field.is_correct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FieldTests
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import is_correct [as 别名]
class FieldTests(unittest.TestCase):
def setUp(self):
self.__x = random.randint(2, 128)
self.__y = random.randint(2, 128)
self.__field = Field(self.__y, self.__x)
def test_zero(self):
self.assertFalse(Field(0, 0).is_correct(0, 0))
def test_size(self):
self.assertEqual(self.__field.x, self.__x)
self.assertEqual(self.__field.y, self.__y)
def test_basic(self):
n = random.random()
x = random.randint(0, self.__x - 1)
y = random.randint(0, self.__y - 1)
self.__field[y][x] = n
self.assertEqual(self.__field[y][x], n)
def test_border(self):
self.__field[0][0] = 0
self.__field[self.__y - 1][self.__x - 1] = 0
def test_method_is_correct(self):
x = random.randint(0, self.__x - 1)
y = random.randint(0, self.__y - 1)
self.assertTrue(self.__field.is_correct(0, 0))
self.assertTrue(self.__field.is_correct(y, x))
self.assertTrue(not self.__field.is_correct(-1, 0))
self.assertTrue(not self.__field.is_correct(0, -1))
self.assertTrue(not self.__field.is_correct(self.__y, 0))
self.assertTrue(not self.__field.is_correct(0, self.__x))
示例2: __init__
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import is_correct [as 别名]
def __init__(self, field: Field, x: int, y: int):
self._neighbor = {'grass': 0, 'herbivore': 0, 'carnivore': 0}
if not field.is_correct(y, x):
raise IndexError
for dx, dy in [(0, 0), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1)]:
cx = x + dx
cy = y + dy
if not field.is_correct(cy, cx):
continue
self._neighbor['grass'] += field[cy][cx].get_grass()
self._neighbor['herbivore'] += field[cy][cx].get_herbivore()
self._neighbor['carnivore'] += field[cy][cx].get_carnivore()