Skip to content

Commit da17f68

Browse files
committed
fix: tests.js
2 parents b1be443 + 9837435 commit da17f68

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ function formatTimeDisplay(seconds) {
3030
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3131
// =============> write your answer here
3232

33-
// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
33+
// e) What is the return value of pad when it is called for the last time in this program? Explain your answer
3434
// =============> write your answer here

Sprint-3/1-implement-and-rewrite-tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ to choose test values that thoroughly test a function.
88
In the `implement` directory you've got a number of functions you'll need to implement.
99
For each function, you also have a number of different cases you'll need to check for your function.
1010

11-
Write your assertions and build up your program case by case. Don't rush to a solution. The point of these assignments is to learn how to write assertions and build up a program step by step.
11+
Write your implementation and your tests to cover the cases the function should fulfil.
1212

1313
Here is a recommended order:
1414

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,57 @@ function getCardValue(card) {
2929
throw new Error("Invalid card");
3030
}
3131

32-
module.exports = getCardValue;
32+
<<<<<<< HEAD
33+
module.exports = getCardValue;
34+
=======
35+
// The line below allows us to load the getCardValue function into tests in other files.
36+
// This will be useful in the "rewrite tests with jest" step.
37+
module.exports = getCardValue;
38+
39+
// Helper functions to make our assertions easier to read.
40+
function assertEquals(actualOutput, targetOutput) {
41+
console.assert(
42+
actualOutput === targetOutput,
43+
`Expected ${actualOutput} to equal ${targetOutput}`
44+
);
45+
}
46+
47+
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
48+
// Examples:
49+
assertEquals(getCardValue("9♠"), 9);
50+
51+
// Ace
52+
assertEquals(getCardValue("A♠"), 11);
53+
54+
// Face cards
55+
assertEquals(getCardValue("J♥"), 10);
56+
assertEquals(getCardValue("Q♦"), 10);
57+
assertEquals(getCardValue("K♣"), 10);
58+
59+
// Number cards
60+
assertEquals(getCardValue("2♠"), 2);
61+
assertEquals(getCardValue("10♥"), 10);
62+
63+
// Handling invalid cards
64+
try {
65+
getCardValue("invalid");
66+
67+
// This line will not be reached if an error is thrown as expected
68+
console.error("Error was not thrown for invalid card 😢");
69+
} catch (e) {
70+
console.log("Error thrown for invalid card 🎉");
71+
}
72+
73+
// More invalid cases
74+
try {
75+
getCardValue("11♠");
76+
console.error("Error was not thrown for invalid card");
77+
} catch (e) {}
78+
79+
try {
80+
getCardValue("A");
81+
console.error("Error was not thrown for invalid card");
82+
} catch (e) {}
83+
84+
// What other invalid card cases can you think of?
85+
>>>>>>> 983743526bc0a40a31b8e20926f23fa3ceb5cf29

0 commit comments

Comments
 (0)