Skip to content

Commit 95a7938

Browse files
committed
Done the Implement and rewrite
1 parent c83ad2f commit 95a7938

File tree

3 files changed

+60
-28
lines changed

3 files changed

+60
-28
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,33 @@
1414
// execute the code to ensure all tests pass.
1515

1616
function getAngleType(angle) {
17-
function getAngleType(angle) {
18-
if (angle <= 0 || angle >= 360)
19-
}
17+
if (angle <= 0 || angle >= 360) {
18+
return "Invalid angle";
19+
}
2020

2121
if (angle < 90) {
22-
return "acute angle";
22+
return "Acute angle";
23+
}
24+
if (angle === 90) {
25+
return "Right angle";
26+
}
27+
if (angle < 180) {
28+
return "Obtuse angle";
29+
}
30+
if (angle === 180) {
31+
return "Straight angle";
32+
}
33+
if (angle < 360) {
34+
return "Reflex angle";
2335
}
24-
if (angle === 90) {
25-
return "right angle";
26-
}
27-
if (angle < 180){
28-
return "obtuse angle";
29-
}
30-
if (angle === 180){
31-
return "straight angle";
32-
}
33-
if (angle < 360){
34-
return "reflex angle";
3536
}
3637
module.exports = getAngleType;
3738

38-
39-
// TODO: Implement this function
40-
39+
// TODO: Implement this function
4140

4241
// The line below allows us to load the getAngleType function into tests in other files.
4342
// This will be useful in the "rewrite tests with jest" step.
4443

45-
4644
// This helper function is written to make our assertions easier to read.
4745
// If the actual output matches the target output, the test will pass
4846
function assertEquals(actualOutput, targetOutput) {
@@ -57,7 +55,7 @@ function assertEquals(actualOutput, targetOutput) {
5755
const right = getAngleType(90);
5856
assertEquals(right, "Right angle");
5957

60-
// Test
58+
// Test
6159
assertEquals(getAngleType(45), "Acute angle");
6260
assertEquals(getAngleType(90), "Right angle");
6361
assertEquals(getAngleType(120), "Obtuse angle");

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,37 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
14+
return numerator < denominator;
1515
}
1616

1717
// The line below allows us to load the isProperFraction function into tests in other files.
1818
// This will be useful in the "rewrite tests with jest" step.
19-
module.exports = isProperFraction;
2019

21-
// Here's our helper again
20+
// Here's our hel per again
2221
function assertEquals(actualOutput, targetOutput) {
2322
console.assert(
2423
actualOutput === targetOutput,
2524
`Expected ${actualOutput} to equal ${targetOutput}`
2625
);
2726
}
27+
module.exports = isProperFraction;
2828

2929
// TODO: Write tests to cover all cases.
3030
// What combinations of numerators and denominators should you test?
3131

32-
// Example: 1/2 is a proper fraction
33-
assertEquals(isProperFraction(1, 2), true);
32+
//Test
33+
// Proper fraction
34+
assertEquals(isProperFraction(3, 5), true);
35+
assertEquals(isProperFraction(4, 8), true);
36+
assertEquals(isProperFraction(-1, 2), true);
37+
assertEquals(isProperFraction(-1, -2), true);
38+
assertEquals(isProperFraction(1, -2), true);
39+
40+
//Not
41+
assertEquals(isProperFraction(9, 7), false);
42+
assertEquals(isProperFraction(13, 11), false);
43+
assertEquals(isProperFraction(19, 10), false);
44+
assertEquals(isProperFraction(17, 3), false);
45+
46+
//Edge case
47+
assertEquals(isProperFraction(0, 5), true);

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

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

2424
function getCardValue(card) {
25-
// TODO: Implement this function
25+
const rank = card.slice(0, -1);
26+
const suit = card.slice(-1);
27+
28+
const vaildSuits = ["♠", "♥", "♦", "♣"];
29+
const vailRanks = ["A","2","3","4","5","6","7","8","9","10","J","Q","k"];
30+
31+
if (!vaildSuits.includes(suit) || !validRanks.inculdes(rank)){
32+
throw new Error("Invaild card");
33+
}
34+
if (rank === "A") return 11;
35+
if (rank === "J" || rank === "Q" || rank === "K") return 10;
36+
37+
return Number(rank);
2638
}
2739

40+
module.exports = getCardValue;
41+
42+
2843
// The line below allows us to load the getCardValue function into tests in other files.
2944
// This will be useful in the "rewrite tests with jest" step.
30-
module.exports = getCardValue;
45+
3146

3247
// Helper functions to make our assertions easier to read.
3348
function assertEquals(actualOutput, targetOutput) {
@@ -40,13 +55,18 @@ function assertEquals(actualOutput, targetOutput) {
4055
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4156
// Examples:
4257
assertEquals(getCardValue("9♠"), 9);
58+
//Test
59+
assertEquals(getCardvalue("A♠"), 11);
60+
assertEquals(getCardEqual("J♣), 10);
61+
assertEquals(getCardequal("10♥"), 10);
4362

4463
// Handling invalid cards
4564
try {
4665
getCardValue("invalid");
66+
4767

4868
// This line will not be reached if an error is thrown as expected
4969
console.error("Error was not thrown for invalid card");
5070
} catch (e) {}
5171

52-
// What other invalid card cases can you think of?
72+
// What other invalid card cases can you think of?

0 commit comments

Comments
 (0)