-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-get-card-value.test.js
More file actions
38 lines (32 loc) · 1.16 KB
/
Copy path3-get-card-value.test.js
File metadata and controls
38 lines (32 loc) · 1.16 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
// 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");
test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});
// Case 2: Handle Number Cards (2-10):
for (let i = 2; i <= 10; i++) {
test(`should return ${i} for a number card ${i}♥`, () => {
const card = getCardValue(`${i}♥`);
expect(card).toEqual(i);
});
}
// Case 3: Handle Face Cards (J, Q, K):
const faceCards = ["J", "Q", "K"];
for (let faceCard of faceCards) {
test(`should return 10 for a card card ${faceCard}♢`, () => {
const card = getCardValue(`${faceCard}♢`);
expect(card).toEqual(10);
});
}
// Case 4: Handle Ace (A):
test("should return 11 for an Ace", () => {
const ace = getCardValue("A♠");
expect(ace).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should return `Invalid card rank.` for an invalid card", () => {
const invalidRank = getCardValue("@");
expect(invalidRank).toEqual("Invalid card rank.");
});