Review this generated specification before an agent uses it as acceptance evidence.
Specify that non-negative integer subtotals use integer cents; standard French shipping costs 500 cents below 5,000 and is free at 5,000 or more; expedited French shipping costs 900; non-French shipping costs 1,200; and absent country codes or invalid subtotals are rejected.
JavaScript
import assert from "node:assert/strict";
function shippingFeeCents(order) {
const { subtotalCents, country, expedited = false } = order;
if (subtotalCents < 0) throw new RangeError("negative subtotal");
if (country !== "FR") return 1200;
if (expedited) return 900;
return subtotalCents > 5000 ? 0 : 500;
}
const examples = [
[{ subtotalCents: 6000, country: "FR" }, 0],
[{ subtotalCents: 2000, country: "FR" }, 500],
[{ subtotalCents: 8000, country: "FR", expedited: true }, 900],
];
for (const example of examples) {
const [input, expected] = example;
assert.equal(shippingFeeCents(input), expected);
}
for (let subtotal = 0; subtotal < 10_000_000; subtotal += 1) {
assert.ok(shippingFeeCents({ subtotalCents: subtotal, country: "FR" }) >= 0);
}
generated code is illustrative, not from any one model