Calculates user bills for a mass transit system based on journey data, applying zone-based pricing and daily/monthly caps
- Produce production-quality code with tests
- Take command line arguments for input/output files
- Calculate total charge for each customer's transit journeys
- Apply pricing rules:
- £2 base fee per journey
- Additional zone-based costs:
Zone 1: £0.80 Zones 2-3: £0.50 Zones 4-5: £0.30 Zone 6+: £0.10
- £5 fee for erroneous journeys
- Daily cap: £15
- Monthly cap: £100
- Python 3.7+
- pytest (for testing)
python main.py <zones_file_path> <journey_data_path> <output_file_path>
Example:
python main.py zone_map.csv journey_data.csv billing_results.csv
Run tests with:
pytest tests.py
test_read_zone_map
: Validates correct reading of zone map from CSVtest_read_zone_map_invalid_data
: Checks handling of invalid zone datatest_read_journey_data
: Verifies correct reading of journey datatest_read_journey_data_invalid_station
: Tests handling of unknown stationstest_calculate_journey_cost
: Checks journey cost calculations for various zonestest_daily_cap
: Ensures daily spending cap (£15) is applied correctlytest_monthly_cap
: Verifies monthly spending cap (£100) is applied correctlytest_incomplete_journey
: Checks application of incomplete journey fee (£5)test_cross_midnight_journey
: Verifies handling of journeys spanning midnighttest_export_billing_results
: Checks correct formatting of billing results CSV
- Valid journeys completed before midnight
- £2 base fee per journey
- £5 fee for incomplete journeys
- Daily cap: £15, Monthly cap: £100
- Input data is chronologically sorted