Menu

Testing the last 8 bags on a purchase order with SQLite
📰

Testing the last 8 bags on a purchase order with SQLite

DEV Community: python·Bokeping uTaxes·5 days ago
#cbyRTHSr
#devtopython#devto#dev#self#bags
Long article (673 words) — no AI summary yet.
Reading 0:00
15s threshold

A café orders 24 five-pound bags at $33 each. The first shipment arrives with a supplier invoice for 16 bags. That bill comes to $528. Now try to enter a second bill for 9 bags. A check against the original 24 will happily accept it, leaving the café billed for 25.

The interesting pair of inputs is 8 and 9 , both tried from exactly the same starting point. Eight should create a $264 bill and leave zero bags on order. Nine should fail and leave both the first bill and the eight open bags alone. If you run the eight-bag case first and reuse its database for the nine-bag case, you’ve only tested what happens to a completely filled order.

Save this as test_partial_bill.py and run python3 test_partial_bill.py . It uses Python’s standard library and an in-memory SQLite database. The order has one line, whole bags, and no tax, freight, or cancellations.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.