Пример #1
0
    def test_attach_neuron(self):
        neuron = Neuron(1, 1, 1)
        brain = Brain()
        brain.attach_neuron(neuron)

        res = helpers.get_from_dict_by_key(brain.neurons, "1.1.1", 0)

        self.assertNotEqual(res, 0)
Пример #2
0
class BrainTest( unittest.TestCase ):
	@staticmethod
	def buildSuite():
		suite = unittest.TestSuite()
		suite.addTest(BrainTest("testShouldBuildNetwork"))
		suite.addTest(BrainTest("testShouldAddConnection"))
		suite.addTest(BrainTest("testShouldAddNeuron"))
		suite.addTest(BrainTest("testShouldRandomizeConnection"))
		return suite

	def setUp( self ):
		from classes.brain import Brain	
		self.brain = Brain()	

	def testShouldBuildNetwork( self ):
		assert self.brain.network is not None, "network not initialized"

	def testShouldAddConnection( self ):
		before = 0
		for mod in self.brain.network.modules:
			for con in self.brain.network.connections[mod]:
				before += 1
		self.brain.add_random_connection()
		after = 0
		for mod in self.brain.network.modules:
			for con in self.brain.network.connections[mod]:
				after += 1
		assert after == before + 1, "connection not added"

	def testShouldAddNeuron( self ):
		before = 0
		for mod in self.brain.network.modules:
			before += 1
		self.brain.add_random_neuron()
		after = 0
		for mod in self.brain.network.modules:
			after += 1
		assert after == before + 1, "connection not added"

	def testShouldRandomizeConnection( self ):
		c = self.brain.connections[0]
		b = c.params[0]
		self.brain.randomize_connection(c)
		d = c.params[0]

		self.assertNotAlmostEqual(b,d), "connection not randomized"


	def tearDown( self ):
		self.member = None
Пример #3
0
from classes.brain import Brain

if __name__=='__main__':
    brain = Brain()
    brain.run()



Пример #4
0
	def setUp( self ):
		from classes.brain import Brain	
		self.brain = Brain()