Skip to content

Commit 9fc0d42

Browse files
committed
Format file with Prettier and revise test descriptions
1 parent 431a4ef commit 9fc0d42

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
if (typeof card !== "string") {
25+
if (typeof card !== "string") {
2626
throw new Error("Invalid card");
2727
}
2828
let rank = card.slice(0, -1); // Get everything except the last character
29-
let suit = card.slice(-1); // Get the last character
30-
29+
let suit = card.slice(-1); // Get the last character
30+
3131
const validSuits = ["♠", "♥", "♦", "♣"]; // check if suit is valid
3232
if (!validSuits.includes(suit)) {
3333
throw new Error("Invalid card");
3434
}
3535

36-
if (rank === "A"){
36+
if (rank === "A") {
3737
return 11;
38-
}else if(/^[JQK]$/.test(rank)){
38+
} else if (/^[JQK]$/.test(rank)) {
3939
return 10;
40-
}else if(rank.match(/^(10|[2-9])$/)){
40+
} else if (rank.match(/^(10|[2-9])$/)) {
4141
return Number(rank);
42-
}else throw new Error("Invalid card");
42+
} else throw new Error("Invalid card");
4343
}
4444
// The line below allows us to load the getCardValue function into tests in other files.
4545
// This will be useful in the "rewrite tests with jest" step.
@@ -71,28 +71,28 @@ try {
7171
// What other invalid card cases can you think of?
7272

7373
try {
74-
getCardValue("9X"); // invalid suit
74+
getCardValue("9X"); // invalid suit
7575
console.error('Test failed for "9X": error was not thrown');
7676
} catch (e) {
7777
console.log('Test passed for "9X": caught error ->', e.message);
7878
}
7979

8080
try {
81-
getCardValue("1♠"); // invalid rank
81+
getCardValue("1♠"); // invalid rank
8282
console.error('Test failed for "1♠": error was not thrown');
8383
} catch (e) {
8484
console.log('Test passed for "1♠": caught error ->', e.message);
8585
}
8686

8787
try {
88-
getCardValue("0♥"); // invalid rank
88+
getCardValue("0♥"); // invalid rank
8989
console.error('Test failed for "0♥": error was not thrown');
9090
} catch (e) {
9191
console.log('Test passed for "0♥": caught error ->', e.message);
9292
}
9393

9494
try {
95-
getCardValue("ABC"); // completely wrong format
95+
getCardValue("ABC"); // completely wrong format
9696
console.error('Test failed for "ABC": error was not thrown');
9797
} catch (e) {
9898
console.log('Test passed for "ABC": caught error ->', e.message);

Sprint-3/1-implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
55
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
66

77
// Special case: numerator is zero
8-
test(`should return false when denominator is zero`, () => {
8+
test("returns false when denominator is zero", () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11-
test(`should return false when denominator is less than numerator`, () => {
12-
expect(isProperFraction(2, 1)).toEqual(false);
13-
});
14-
test("should return false when numerator is zero", ()=>{
11+
12+
test("returns false when numerator is zero", () => {
1513
expect(isProperFraction(0, 1)).toEqual(false);
1614
});
17-
test("should return false when numerator is a negative number", ()=>{
15+
16+
test("returns false when numerator > denominator", () => {
17+
expect(isProperFraction(2, 1)).toEqual(false);
18+
});
19+
20+
test("returns false when numerator is negative", () => {
1821
expect(isProperFraction(-2, 2)).toEqual(false);
1922
});
20-
test("should return false when denominator is a negative number", ()=>{
23+
24+
test("returns false when denominator is negative", () => {
2125
expect(isProperFraction(2, -2)).toEqual(false);
2226
});
23-
test("should return false where both numerator and denominator are negative numbers", ()=> {
27+
28+
test("returns false when both numerator and denominator are negative", () => {
2429
expect(isProperFraction(-3, -4)).toEqual(false);
25-
})
30+
});

0 commit comments

Comments
 (0)