UAT 104 Computer Programming
Worksheet 2 A mission tools library
Objective
Write reusable functions with automated tests and check a route against a geofence radius
Equipment and materials
- Computer with Python and pytest
- Module 2 example code
Safety
- Desk work only; no flying
Steps
- Create mission_tools.py with battery_status(), distance_m() and route_length_m(), each with a docstring
- Make functions raise an error on impossible values rather than guess
- Write test_mission_tools.py for boundary, impossible and known-answer values (1 degree of longitude on the equator is 111 194.9 m)
- Make pytest pass
- Write a function that checks every waypoint is inside the geofence radius and reports those outside
- Swap tests with another group, run them on their code and record the cases that break it
Record of results
| Function | Input | Expected result | Case type (boundary, invalid, known) | Pass? |
|---|---|---|---|---|
| Waypoint | Latitude, longitude (deg) | Distance from take-off (m) | Inside the radius? |
|---|---|---|---|
| Test | Error message or result | Cause found from the traceback | Suggested fix |
|---|---|---|---|
Questions
What do 15 and 7 give in battery_status()? If someone swapped the checks so <= 15 comes before <= 7, which test in Table 1 would catch it and which would not?
Why should battery_status() raise ValueError (and your other functions raise an error) on impossible values instead of returning a guess? How does the caller find out there is a problem?
Pick one case from Table 3 that broke the other group's code. Which line of the traceback did you read first, and was the cause a syntax, runtime or logic error?
If a waypoint is just outside the geofence radius from take-off, how should the program report it, and why should it not be rounded into a pass?
Check before you hand in
What to hand in
- mission_tools.py
- test_mission_tools.py and pytest output
- List of cases that broke the other group's code