-
-
Notifications
You must be signed in to change notification settings - Fork 337
Expand file tree
/
Copy path3-get-card-value.test.js
More file actions
94 lines (87 loc) · 3.23 KB
/
3-get-card-value.test.js
File metadata and controls
94 lines (87 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// This statement loads the getCardValue function you wrote in the implement directory.
// We will use the same function, but write tests for it using Jest in this file.
const getCardValue = require("../implement/3-get-card-value");
// TODO: Write tests in Jest syntax to cover all possible outcomes.
// Case 1: Ace (A)
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♠")).toEqual(11);
});
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♥")).toEqual(11);
});
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♦")).toEqual(11);
});
test(`Should return 11 when given an ace card`, () => {
expect(getCardValue("A♣")).toEqual(11);
});
// Suggestion: Group the remaining test data into these categories:
// Number Cards (2-10)
test(`Should return 2 when given a 2 card`, () => {
expect(getCardValue("2♠")).toEqual(2);
});
test(`Should return 3 when given a 3 card`, () => {
expect(getCardValue("3♥")).toEqual(3);
});
test(`Should return 4 when given a 4 card`, () => {
expect(getCardValue("4♦")).toEqual(4);
});
test(`Should return 5 when given a 5 card`, () => {
expect(getCardValue("5♣")).toEqual(5);
});
test(`Should return 6 when given a 6 card`, () => {
expect(getCardValue("6♥")).toEqual(6);
});
test(`Should return 7 when given a 7 card`, () => {
expect(getCardValue("7♠")).toEqual(7);
});
test(`Should return 8 when given a 8 card`, () => {
expect(getCardValue("8♦")).toEqual(8);
});
test(`Should return 9 when given a 9 card`, () => {
expect(getCardValue("9♠")).toEqual(9);
});
test(`Should return 10 when given a 10 card`, () => {
expect(getCardValue("10♣")).toEqual(10);
});
// Face Cards (J, Q, K)
test(`Should return 10 when given a J card`, () => {
expect(getCardValue("J♠")).toEqual(10);
});
test(`Should return 10 when given a Q card`, () => {
expect(getCardValue("Q♦")).toEqual(10);
});
test(`Should return 10 when given a K card`, () => {
expect(getCardValue("K♥")).toEqual(10);
});
// Invalid Cards
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("1♠")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("2❦")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("11♥")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("B♦")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("Z♣")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("♣2")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("s")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("♣♥♠♦")).toThrow();
});
test(`Should throw an error when given an invalid card`, () => {
expect(() => getCardValue("")).toThrow();
});
// To learn how to test whether a function throws an error as expected in Jest,
// please refer to the Jest documentation:
// https://jestjs.io/docs/expect#tothrowerror