Test a report's filters at their edges

short · 40 min · Objective 4.3

Task

Write the function behind a filtered revenue figure, then test it where filters break: month boundaries, an exclusive end date, capitalisation, and a region with no data.

Steps

  1. Write lab/edge/total.py with a function total(region=None, start=None, end=None) returning the number of valid orders and their net revenue, matching region without regard to case, with both dates inclusive.
  2. Record in lab/edge/results.txt the line year: N (no filters), to two decimal places, and months match year: yes if the twelve monthly totals -- each month ending on its real last day, from calendar.monthrange -- add up to the year within 0.01, otherwise no.
  3. Record march inclusive: N orders (end 2025-03-31) and march exclusive end: N orders (orders before 2025-03-31).
  4. Record west equals WEST: yes or no, and Central: N, the revenue for a region with no orders, to two decimal places.

Verify

These checks run in a POSIX shell with Python 3: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. On Windows, python3 is often a Microsoft Store placeholder that prints “Python was not found”; run alias python3=py in Git Bash first.

grep -E '^(year|months match year|march inclusive|march exclusive end|west equals WEST|Central): ' lab/edge/results.txt

The year is 354627.14 and the months match it, so no order falls between two months. Why within 0.01 rather than equal? The exact total is 354627.135, half a cent, and floating-point addition in a different order can land either side of it: adding the months first prints 354627.13. Compare money with a tolerance, or in whole cents. March has 176 orders inclusive but 174 with an exclusive end date: the 2 orders on 31 March vanish. west equals WEST, and Central returns 0.00 rather than an error. Each is a filter a user will try on the first day.

This is an independent study companion for CompTIA Data+ DA0-002 and is not produced by or endorsed by CompTIA.