Skip to content

Commit 8934909

Browse files
completes sprint 3 task 1 exercise 3 pt 2
1 parent f59e42d commit 8934909

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/package.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,40 @@ const getCardValue = require("../implement/3-get-card-value");
66

77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
9+
expect(getCardValue("A♣")).toEqual(11);
910
expect(getCardValue("A♠")).toEqual(11);
11+
expect(getCardValue("A♥")).toEqual(11);
12+
expect(getCardValue("A♦")).toEqual(11);
1013
});
1114

12-
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
15-
// Invalid Cards
15+
// Case 2: Number Cards (2-10)
16+
test(`Should return a value equal to the number on the card`, () => {
17+
expect(getCardValue("2♠")).toEqual(2);
18+
expect(getCardValue("5♥")).toEqual(5);
19+
expect(getCardValue("9♦")).toEqual(9);
20+
expect(getCardValue("10♣")).toEqual(10);
21+
});
22+
23+
// Case 3: Face Cards (J, Q, K)
24+
test(`Should return 10 when given a face card`, () => {
25+
expect(getCardValue("K♥")).toEqual(10);
26+
expect(getCardValue("J♠")).toEqual(10);
27+
expect(getCardValue("Q♦")).toEqual(10);
28+
});
1629

30+
// Case 4: Invalid Cards
31+
test(`All invalid cards should throw an Invalid error`, () => {
32+
expect(() => getCardValue("9")).toThrow(/Invalid/); // missing suit
33+
expect(() => getCardValue("♥")).toThrow(/Invalid/); // missing rank
34+
expect(() => getCardValue("1♠")).toThrow(/Invalid/); // invalid rank
35+
expect(() => getCardValue("11♠")).toThrow(/Invalid/); // rank too high
36+
expect(() => getCardValue("9X")).toThrow(/Invalid/); // invalid suit
37+
expect(() => getCardValue("♠9")).toThrow(/Invalid/); // wrong order
38+
expect(() => getCardValue("9 ♠")).toThrow(/Invalid/); // space inside
39+
expect(() => getCardValue("9♠ ")).toThrow(/Invalid/); // space after
40+
expect(() => getCardValue("")).toThrow(/Invalid/); // empty string
41+
expect(() => getCardValue("j♠")).toThrow(/Invalid/); // lowercase
42+
});
1743
// To learn how to test whether a function throws an error as expected in Jest,
1844
// please refer to the Jest documentation:
1945
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)