Ejemplo n.º 1
0
	def test_records_assortment(self):
		"""
		Check that the model records assortment.
		"""

		gens = 26
		pop = Population.from_random(32)
		assort0 = pop.average_assortment
		myModel = Model( pop, h = 0.4, s = 0.6, delta = 0.3, generations = gens)
		myModel.go()
		self.assertEqual( len( myModel.desired_assortment ), gens )
		self.assertEqual( assort0, myModel.desired_assortment[0] )
Ejemplo n.º 2
0
	def test_records_fairness(self):
		"""
		Test that the model record fairness, simply by asserting that the model
		has a list of the length of the number of generations.

		"""

		gens = 26
		pop = Population.from_random(32)
		fairness0 = pop.fairness
		myModel = Model( pop, h = 0.4, s = 0.6, delta = 0.3, generations = gens)
		myModel.go()
		self.assertEqual( len( myModel.fairness ), gens )
		self.assertEqual( fairness0, myModel.fairness[0] )
Ejemplo n.º 3
0
	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 )
Ejemplo n.º 4
0
	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)
Ejemplo n.º 5
0
	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 )
Ejemplo n.º 6
0
	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 )
Ejemplo n.º 7
0
	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 )
Ejemplo n.º 8
0
	def test_can_be_contructed_from_function(self):
		"""
		Test that we can construct a model from a function that returns an
		individual.
		"""
		##Make a function that returns a constan individual
		def _const_ind():
			return Individual(1,1,1,1)
		myModel = Model.from_function( _const_ind, 12, 0.3,0.3,0.9 )
		self.assertIsInstance(myModel, Model)
		self.assertEqual( myModel.size, 12  )
		self.assertEqual( myModel.delta, 0.9 )
		self.assertEqual( myModel.Population.fairness, 1 )
		self.assertEqual( myModel.Population.average_assortment, 1 )