Пример #1
0
    def testCellNet_VC(self):
        cn = cellNet.SimpleCellTriangle([
            cell.IntegerCell('Cell A', 1),
            cell.IntegerCell('Cell B', 5),
            cell.IntegerCell('Cell C', 7)
        ])
        cnvc = cellNet.CellNet_VC(cn)
        self.assertEqual(str(cnvc), '\n0: 1\n1: 5\n2: 7')

        # Use mutate() and update() to change specific cells
        cnvc.mutateCell(0)
        self.assertEqual(str(cnvc), '\n0: 12\n1: 5\n2: 7')
        cnvc.updateCell(1, 10)
        self.assertEqual(str(cnvc), '\n0: 12\n1: 10\n2: 7')

        cnvc.play()
        cnvc.pause()
        self.assertEqual(str(cnvc), '\n0: 17\n1: 19\n2: 22')

        cnvc.play()
        time.sleep(2.5)
        self.assertEqual(str(cnvc), '\n0: 157\n1: 155\n2: 152')

        cnvc.updateCell(1, 10)
        time.sleep(1)
        cnvc.pause()
        self.assertEqual([c.state for c in cnvc.cellNet.cells],
                         [162, 309, 167])
Пример #2
0
    def testCellTriangleIntegerCells(self):
        """ Test for a SimpleCellTriangle object """
        cn = cellNet.SimpleCellTriangle([
            cell.IntegerCell('Cell A', 1),
            cell.IntegerCell('Cell B', 5),
            cell.IntegerCell('Cell C', 7)
        ])
        self.assertEqual([c.state for c in cn.cells], [1, 5, 7])
        cn.play()
        cn.pause()
        self.assertEqual([c.state for c in cn.cells], [12, 8, 6])

        cn.play()
        time.sleep(1.5)
        cn.cells[1].update(10)
        time.sleep(1)
        cn.pause()
        self.assertEqual([c.state for c in cn.cells], [42, 70, 48])
Пример #3
0
    def testIntegerCell(self):
        """ tests specific to IntegerCell """
        c1 = cell.IntegerCell("Cell 1")  # default state
        c2 = cell.IntegerCell('Cell 2', 1)
        c3 = cell.IntegerCell('Cell 3', 5)
        c4 = cell.IntegerCell('Cell 4', 10)

        self.assertEqual(str(c1), '0')
        self.assertEqual(str(c2), '1')

        [c4.addNeighbor(c) for c in (c1, c2, c3)]

        c4.mutate()  # new state depends on neighbor state
        self.assertEqual(c4.state, 6)

        c4.update(state=100)  # directly change state
        self.assertEqual(c4.state, 100)

        c1.state = 10
        c5 = c4.nextGen('Cell 5')  # nextGen includes a mutate()
        self.assertEqual(c5.state, 16)
Пример #4
0
    def testIntegerCell_VC(self):
        """ tests specific to Integer Cell VC """

        # create an IntegerCell and a Viewer/Controller
        c1 = cell.IntegerCell('Cell1')
        vc = cell.IntegerCell_VC(c1)

        # check association and initial value of the viewer/controller string
        self.assertEqual(str(vc), '0')

        # set up neighbors of c1
        c2 = cell.IntegerCell('Cell2', state=5)
        c3 = cell.IntegerCell('Cell3', state=10)
        c1.addNeighbor(c2)
        c1.addNeighbor(c3)

        # two types of modification. Each should update the py string
        vc.mutate()  # mutate according to Cells internal rules
        self.assertEqual(str(vc), '15')

        vc.update(state=50)
        self.assertEqual(str(vc), '50')
Пример #5
0
import cell, cellNet, time

cn = cellNet.SimpleCellTriangle([
    cell.IntegerCell('Cell A', 1),
    cell.IntegerCell('Cell B', 5),
    cell.IntegerCell('Cell C', 7)
])
cnvc = cellNet.CellNet_VC(cn)
print cnvc

cnvc.play()
time.sleep(10)
print cnvc
cnvc.pause()