Пример #1
0
    def test_can_update(self):
        clist = CellList.from_file('grid.txt')

        with open('steps.txt') as f:
            steps = json.load(f)

        num_updates = 0
        for step in sorted(steps.keys(), key=int):
            with self.subTest(step=step):
                for _ in range(int(step) - num_updates):
                    clist = clist.update()
                    num_updates += 1
                # TODO: Rewrite me
                c = 0
                row = []
                states = []
                for cell in clist:
                    row.append(int(cell.is_alive()))
                    c += 1
                    if c % clist.ncols == 0:
                        states.append(row)
                        row = []
                self.assertEqual(steps[step], states)
Пример #2
0
 def test_get_neighbours_for_bottom_side(self):
     clist = CellList.from_file('grid.txt')
     neighbours = clist.get_neighbours(Cell(5, 3))
     self.assertEquals(5, len(neighbours))
     self.assertEquals(4, sum(c.is_alive() for c in neighbours))
Пример #3
0
 def test_get_neighbours_for_lower_right_corner(self):
     clist = CellList.from_file('grid.txt')
     neighbours = clist.get_neighbours(Cell(5, 7))
     self.assertEquals(3, len(neighbours))
     self.assertEquals(1, sum(c.is_alive() for c in neighbours))
Пример #4
0
 def test_can_create_a_grid_from_file(self):
     clist = CellList.from_file('grid.txt')
     states = [cell.is_alive() for cell in clist]
     self.assertEqual(6, clist.nrows)
     self.assertEqual(8, clist.ncols)
     self.assertEqual(29, sum(states))