Invoices are agreements to transfer money between companies. We need a python class to aggregate and gather basic stats on the invoices we process. Your task is to write this class.
Write a python class, InvoiceStats
, along with suitable tests, which supports the following methods:
add_invoices
- add a list of invoices, in dollars and centsadd_invoice
- add a single invoice, in dollars and cents.clear
- remove all stored invoice data.get_median
- find the median value (https://en.wikipedia.org/wiki/Median) of the added invoices, to the nearest cent. Half a cent should round down.get_mean
- find the mean value of the invoices, to the nearest cent. Half a cent should round down.
Constraints:
- Valid invoice values v are 0 < v < $200,000,000.00 and must be a whole number of dollars and cents.
- Adding non valid invoice value(s) should raise an exception.
- You may decide what data type(s) to use to best represent the invoice amounts.
- Maximum number of invoices is 20,000,000
- Assume the machine the code is running on will not crash, so no need to persist data.
- You may use (non standard) third party libraries. If so, please include details of them, including why you used them.
- Your code will be judged on scalability, clarity, readability, accuracy, test coverage, performance and robustness
errors.py
: user-defined errors to raise when facing invalid invoicesinvoice.py
: customInvoice
class to represent invoicesinvoice_stats.py
: implementation of theInvoiceStats
classtest_invoice_stats.py
: unit tests
Every package used is from the standard library, to run the tests just launch (tested with python==3.7.2):
python3 -m unittest test_invoice_stats.py