本文整理汇总了Python中cube.Cube.foreach_cell方法的典型用法代码示例。如果您正苦于以下问题:Python Cube.foreach_cell方法的具体用法?Python Cube.foreach_cell怎么用?Python Cube.foreach_cell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cube.Cube
的用法示例。
在下文中一共展示了Cube.foreach_cell方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CubeTest
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import foreach_cell [as 别名]
class CubeTest(unittest.TestCase):
""" Tests the Cube class """
TEST_CUBE_DIMENSION = 3
def setUp(self):
self.cube = Cube(CubeTest.TEST_CUBE_DIMENSION)
def tearDown(self):
pass
def testCellCount(self):
self.assertEquals(CubeTest.TEST_CUBE_DIMENSION
* CubeTest.TEST_CUBE_DIMENSION
* CubeTest.TEST_CUBE_DIMENSION,
len(self.cube.get_cells()))
def __awakenCell(self, cell):
cell.state = Cell.LIVE
def testForeachCellAndStateChange(self):
for cell in self.cube.get_cells():
self.assertEquals(Cell.DEAD, cell.state)
self.cube.foreach_cell(self.__awakenCell)
for cell in self.cube.get_cells():
self.assertEquals(Cell.LIVE, cell.state)
示例2: random_red
# 需要导入模块: from cube import Cube [as 别名]
# 或者: from cube.Cube import foreach_cell [as 别名]
Created on 29 nov. 2010
@author: Terranca
'''
from cube import Cube
from cells import red_cell
from random import random
def random_red(cell):
if random() > 0.8:
cell = red_cell.RedCell(copy=cell)
return cell
def update(cube):
""" Progress the cube one time-tick
"""
for cell in cube.get_cells():
cube.set_cell(cell.location, cell.tick())
def get_colors(cube):
for cell in cube.get_cells():
print cell.COLOR
if __name__ == '__main__':
cube = Cube(7)
cube.foreach_cell(random_red)
#update(cube)
get_colors(cube)
print 'Number of cells: %d' % len(cube.get_cells())