Skip to content

Commit a482299

Browse files
committed
Add test for negative license amount
The function throws an error if the license amount is negative
1 parent a4cb89e commit a482299

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

exercises/tiered_pricing/solutions/xetxeberria-ts/src/tieredPricing.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const priceTiers = [
77
];
88

99
export function tieredPricing(licenseAmount: number): number {
10+
if (licenseAmount < 0)
11+
throw new Error(
12+
"Invalid license amount. License amount can not be negative"
13+
);
14+
1015
const licensePrice = calculateLicensePrice(licenseAmount);
1116

1217
return licensePrice * licenseAmount;

exercises/tiered_pricing/solutions/xetxeberria-ts/tests/tieredPricing.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ describe("TieredPricing should", () => {
2828
test("return 0 for 0 licenses", async () => {
2929
expect(tieredPricing(0)).toBe(0);
3030
});
31+
32+
test("throw an error if the license amount is negative", async () => {
33+
expect(() => tieredPricing(-1)).toThrow(Error);
34+
});
3135
});

0 commit comments

Comments
 (0)