UAT 104 Computer Programming

Worksheet 2 A mission tools library

Analysis activity 6 hAssesses CLO1

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

  1. Create mission_tools.py with battery_status(), distance_m() and route_length_m(), each with a docstring
  2. Make functions raise an error on impossible values rather than guess
  3. Write test_mission_tools.py for boundary, impossible and known-answer values (1 degree of longitude on the equator is 111 194.9 m)
  4. Make pytest pass
  5. Write a function that checks every waypoint is inside the geofence radius and reports those outside
  6. Swap tests with another group, run them on their code and record the cases that break it

Record of results

Table 1 Test cases in test_mission_tools.py
FunctionInputExpected resultCase type (boundary, invalid, known)Pass?
Table 2 Geofence check results
WaypointLatitude, longitude (deg)Distance from take-off (m)Inside the radius?
Table 3 Cases that broke the other group's code
TestError message or resultCause found from the tracebackSuggested fix

Questions

  1. 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?

  2. 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?

  3. 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?

  4. 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

CLO1 Write structured Python programs to solve technology problems. (CLOs are a web-team draft; the course owner sets the final ones.)

Instructors: answers and teaching notes for this worksheet are in the teaching pack