def test_block_doesnt_change(self): block = [[1, 1], [1, 1]] block_with_frame = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]] w = World(4, 4, block, 1, 1) self.assertTrue(np.array_equal(w.next(), np.array(block_with_frame)), "Block changed") self.assertTrue(np.array_equal(w.next(), np.array(block_with_frame)), "Block changed")
def test_error_raised_if_seed_doesnt_fit(self): with self.assertRaises(ValueError): World(4, 4, [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]], 1, 1) with self.assertRaises(ValueError): World(4, 4, [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]], 0, 1)
def test_beacon_has_a_period_of_two(self): w = World(4, 4, seed=[[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]) self.assertTrue( np.array_equal( w.let_it_live(2), np.array([[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]])), "Next state is ivalid")
def test_next_iteration_is_valid(self): w = World(4, 4, seed=[[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]) self.assertTrue( np.array_equal( w.next(), np.array([[1, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1]])), "Next state is ivalid") self.assertTrue( np.array_equal( w.next(), np.array([[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]])), "Next state is ivalid")
def test_seed_is_integrated(self): w = World(4, 4, seed=[[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]) self.assertTrue( np.array_equal( w.world, np.array([[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]])), "Arrays are not eqeual")
def test_pulsar_has_a_period_of_two(self): pulsar = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0]] w = World(19, 19, pulsar) self.assertTrue(np.array_equal(w.let_it_live(3), np.array(pulsar)), "Next state is ivalid")
def test_world_is_created(self): w = World(2, 2) self.assertTrue(np.array_equal(w.world, np.array([[0, 0], [0, 0]])), "Arrays are not eqeual")
def test_blinker_has_a_period_of_two(self): blinker = [[0, 1, 0], [0, 1, 0], [0, 1, 0]] w = World(3, 3, blinker) self.assertTrue(np.array_equal(w.let_it_live(2), np.array(blinker)), "Next state is ivalid")