def test_can_construct_with_random_pop(self): """ Assert that we can constuct the class from a random population. """ myModel = Model.from_random_pop( 16, h = 0.4, s = 0.4, delta =0.2) self.assertIsInstance( myModel, Model ) self.assertEqual( myModel.size, 16 )
def test_make_graph_returns_matplotlib_figure(self): """ Simply assert that the function returns a figure. """ myModel = Model.from_random_pop( 16, 0.4, 0.5, 0.1, graphs = False) myModel.go() fig = myModel.make_graphs() self.assertIsInstance( fig, mpl.figure.Figure )
def test_model_handles_mutation(self): """ Run the model for one generation, and see that mutation is taking effect. """ mod = Model.from_random_pop( 16, 0.4, 0.5, 0.1, graphs = False,\ generations = 1, mu_strat = 0.5, mu_assort = 0 ) mod.go() ##We're bascially just checking that this runs, so this is just a minimal test self.assertIsInstance(mod,Model)
def test_go(self): """ Can't really test the whole Model automatically in any detail, but check that the whole thing can run, and the population stays the same size """ myModel = Model.from_random_pop( 16, h = 0.4, s = 0.4, delta =0.2) myModel.go() self.assertEqual( len( myModel.Population ), len( myModel.pop0 ) ) ##Check that something has happened at least self.assertNotEqual( myModel.Population, myModel.pop0 )
def test_model_sets_final_results(self): """ The other classes will be looking for certain key words after the simulation has stopped. Check that they exist, and are sensible vaules. """ myModel = Model.from_random_pop( 16, 0.4, 0.5, 0.1 ) myModel.go() self.assertGreaterEqual( myModel.final_fairness, 0 ) self.assertLessEqual( myModel.final_fairness, 1 ) self.assertGreaterEqual( myModel.final_desired_assortment, 0 ) self.assertLessEqual( myModel.final_desired_assortment, 1 )