def test_init_errors(self): for size in (-5, 0, 1): with self.assertRaises(ValueError): Field(size) for size in ((2, 3), 5.5, '4'): with self.assertRaises(TypeError): Field(size)
def test_clear_state(self): field = Field(3) state = FieldState(field) for cell, value in (((1, 1), 2), ((2, 3), 4), ((3, 1), 7)): state.set_state(cell, value) state.clear_state() for cell in field.get_all_cells(): self.assertEqual(state.get_state(cell), 0)
def test_get_neighbour_cells(self): field = Field(3) for (cell, neighbours) in (((0, 0), { (0, 1), (1, 1), (1, 0) }), ((1, 2), {(0, 1), (0, 2), (1, 3), (2, 3), (2, 2), (1, 1)}), ((2, 2), { (1, 1), (1, 2), (2, 3), (3, 2), (3, 1), (2, 1) }), ((2, 4), {(1, 3), (2, 3), (3, 3)}), ((3, 1), { (2, 1), (2, 2), (3, 2), (4, 1), (4, 0), (3, 0) }), ((4, 1), {(4, 0), (3, 1), (3, 2), (4, 2)})): self.assertSetEqual(neighbours, set(field.get_neighbour_cells(cell)))
def test_set_state_errors(self): field = Field(3) state = FieldState(field) with self.assertRaises(ValueError): state.set_state((1, 1), -5) for cell, value in (((1, 0), 2.5), ((2, 2), '10'), ((4, 2), (1, 5))): with self.assertRaises(TypeError): state.set_state(cell, value)
def test_get_full_state(self): field = Field(3) state = FieldState(field) state.set_state((2, 4), 1) self.assertEqual(state.get_full_state(), state._state)
def test_set_state(self): field = Field(3) state = FieldState(field) state.set_state((2, 4), 5) self.assertEqual(state.get_state((2, 4)), 5)
def test_init_state(self): field = Field(3) state = FieldState(field) for cell in field.get_all_cells(): self.assertEqual(state.get_state(cell), 0)
def test_get_all_cells(self): field = Field(2) cells = field.get_all_cells() self.assertSetEqual(set(cells), {(0, 0), (0, 1), (1, 0), (1, 2), (1, 1), (2, 0), (2, 1)})
def test_init_field(self): field = Field(5) self.assertEqual(5, field.size())