Example #1
0
    def test_get_neighbours_for_right_side(self):

        clist = CellList.from_file('grid.txt')

        neighbours = clist.get_neighbours(Cell(2, 7))

        self.assertEquals(5, len(neighbours))

        self.assertEquals(2, sum(c.is_alive() for c in neighbours))
Example #2
0
    def test_get_neighbours(self):

        clist = CellList.from_file('grid.txt')

        neighbours = clist.get_neighbours(Cell(2, 3))

        self.assertEquals(8, len(neighbours))

        self.assertEquals(4, sum(c.is_alive() for c in neighbours))
Example #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))
Example #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))
Example #5
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)
 def test_get_neighbours_for_upper_side(self):
     clist = CellList.from_file('grid.txt')
     neighbours = clist.get_neighbours(Cell(0,3))
     self.assertEqual(5, len(neighbours))
     self.assertEqual(4, sum(c.is_alive() for c in neighbours))
 def test_get_neighbours_for_upper_left_corner(self):
     clist = CellList.from_file('grid.txt')
     neighbours = clist.get_neighbours(Cell(0,0))
     self.assertEqual(3, len(neighbours))
     self.assertEqual(2, sum(c.is_alive() for c in neighbours))