forked from udacity/AIPND-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testing module&modify several tasks
- Loading branch information
Mac1024
authored and
Mac1024
committed
Aug 28, 2018
1 parent
81c22fa
commit 5bee397
Showing
3 changed files
with
142 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,18 @@ | ||
import random | ||
import time | ||
|
||
MAZE_1 = [ | ||
[0,0,0,0,0,2,3], | ||
[1,2,2,2,0,2,0], | ||
[2,0,0,0,0,2,0], | ||
[2,2,2,2,0,0,0]] | ||
|
||
MAZE_2 = [ | ||
[2,2,3,0,2,0], | ||
[1,2,2,0,2,0], | ||
[0,0,2,0,2,0], | ||
[2,0,2,0,0,0], | ||
[2,0,0,0,2,0]] | ||
|
||
MAZE_3 = [ | ||
MAZE = [ | ||
[3,2,2,2,2,2,2,2,1], | ||
[0,0,2,2,2,2,2,0,0], | ||
[2,0,0,2,2,2,0,0,2], | ||
[2,2,0,0,2,0,0,2,2], | ||
[2,2,2,0,0,0,2,2,2]] | ||
|
||
MAZE_LIST = [MAZE_1, MAZE_2, MAZE_3] | ||
|
||
def fetch_maze(): | ||
maze_id = random.randint(0,len(MAZE_LIST)-1) | ||
print("maze-id {}-{}".format(1, round(time.time()))) | ||
print('['+str(MAZE_LIST[maze_id][0])+',') | ||
for line in MAZE_LIST[maze_id][1:-1]: | ||
print('['+str(MAZE[0])+',') | ||
for line in MAZE[1:-1]: | ||
print(' '+str(line)+',') | ||
print(' '+str(MAZE_LIST[maze_id][-1])+']') | ||
return MAZE_LIST[maze_id] | ||
print(' '+str(MAZE[-1])+']') | ||
return MAZE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import unittest | ||
|
||
|
||
class RobotControllortTestCase(unittest.TestCase): | ||
"""Test for Robot Controller project""" | ||
|
||
def test_cal_barriers(self): | ||
self.assertEqual(number_of_barriers_row1, 7) | ||
self.assertEqual(number_of_barriers_col3, 3) | ||
|
||
def test_cal_loc_map(self): | ||
self.assertEqual(loc_map["start"], (0, 8)) | ||
self.assertEqual(loc_map["destination"], (0, 0)) | ||
|
||
def test_is_move_valid(self): | ||
self.assertEqual(is_move_valid(env_data, (0, 0), 'u'), False) | ||
self.assertEqual(is_move_valid(env_data, (0, 0), 'l'), False) | ||
|
||
self.assertEqual(is_move_valid(env_data, (4, 0), 'd'), False) | ||
self.assertEqual(is_move_valid(env_data, (0, 8), 'r'), False) | ||
|
||
self.assertEqual(is_move_valid(env_data, (0, 0), 'r'), False) | ||
self.assertEqual(is_move_valid(env_data, (1, 0), 'd'), False) | ||
|
||
self.assertEqual(is_move_valid(env_data, (1, 7), 'd'), True) | ||
self.assertEqual(is_move_valid(env_data, (3, 5), 'r'), True) | ||
|
||
self.assertEqual(is_move_valid(env_data, (1, 0), 'u'), True) | ||
|
||
def test_is_move_valid_special(self): | ||
self.assertEqual(is_move_valid_special((0, 0), 'u'), False) | ||
self.assertEqual(is_move_valid_special((0, 0), 'l'), False) | ||
|
||
self.assertEqual(is_move_valid_special((4, 0), 'd'), False) | ||
self.assertEqual(is_move_valid_special((0, 8), 'r'), False) | ||
|
||
self.assertEqual(is_move_valid_special((0, 0), 'r'), False) | ||
self.assertEqual(is_move_valid_special((1, 0), 'd'), False) | ||
|
||
self.assertEqual(is_move_valid_special((1, 7), 'd'), True) | ||
self.assertEqual(is_move_valid_special((3, 5), 'r'), True) | ||
|
||
self.assertEqual(is_move_valid_special((1, 0), 'u'), True) | ||
|
||
|
||
|
||
def test_valid_actions(self): | ||
self.assertEqual(valid_actions(env_data, (0, 8)), ['d']) | ||
self.assertEqual(valid_actions(env_data, (1, 0)), ['u', 'r']) | ||
|
||
def test_move_robot(self): | ||
self.assertEqual(move_robot((1, 0), 'u'), (0, 0)) | ||
self.assertEqual(move_robot((0, 8), 'd'), (1, 8)) | ||
self.assertEqual(move_robot((3, 3), 'l'), (3, 2)) | ||
self.assertEqual(move_robot((1, 0), 'r'), (1, 1)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |