Example #1
0
	def test_min_reward(self):
		print('test minimum reward')
		env  = SimpleVehicle()
		state = env.reset()		
		state_size = env.state_size
		action_size = env.discrete_action_size
		agent = ReinforceAgent(state_size, action_size)
		action = agent.getAction(state)
		next_state, reward, done = env.discrete_step(action)		
		print('action: ', action)
		print('reward: ', reward)
		
		self.assertGreater(reward,0.001, 'reward is greater than 0.001')
Example #2
0
	def test_next_state_left_fast(self):
		print('test left move fast')				
		env = SimpleVehicle()		
		next_state = env.reset()
		print(next_state)
		init = copy.copy(next_state)
		action = 1# move left		
		next_state, reward, done = env.discrete_step(action)
		print(next_state)
		print(init)
				
		self.assertNotEqual(init[0],next_state[0], 'initial and next state x-position are the same')	
		self.assertNotEqual(init[1],next_state[1], 'initial and next state y-position are the same')					
		self.assertLess(init[2],next_state[2], 'next state heading is less than initial')	
Example #3
0
	def test_next_state_straight_fast(self):		
		print('test straight move fast')
		env = SimpleVehicle()		
		next_state = env.reset()
		print(next_state)
		init = copy.copy(next_state)
		action = 3# move straight fast		
		next_state, reward, done = env.discrete_step(action)
		print(next_state)
		print(init)
				
		self.assertNotEqual(init[0],next_state[0], 'initial and next state x-position are the same')	
		self.assertNotEqual(init[1],next_state[1], 'initial and next state y-position are the same')					
		self.assertEqual(init[2],next_state[2], 'initial and next state heading are NOT the same')									
Example #4
0
	def test_next_state_right(self):
		print('test right move')				
		env = SimpleVehicle()		
		next_state = env.reset()
		print(next_state)
		init = copy.copy(next_state)
		action = 4# move right		
		next_state, reward, done = env.discrete_step(action)
		print(next_state)
		print(init)
				
		self.assertNotEqual(init[0],next_state[0], 'initial and next state x-position are the same')	
		self.assertNotEqual(init[1],next_state[1], 'initial and next state y-position are the same')					
		self.assertGreater(init[2],next_state[2], 'next state heading is greater than initial')							
Example #5
0
	def test_done_condition(self):
		print('check done condition')
		env = SimpleVehicle()
		state = env.reset()		
		state_size = env.state_size
		action_size = env.discrete_action_size
		agent = ReinforceAgent(state_size, action_size)
		
		action = agent.getAction(state)
		next_state, reward, done = env.discrete_step(action)		
		if (env._border_fcn(env.tmpstep[:, 0]) > env.tmpstep[:, 1]).any() \
                or (env.tmpstep[:, 0] < env.xlim[0]).any() \
                or (env.tmpstep[:, 0] > env.xlim[1]).any() \
                or (env.tmpstep[:, 1] < env.ylim[0]).any() \
				or (env.tmpstep[:, 1] > env.ylim[1]).any() \
				or ((env.tmpstep[:, 0] > min(env.ox1)).any() and (env.tmpstep[:, 0] < max(env.ox1)).any() and (env.tmpstep[:, 1] > min(env.oy1)).any() and (env.tmpstep[:, 1] < max(env.oy1)).any()) \
				or ((env.tmpstep[:, 0] > min(env.ox2)).any() and (env.tmpstep[:, 0] < max(env.ox2)).any() and (env.tmpstep[:, 1] > min(env.oy2)).any() and (env.tmpstep[:, 1] < max(env.oy2)).any()):		  				 					
			self.assertTrue(done, 'done is False')
		else:
			self.assertFalse(done, 'done is True')