|
Robot
Move a little robot.
|
Functions | |
| def | check_diff (received, expected) |
| def | find_robot_grid (r) |
| def | find_image_in_grid (table) |
| def | final_position (moves, x_max=4, y_max=4) |
| def | test_moves (moves) |
| def | main () |
Variables | |
| server | |
| def | flag = main() |
| def integration_test.check_diff | ( | received, | |
| expected | |||
| ) |
Checks difference between two strings.
First compares the lengths. If they are equal, compares character by
character.
Args:
received (string): Received string.
expected (string): Expected string.
Returns:
flag (boolean) : True if strings differ, False otherwise.
| def integration_test.final_position | ( | moves, | |
x_max = 4, |
|||
y_max = 4 |
|||
| ) |
Given a list of the moves, this function computes the final coordinates.
Important note: the list always needs to start with a 'reset' to ensure
replicable tests!
Args:
moves (list): list of moves done by the robot. Always start with
'reset', and can contain the following elements in any order
(and repeated as many times as you want):
- 'reset'
- 'up'
- 'down'
- 'left'
- 'right'
- 'coords/x/y' with x and y as integers
x_max (int): Value max for x (so number of lines in the grid - 1).
y_max (int): Value max for y (so number of columns in the grid - 1).
Returns:
x (int): robot's final x coordinate in the table.
y (int): robot's final y coordinate in the table.
| def integration_test.find_image_in_grid | ( | table | ) |
Find the robot in the grid parsed using find_robot_grid().
Args:
table (list): see result of find_robot_grid().
Returns:
x (int): robot's x coordinate in the table.
y (int): robot's y coordinate in the table.
| def integration_test.find_robot_grid | ( | r | ) |
Find the table containing the robot using BeautifulSoup.
Table should have the class 'robot-grid'.
Args:
r (request): request containing the table to analyze.
Returns:
table (list): table as a list of lists.
| def integration_test.main | ( | void | ) |
Integration tests.
With previously opened server:
- TEST 1: ask for CSS template, PNG robot image, JS script and check if
matches the saved ones.
- TEST 2: ask for random requests.
- TEST 3: tries many moves sequences.
Returns:
(boolean): True if all tests passed, otherwise False.
| def integration_test.test_moves | ( | moves | ) |
Test a sequence of moves by sending the matching requests to the
server, finind the robot in the final response, and comparing it to the
theorical answer.
Args:
moves (list): list of moves done by the robot. Always start with
'reset', and can contain the following elements in any order
(and repeated as many times as you want):
- 'reset'
- 'up'
- 'down'
- 'left'
- 'right'
- 'coords/x/y' with x and y as integers
Returns:
(boolean): True if last position matches the expected one.
| def integration_test.flag = main() |
| integration_test.server |