本文整理汇总了Python中Model.Model.map_copy方法的典型用法代码示例。如果您正苦于以下问题:Python Model.map_copy方法的具体用法?Python Model.map_copy怎么用?Python Model.map_copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.Model
的用法示例。
在下文中一共展示了Model.map_copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestModel
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import map_copy [as 别名]
class TestModel(TestCase):
def setUp(self):
self.subject = Subject()
self.model = Model(self.subject, 4, 4, 0.5)
self.model.map = [
[1, 0, 0, 1],
[0, 0, 1, 0],
[1, 0, 1, 0],
[0, 0, 1, 1],
]
def test_map_copy(self):
backup = self.model.map_copy()
backup[0] = [0, 1, 1, 0]
self.assertEqual(self.model.map[0],
[1, 0, 0, 1], 'Should not change after update backup')
backup[0][1] = 1
self.assertEqual(self.model.map[0][1],
0, 'Should not change after update backup')
def test_count_neighbours(self):
self.assertEqual(self.model.count_neighbours(1, 1, self.model.map_copy()),
4, 'Should return the correct number of neighbours')
self.assertEqual(self.model.count_neighbours(0, 0, self.model.map_copy()),
2, 'Should return the correct number of neighbours')
def test_update(self):
self.model.update()
self.assertEqual(self.model.round, 1, 'Should go to next round')
self.assertEqual(self.model.map, [
[1, 1, 0, 0],
[1, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
], 'Should update map correctly')