{
  "id": "py-invoicing",
  "kind": "repos",
  "version": "v1",
  "answers": [
    {
      "key": "bug-1",
      "question": "Planted bug 1 of 2: where is it and what is the minimal fix?",
      "answer": {
        "file": "invoicing/discounts.py",
        "line": 13,
        "category": "off-by-one comparison",
        "bug": "Tier thresholds are documented as inclusive, but the comparison is strict, so a subtotal of exactly 1,000.00 gets no discount.",
        "fix": {
          "before": "        if subtotal > minimum:",
          "after": "        if subtotal >= minimum:",
          "before_starts_at_line": 13
        },
        "failing_tests": [
          "test_discount_at_exactly_1000"
        ]
      },
      "type": "object",
      "unit": null,
      "tolerance": null,
      "evidence": [
        {
          "file": "py-invoicing.zip",
          "page": null,
          "quote": "if subtotal > minimum:",
          "bbox": null,
          "cell": null,
          "line": 13,
          "path": "py-invoicing/invoicing/discounts.py",
          "role": "proof"
        }
      ]
    },
    {
      "key": "bug-2",
      "question": "Planted bug 2 of 2: where is it and what is the minimal fix?",
      "answer": {
        "file": "invoicing/money.py",
        "line": 16,
        "category": "wrong rounding mode",
        "bug": "Cents are rounded half to even (banker's rounding), but the documented rule is half away from zero, so 0.125 becomes 0.12 and a 2.525 tax becomes 2.52.",
        "fix": {
          "before": "    return amount.quantize(CENT, rounding=ROUND_HALF_EVEN)",
          "after": "    return amount.quantize(CENT, rounding=ROUND_HALF_UP)",
          "before_starts_at_line": 16
        },
        "failing_tests": [
          "test_round_half_up",
          "test_tax_rounds_half_up"
        ]
      },
      "type": "object",
      "unit": null,
      "tolerance": null,
      "evidence": [
        {
          "file": "py-invoicing.zip",
          "page": null,
          "quote": "return amount.quantize(CENT, rounding=ROUND_HALF_EVEN)",
          "bbox": null,
          "cell": null,
          "line": 16,
          "path": "py-invoicing/invoicing/money.py",
          "role": "proof"
        }
      ]
    }
  ],
  "test_command": "python3 -m unittest discover -s tests -t . -v",
  "failing_tests_as_shipped": [
    "test_discount_at_exactly_1000",
    "test_round_half_up",
    "test_tax_rounds_half_up"
  ],
  "patch": "--- a/invoicing/discounts.py\n+++ b/invoicing/discounts.py\n@@ -10,6 +10,6 @@\n \n def discount_rate(subtotal):\n     for minimum, rate in TIERS:\n-        if subtotal > minimum:\n+        if subtotal >= minimum:\n             return rate\n     return Decimal(\"0\")\n--- a/invoicing/money.py\n+++ b/invoicing/money.py\n@@ -13,4 +13,4 @@\n \n def round_money(amount):\n     \"\"\"Round to whole cents, half away from zero (the rule on our printed invoices).\"\"\"\n-    return amount.quantize(CENT, rounding=ROUND_HALF_EVEN)\n+    return amount.quantize(CENT, rounding=ROUND_HALF_UP)\n",
  "not_bugs": []
}
