Test a report's filters at their edges
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
- Write
lab/edge/total.pywith a functiontotal(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. - Record in
lab/edge/results.txtthe lineyear: N(no filters), to two decimal places, andmonths match year: yesif the twelve monthly totals -- each month ending on its real last day, fromcalendar.monthrange-- add up to the year within 0.01, otherwiseno. - Record
march inclusive: N orders(end 2025-03-31) andmarch exclusive end: N orders(orders before 2025-03-31). - Record
west equals WEST: yesorno, andCentral: 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.