Skip to content

Commit 02bb64f

Browse files
committed
Implement and rewrite test done
1 parent 3372770 commit 02bb64f

File tree

3 files changed

+113
-4
lines changed

3 files changed

+113
-4
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,27 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
// TODO: Implement this function
18+
if (angle > 0 && angle < 90) {
19+
return "Acute angle";
20+
}
21+
22+
if (angle === 90) {
23+
return "Right angle";
24+
}
25+
26+
if (angle > 90 && angle < 180) {
27+
return "Obtuse angle";
28+
}
29+
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";
1939
}
2040

2141
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +55,22 @@ function assertEquals(actualOutput, targetOutput) {
3555
// Example: Identify Right Angles
3656
const right = getAngleType(90);
3757
assertEquals(right, "Right angle");
58+
59+
// Acute
60+
assertEquals(getAngleType(45), "Acute angle");
61+
62+
// Right
63+
assertEquals(getAngleType(90), "Right angle");
64+
65+
// Obtuse
66+
assertEquals(getAngleType(120), "Obtuse angle");
67+
68+
// Straight
69+
assertEquals(getAngleType(180), "Straight angle");
70+
71+
// Reflex
72+
assertEquals(getAngleType(270), "Reflex angle");
73+
74+
// Invalid
75+
assertEquals(getAngleType(0), "Invalid angle");
76+
assertEquals(getAngleType(360), "Invalid angle");

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

Lines changed: 15 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+
if (denominator === 0) {
16+
return false;
17+
}
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,13 @@ function assertEquals(actualOutput, targetOutput) {
3136

3237
// Example: 1/2 is a proper fraction
3338
assertEquals(isProperFraction(1, 2), true);
39+
assertEquals(isProperFraction(-1, 2), true);
40+
assertEquals(isProperFraction(1, -2), true);
41+
42+
// Improper fractions
43+
assertEquals(isProperFraction(2, 2), false);
44+
assertEquals(isProperFraction(3, 2), false);
45+
assertEquals(isProperFraction(-3, 2), false);
46+
47+
// Invalid denominator
48+
assertEquals(isProperFraction(1, 0), false);

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

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

2424
function getCardValue(card) {
25-
// TODO: Implement this function
25+
const suit = card.slice(-1);
26+
const rank = card.slice(0, -1);
27+
28+
const validSuits = ["♠", "♥", "♦", "♣"];
29+
30+
if (!validSuits.includes(suit)) {
31+
throw new Error("Invalid card");
32+
}
33+
34+
if (rank === "A") {
35+
return 11;
36+
}
37+
38+
if (rank === "J" || rank === "Q" || rank === "K") {
39+
return 10;
40+
}
41+
42+
if (
43+
rank === "2" ||
44+
rank === "3" ||
45+
rank === "4" ||
46+
rank === "5" ||
47+
rank === "6" ||
48+
rank === "7" ||
49+
rank === "8" ||
50+
rank === "9" ||
51+
rank === "10"
52+
) {
53+
return Number(rank);
54+
}
55+
56+
throw new Error("Invalid card");
2657
}
2758

2859
// The line below allows us to load the getCardValue function into tests in other files.
@@ -38,8 +69,19 @@ function assertEquals(actualOutput, targetOutput) {
3869
}
3970

4071
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
41-
// Examples:
72+
73+
// Ace
74+
assertEquals(getCardValue("A♠"), 11);
75+
76+
// Face cards
77+
assertEquals(getCardValue("J♣"), 10);
78+
assertEquals(getCardValue("Q♦"), 10);
79+
assertEquals(getCardValue("K♥"), 10);
80+
81+
// Number cards
82+
assertEquals(getCardValue("2♥"), 2);
4283
assertEquals(getCardValue("9♠"), 9);
84+
assertEquals(getCardValue("10♦"), 10);
4385

4486
// Handling invalid cards
4587
try {
@@ -49,4 +91,17 @@ try {
4991
console.error("Error was not thrown for invalid card");
5092
} catch (e) {}
5193

52-
// What other invalid card cases can you think of?
94+
try {
95+
getCardValue("1♠");
96+
console.error("Error was not thrown for invalid rank");
97+
} catch (e) {}
98+
99+
try {
100+
getCardValue("A");
101+
console.error("Error was not thrown for missing suit");
102+
} catch (e) {}
103+
104+
try {
105+
getCardValue("A★");
106+
console.error("Error was not thrown for invalid suit");
107+
} catch (e) {}

0 commit comments

Comments
 (0)