Skip to content

Commit 1a326b8

Browse files
author
Enice-Codes
committed
Remove unrelated file changes not part of practice-tdd task
1 parent 7cd3556 commit 1a326b8

2 files changed

Lines changed: 42 additions & 21 deletions

File tree

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@
99
// Acceptance criteria:
1010
// After you have implemented the function, write tests to cover all the cases, and
1111
// execute the code to ensure all tests pass.
12+
1213
function isProperFraction(numerator, denominator) {
13-
if (denominator === 0) {
14-
return false;
15-
}
14+
// TODO: Implement this function
15+
}
1616

17-
return Math.abs(numerator) < Math.abs(denominator);
17+
// The line below allows us to load the isProperFraction function into tests in other files.
18+
// This will be useful in the "rewrite tests with jest" step.
19+
module.exports = isProperFraction;
20+
21+
// Here's our helper again
22+
function assertEquals(actualOutput, targetOutput) {
23+
console.assert(
24+
actualOutput === targetOutput,
25+
`Expected ${actualOutput} to equal ${targetOutput}`
26+
);
1827
}
1928

20-
module.exports = isProperFraction;
29+
// TODO: Write tests to cover all cases.
30+
// What combinations of numerators and denominators should you test?
31+
32+
// Example: 1/2 is a proper fraction
33+
assertEquals(isProperFraction(1, 2), true);

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,35 @@
2020
// Acceptance criteria:
2121
// After you have implemented the function, write tests to cover all the cases, and
2222
// execute the code to ensure all tests pass.
23-
function getCardValue(card) {
24-
const rank = card.slice(0, -1);
25-
const suit = card.slice(-1);
2623

27-
const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
24+
function getCardValue(card) {
25+
// TODO: Implement this function
26+
}
2827

29-
const validSuits = ["♠", "♥", "♦", "♣"];
28+
// The line below allows us to load the getCardValue function into tests in other files.
29+
// This will be useful in the "rewrite tests with jest" step.
30+
module.exports = getCardValue;
3031

31-
if (!validRanks.includes(rank) || !validSuits.includes(suit)) {
32-
throw new Error("Invalid card");
33-
}
32+
// Helper functions to make our assertions easier to read.
33+
function assertEquals(actualOutput, targetOutput) {
34+
console.assert(
35+
actualOutput === targetOutput,
36+
`Expected ${actualOutput} to equal ${targetOutput}`
37+
);
38+
}
3439

35-
if (rank === "A") {
36-
return 11;
37-
}
40+
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
41+
// Examples:
42+
assertEquals(getCardValue("9♠"), 9);
3843

39-
if (["J", "Q", "K"].includes(rank)) {
40-
return 10;
41-
}
44+
// Handling invalid cards
45+
try {
46+
getCardValue("invalid");
4247

43-
return Number(rank);
48+
// This line will not be reached if an error is thrown as expected
49+
console.error("Error was not thrown for invalid card 😢");
50+
} catch (e) {
51+
console.log("Error thrown for invalid card 🎉");
4452
}
4553

46-
module.exports = getCardValue;
54+
// What other invalid card cases can you think of?

0 commit comments

Comments
 (0)