def test_minimal_2d_vars(self): # pre run to get information set by the user ca_config = CAConfig(self.filepath2d) prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertEqual(ca_config.title, "Example 2D CA Minimal") self.assertEqual(ca_config.dimensions, 2) self.assertEqual(ca_config.states, (0,1,2))
def test_basic1d(self): ca_config = CAConfig(self.filepath1d) self.assertIsInstance(ca_config, CAConfig) #values from file self.assertEqual(ca_config.title, "Example 1D CA") self.assertEqual(ca_config.dimensions, 1) #pre run to get states prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertEqual(ca_config.states, (0,1))
def test_basic2d(self): ca_config = CAConfig(self.filepath2d) self.assertIsInstance(ca_config, CAConfig) #values from parsing the file self.assertEqual(ca_config.title, "Example 2D CA") self.assertEqual(ca_config.dimensions, 2) # pre run to get information set by the user prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertEqual(ca_config.title, "Example 2D CA") self.assertEqual(ca_config.dimensions, 2) self.assertEqual(ca_config.states, (0,1,2))
def load_ca(self, filepath): """Load a CA description file Pre runs the setup function in the description to populate the CAConfig object. Only then will the GUI be properly initialised (states must be known before adding config frame) Note: If manually specifying a path: sys.path[0] can be used to get the directory of main.py and then '/ca_descriptions/xxx.py' can be appended to create the filepath. Args: filepath (str): Full path to the CA description py file """ if not filepath == '': # loads the ca into the program with a default config # removes previous graph if self.ca_graph is not None: self.ca_graph.clear() # create default config self.ca_config = CAConfig(filepath) self.ca_config = prerun_ca(self.ca_config) if self.ca_config is None: return self.root.wm_title(self.WINDOW_TITLE + " - " + self.ca_config.title) self.add_configuration_controls() # Add ui controls to the gui self.playback_controls.ui.pack(side=tk.LEFT, padx=10) self.playback_controls.ui.sliderframe.pack() self.screenshotui.pack(side=tk.LEFT, padx=10)
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))
def test_1d_fill(self): ca_config = CAConfig(self.filepath1d) prerun_ca(ca_config) ca_config = load(ca_config.path) self.assertIsInstance(ca_config, CAConfig) #values from file ca_config.fill_in_defaults() #values from defaults expected_rulenum = 0 expected_gens = 100 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))