Skip to content

Commit 95a30fe

Browse files
author
Enice-Codes
committed
modified
1 parent 01bb3df commit 95a30fe

3 files changed

Lines changed: 42 additions & 60 deletions

File tree

Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
// TODO: Implement this function
19-
}
18+
if (angle > 0 && angle < 90) {
19+
return "Acute angle";
20+
}
2021

21-
// The line below allows us to load the getAngleType function into tests in other files.
22-
// This will be useful in the "rewrite tests with jest" step.
23-
module.exports = getAngleType;
24-
25-
// This helper function is written to make our assertions easier to read.
26-
// If the actual output matches the target output, the test will pass
27-
function assertEquals(actualOutput, targetOutput) {
28-
console.assert(
29-
actualOutput === targetOutput,
30-
`Expected ${actualOutput} to equal ${targetOutput}`
31-
);
32-
}
22+
if (angle === 90) {
23+
return "Right angle";
24+
}
25+
26+
if (angle > 90 && angle < 180) {
27+
return "Obtuse angle";
28+
}
3329

34-
// TODO: Write tests to cover all cases, including boundary and invalid cases.
35-
// Example: Identify Right Angles
36-
const right = getAngleType(90);
37-
assertEquals(right, "Right angle");
30+
if (angle === 180) {
31+
return "Straight angle";
32+
}
33+
34+
if (angle > 180 && angle < 360) {
35+
return "Reflex angle";
36+
}
37+
38+
return "Invalid angle";
39+
}
40+
module.exports = getAngleType;

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,12 @@
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-
1312
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
15-
}
13+
if (denominator === 0) {
14+
return false;
15+
}
1616

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-
);
17+
return Math.abs(numerator) < Math.abs(denominator);
2718
}
2819

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);
20+
module.exports = isProperFraction;

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,27 @@
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-
2423
function getCardValue(card) {
25-
// TODO: Implement this function
26-
}
24+
const rank = card.slice(0, -1);
25+
const suit = card.slice(-1);
2726

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;
27+
const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
3128

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-
}
29+
const validSuits = ["♠", "♥", "♦", "♣"];
30+
31+
if (!validRanks.includes(rank) || !validSuits.includes(suit)) {
32+
throw new Error("Invalid card");
33+
}
3934

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

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

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 🎉");
43+
return Number(rank);
5244
}
5345

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

0 commit comments

Comments
 (0)