Skip to content

Commit c9ae221

Browse files
committed
Adjusments made on Sprint 3 - Implement and rewrite tests
1 parent 3372770 commit c9ae221

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,29 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19+
// You can use if-else statements or a switch statement to determine the type of angle based on the input value.
20+
if (angle > 0 && angle < 90) {
21+
return "Acute angle";
22+
} else if (angle === 90) {
23+
return "Right angle";
24+
} else if (angle > 90 && angle < 180) {
25+
return "Obtuse angle";
26+
} else if (angle === 180) {
27+
return "Straight angle";
28+
} else if (angle > 180 && angle < 360) {
29+
return "Reflex angle";
30+
} else {
31+
return "Invalid angle";
32+
}
1933
}
2034

2135
// The line below allows us to load the getAngleType function into tests in other files.
2236
// This will be useful in the "rewrite tests with jest" step.
2337
module.exports = getAngleType;
38+
// You can run this file with node to check your implementation, but you will need to write tests to cover all cases, including boundary and invalid cases.
39+
// Example: Identify Right Angles
40+
const right = getAngleType(90);
41+
console.log(right); // Output: "Right angle"
2442

2543
// This helper function is written to make our assertions easier to read.
2644
// If the actual output matches the target output, the test will pass
@@ -31,7 +49,26 @@ function assertEquals(actualOutput, targetOutput) {
3149
);
3250
}
3351

52+
3453
// TODO: Write tests to cover all cases, including boundary and invalid cases.
3554
// Example: Identify Right Angles
3655
const right = getAngleType(90);
3756
assertEquals(right, "Right angle");
57+
// Example: Identify Acute Angles
58+
const acute = getAngleType(45);
59+
assertEquals(acute, "Acute angle");
60+
// Example: Identify Obtuse Angles
61+
const obtuse = getAngleType(120);
62+
assertEquals(obtuse, "Obtuse angle");
63+
// Example: Identify Straight Angles
64+
const straight = getAngleType(180);
65+
assertEquals(straight, "Straight angle");
66+
// Example: Identify Reflex Angles
67+
const reflex = getAngleType(270);
68+
assertEquals(reflex, "Reflex angle");
69+
// Example: Identify Invalid Angles
70+
const invalid = getAngleType(-10);
71+
assertEquals(invalid, "Invalid angle");
72+
const invalid2 = getAngleType(360);
73+
assertEquals(invalid2, "Invalid angle");
74+

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
// A proper fraction is a fraction where the absolute value of the numerator is less than the absolute value of the denominator. Additionally, the denominator cannot be zero. Therefore, we can check if the absolute value of the numerator is less than the absolute value of the denominator and if the denominator is not zero to determine if it is a proper fraction.
16+
if (denominator === 0) {
17+
return false; // A fraction cannot have a denominator of zero
18+
}
19+
return Math.abs(numerator) < Math.abs(denominator);
1520
}
1621

1722
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +36,18 @@ function assertEquals(actualOutput, targetOutput) {
3136

3237
// Example: 1/2 is a proper fraction
3338
assertEquals(isProperFraction(1, 2), true);
39+
// Example: 2/1 is not a proper fraction
40+
assertEquals(isProperFraction(2, 1), false);
41+
// Example: -1/2 is a proper fraction
42+
assertEquals(isProperFraction(-1, 2), true);
43+
// Example: 1/-2 is a proper fraction
44+
assertEquals(isProperFraction(1, -2), true);
45+
// Example: -1/-2 is a proper fraction
46+
assertEquals(isProperFraction(-1, -2), true);
47+
// Example: 0/5 is a proper fraction
48+
assertEquals(isProperFraction(0, 5), true);
49+
// Example: 5/0 is not a proper fraction
50+
assertEquals(isProperFraction(5, 0), false);
51+
// Example: 5/5 is not a proper fraction
52+
assertEquals(isProperFraction(5, 5), false);
53+

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
const rank = card.slice(0, -1); // Get the rank by slicing off the last character (the suit)
27+
const suit = card.slice(-1); // Get the suit by taking the last character
28+
29+
// Define valid ranks and suits
30+
const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
31+
const validSuits = ["♠", "♥", "♦", "♣"];
32+
33+
// Check if the rank and suit are valid
34+
if (!validRanks.includes(rank) || !validSuits.includes(suit)) {
35+
throw new Error("Invalid card");
36+
}
37+
38+
// Determine the value based on the rank
39+
if (rank === "A") {
40+
return 11;
41+
} else if (["J", "Q", "K"].includes(rank)) {
42+
return 10;
43+
} else {
44+
return parseInt(rank); // Convert number cards to their numeric value
45+
}
46+
2647
}
2748

2849
// The line below allows us to load the getCardValue function into tests in other files.
@@ -40,6 +61,12 @@ function assertEquals(actualOutput, targetOutput) {
4061
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4162
// Examples:
4263
assertEquals(getCardValue("9♠"), 9);
64+
assertEquals(getCardValue("A♥"), 11);
65+
assertEquals(getCardValue("J♦"), 10);
66+
assertEquals(getCardValue("Q♣"), 10);
67+
assertEquals(getCardValue("K♠"), 10);
68+
69+
// You should also test the boundary cases, such as "10♥", and invalid cases, such as "11♠" or "A" or "♠".
4370

4471
// Handling invalid cards
4572
try {
@@ -49,4 +76,25 @@ try {
4976
console.error("Error was not thrown for invalid card");
5077
} catch (e) {}
5178

79+
5280
// What other invalid card cases can you think of?
81+
try {
82+
getCardValue("11♠");
83+
84+
// This line will not be reached if an error is thrown as expected
85+
console.error("Error was not thrown for invalid card");
86+
} catch (e) {}
87+
88+
try {
89+
getCardValue("A");
90+
91+
// This line will not be reached if an error is thrown as expected
92+
console.error("Error was not thrown for invalid card");
93+
} catch (e) {}
94+
95+
try {
96+
getCardValue("♠");
97+
98+
// This line will not be reached if an error is thrown as expected
99+
console.error("Error was not thrown for invalid card");
100+
} catch (e) {}

0 commit comments

Comments
 (0)