Skip to content

Commit 13eba78

Browse files
committed
rewrite tests and code
1 parent 49eff3b commit 13eba78

1 file changed

Lines changed: 46 additions & 6 deletions

File tree

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

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,58 @@
33
const getCardValue = require("../implement/3-get-card-value");
44

55
// TODO: Write tests in Jest syntax to cover all possible outcomes.
6+
// Suggestion: Group the remaining test data into these categories:
7+
// Number Cards (2-10)
8+
// Face Cards (J, Q, K)
9+
// Invalid Cards
610

711
// Case 1: Ace (A)
812
test(`Should return 11 when given an ace card`, () => {
913
expect(getCardValue("A♠")).toEqual(11);
1014
});
1115

12-
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
15-
// Invalid Cards
16+
// Case 2: Number cards (2-9)
17+
test(`Should return corresponding number when given a number card`, () => {
18+
expect(getCardValue("2♠")).toEqual(2);
19+
expect(getCardValue("3♠")).toEqual(3);
20+
expect(getCardValue("4♠")).toEqual(4);
21+
expect(getCardValue("5♠")).toEqual(5);
22+
expect(getCardValue("6♠")).toEqual(6);
23+
expect(getCardValue("7♠")).toEqual(7);
24+
expect(getCardValue("8♠")).toEqual(8);
25+
expect(getCardValue("9♠")).toEqual(9);
26+
});
1627

28+
// Case 3: Number cards (10)
29+
test(`Should return 10 when given a 10 card`, () => {
30+
expect(getCardValue("10♠")).toEqual(10);
31+
});
32+
33+
// Case 4: Face cards (J, Q, K)
34+
test(`Should return 10 when given a J card`, () => {
35+
expect(getCardValue("J♠")).toEqual(10);
36+
});
37+
38+
// Case 5: Face cards (J, Q, K)
39+
test(`Should return 10 when given a Q card`, () => {
40+
expect(getCardValue("Q♠")).toEqual(10);
41+
});
42+
43+
// Case 6: Face cards (J, Q, K)
44+
test(`Should return 10 when given a K card`, () => {
45+
expect(getCardValue("K♠")).toEqual(10);
46+
});
47+
48+
// Invalid cases
49+
test(`should throw an error with message "Invalid card format" when given invalid card`, () => {
50+
expect(() => getCardValue("1♠")).toThrow("Invalid card format");
51+
expect(() => getCardValue("11♥")).toThrow("Invalid card format");
52+
expect(() => getCardValue("A1")).toThrow("Invalid card format");
53+
expect(() => getCardValue("1A")).toThrow("Invalid card format");
54+
expect(() => getCardValue("♣10")).toThrow("Invalid card format");
55+
expect(() => getCardValue("$$")).toThrow("Invalid card format");
56+
expect(() => getCardValue("-5♣")).toThrow("Invalid card format");
57+
});
1758
// To learn how to test whether a function throws an error as expected in Jest,
1859
// please refer to the Jest documentation:
19-
// https://jestjs.io/docs/expect#tothrowerror
20-
60+
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)