|
1 | | -// This statement loads the isProperFraction function you wrote in the implement directory. |
2 | | -// We will use the same function, but write tests for it using Jest in this file. |
3 | | -const isProperFraction = require("../implement/2-is-proper-fraction"); |
| 1 | +const getCardValue = require("../implement/3-get-card-value"); |
4 | 2 |
|
5 | | -// denominator is zero |
6 | | -test("should return false when denominator is zero", () => { |
7 | | - expect(isProperFraction(1, 0)).toEqual(false); |
| 3 | +// Ace |
| 4 | +test("Should return 11 when given an ace card", () => { |
| 5 | + expect(getCardValue("A♠")).toBe(11); |
8 | 6 | }); |
9 | 7 |
|
10 | | -// proper fraction (numerator < denominator) |
11 | | -test("should return true when numerator < denominator", () => { |
12 | | - expect(isProperFraction(1, 2)).toEqual(true); |
| 8 | +// Number cards |
| 9 | +test("Should return the numeric value for number cards", () => { |
| 10 | + expect(getCardValue("2♠")).toBe(2); |
| 11 | + expect(getCardValue("5♥")).toBe(5); |
| 12 | + expect(getCardValue("9♦")).toBe(9); |
| 13 | + expect(getCardValue("10♣")).toBe(10); |
13 | 14 | }); |
14 | 15 |
|
15 | | -// improper fraction (numerator > denominator) |
16 | | -test("should return false when numerator > denominator", () => { |
17 | | - expect(isProperFraction(5, 3)).toEqual(false); |
| 16 | +// Face cards |
| 17 | +test("Should return 10 for face cards", () => { |
| 18 | + expect(getCardValue("J♠")).toBe(10); |
| 19 | + expect(getCardValue("Q♥")).toBe(10); |
| 20 | + expect(getCardValue("K♦")).toBe(10); |
18 | 21 | }); |
19 | 22 |
|
20 | | -// equal numbers |
21 | | -test("should return false when numerator === denominator", () => { |
22 | | - expect(isProperFraction(4, 4)).toEqual(false); |
| 23 | +// Invalid cards (basic) |
| 24 | +test("Should throw error for invalid cards", () => { |
| 25 | + expect(() => getCardValue("1♠")).toThrow(); |
| 26 | + expect(() => getCardValue("B♣")).toThrow(); |
| 27 | + expect(() => getCardValue("10?")).toThrow(); |
| 28 | + expect(() => getCardValue("invalid")).toThrow(); |
23 | 29 | }); |
24 | 30 |
|
25 | | -// numerator is zero |
26 | | -test("should return true when numerator is zero and denominator is positive", () => { |
27 | | - expect(isProperFraction(0, 5)).toEqual(true); |
| 31 | +// Invalid numeric formats (IMPORTANT for your strict function) |
| 32 | +test("Should throw error for malformed numeric ranks", () => { |
| 33 | + expect(() => getCardValue("0x02♠")).toThrow(); |
| 34 | + expect(() => getCardValue("2.1♠")).toThrow(); |
| 35 | + expect(() => getCardValue("0002♠")).toThrow(); |
28 | 36 | }); |
29 | 37 |
|
30 | | -// negative numerator |
31 | | -test("should return false when numerator is negative", () => { |
32 | | - expect(isProperFraction(-2, 4)).toEqual(false); |
33 | | -}); |
34 | | - |
35 | | -// negative denominator |
36 | | -test("should return false when denominator is negative", () => { |
37 | | - expect(isProperFraction(5, -4)).toEqual(false); |
38 | | -}); |
39 | | - |
40 | | -// both negative |
41 | | -test("should return false when both numerator and denominator are negative", () => { |
42 | | - expect(isProperFraction(-3, -5)).toEqual(false); |
| 38 | +// Invalid structure cases |
| 39 | +test("Should throw error for malformed card structure", () => { |
| 40 | + expect(() => getCardValue("")).toThrow(); |
| 41 | + expect(() => getCardValue("♠")).toThrow(); |
| 42 | + expect(() => getCardValue("10")).toThrow(); |
| 43 | + expect(() => getCardValue("A♠♠")).toThrow(); |
| 44 | + expect(() => getCardValue(" 2♠")).toThrow(); |
| 45 | + expect(() => getCardValue("2♠ ")).toThrow(); |
43 | 46 | }); |
0 commit comments