def __new__(mcs, name, bases, dict): def gen_test_shape_eq(config, x, shape): def test(self): if (type(x) is tuple): config.set_grid_dims(dims=x) else: config.set_grid_dims(num_generations=x) self.assertEqual(config.initial_grid.shape, shape) self.assertEqual(config.grid_dims, shape) return test #1d #below limit, valid and below current, valid and above current gens = [0, 50, 150] expected = [(2,3), (51,101), (151, 301)] config = CAConfig(TESTDESCRIPTIONS_PATH + "1dbasic.py") config.fill_in_defaults() for g, e in zip(gens, expected): testname = "test_config_setdims_1d_{g}".format(g=g) dict[testname] = gen_test_shape_eq(config, g, e) dict[testname] = gen_test_shape_eq(config, g, e) #2d config = CAConfig(TESTDESCRIPTIONS_PATH + "2dbasic.py") config.fill_in_defaults() shapes = [(2,3), (3,3), (50, 50), (300,300), (300,420)] for s in shapes: testname = "test_config_setdims_2d_{g}".format(g=g) dict[testname] = gen_test_shape_eq(config, s, s) dict[testname] = gen_test_shape_eq(config, s, s) return type.__new__(mcs, name, bases, dict)
def test_minimal_2d_comments_fill(self): ca_config = CAConfig(self.filepath2d) self.assertIsInstance(ca_config, CAConfig) ca_config.fill_in_defaults() #values from defaults # + 1 from the inclusion of generation 0 expected_gens = 100 expected_dims = (200, 200) expected_grid = np.zeros(expected_dims) expected_nhood = np.ones((3,3)) self.assertEqual(ca_config.num_generations, expected_gens) self.assertEqual(ca_config.grid_dims, expected_dims) self.assertTrue(np.array_equal(ca_config.initial_grid, expected_grid)) self.assertTrue(np.array_equal(ca_config.nhood_arr, expected_nhood))
def test_minimal_1d_comments_fill(self): ca_config = CAConfig(self.filepath1d) self.assertIsInstance(ca_config, CAConfig) ca_config.fill_in_defaults() #values from defaults expected_rulenum = 0 expected_gens = 100 # + 1 for generation 0 expected_dims = (expected_gens + 1, expected_gens*2 + 1) expected_grid = np.zeros(expected_dims) expected_nhood = np.array([1,1,1]) self.assertEqual(ca_config.rule_num, expected_rulenum) self.assertEqual(ca_config.num_generations, expected_gens) self.assertEqual(ca_config.grid_dims, expected_dims) self.assertTrue(np.array_equal(ca_config.initial_grid, expected_grid)) self.assertTrue(np.array_equal(ca_config.nhood_arr, expected_nhood))
def test_minimal_2d_vars_fill(self): ca_config = CAConfig(self.filepath2d) prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertIsInstance(ca_config, CAConfig) self.assertEqual(ca_config.states, (0,1,2)) #values from file ca_config.fill_in_defaults() #values from defaults expected_gens = 100 expected_dims = (200, 200) expected_grid = np.zeros(expected_dims) expected_nhood = np.ones((3,3)) self.assertEqual(ca_config.num_generations, expected_gens) self.assertEqual(ca_config.grid_dims, expected_dims) self.assertTrue(np.array_equal(ca_config.initial_grid, expected_grid)) self.assertTrue(np.array_equal(ca_config.nhood_arr, expected_nhood))