Skip to content

Commit a7c6832

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
added assert tests for implement 1, 2 and 3
1 parent 9c3d4d8 commit a7c6832

3 files changed

Lines changed: 58 additions & 5 deletions

File tree

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
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) {return "Acute angle";}
19+
if (angle == 90) {return "Right angle";}
20+
if (angle > 90 && angle < 180) {return "Obtuse angle";}
21+
if (angle == 180) {return "Straight angle";}
22+
if (angle > 180 && angle < 360) {return "Reflex angle";}
23+
else return "Invalid angle"
1924
}
2025

2126
// The line below allows us to load the getAngleType function into tests in other files.
@@ -33,5 +38,24 @@ function assertEquals(actualOutput, targetOutput) {
3338

3439
// TODO: Write tests to cover all cases, including boundary and invalid cases.
3540
// Example: Identify Right Angles
36-
const right = getAngleType(90);
37-
assertEquals(right, "Right angle");
41+
42+
assertEquals(getAngleType(-1), "Invalid angle");
43+
assertEquals(getAngleType(0), "Invalid angle");
44+
assertEquals(getAngleType(360), "Invalid angle");
45+
assertEquals(getAngleType(10000), "Invalid angle");
46+
47+
assertEquals(getAngleType(1), "Acute angle");
48+
assertEquals(getAngleType(45), "Acute angle");
49+
assertEquals(getAngleType(89.99), "Acute angle");
50+
assertEquals(getAngleType(45), "Acute angle");
51+
52+
assertEquals(getAngleType(90), "Right angle");
53+
54+
assertEquals(getAngleType(91), "Obtuse angle");
55+
assertEquals(getAngleType(179), "Obtuse angle");
56+
57+
assertEquals(getAngleType(180), "Straight angle");
58+
59+
assertEquals(getAngleType(181), "Reflex angle");
60+
assertEquals(getAngleType(359), "Reflex angle");
61+

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// execute the code to ensure all tests pass.
1212

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

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

3232
// Example: 1/2 is a proper fraction
3333
assertEquals(isProperFraction(1, 2), true);
34+
assertEquals(isProperFraction(0.1, 2), true);
35+
assertEquals(isProperFraction(-1, 2), true);
36+
assertEquals(isProperFraction(1, -2), true);
37+
assertEquals(isProperFraction(100000, 200000), true);
38+
39+
assertEquals(isProperFraction(2, 1), false);
40+
assertEquals(isProperFraction(2, 0.1), false);
41+
assertEquals(isProperFraction(2, -1), false);
42+
assertEquals(isProperFraction(-2, 1), false);
43+
assertEquals(isProperFraction(200000, 100000), false);

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
// TODO: Implement this function
25+
const suits = ["♠", "♥", "♦", "♣"];
26+
if (!suits.includes(card.slice(-1))) {throw new Error("Invalid card");}
27+
28+
const value = card.slice(0, -1);
29+
if (value == 10) {return 10;}
30+
if (value >= 2 && value <= 9) {return Number(value);}
31+
if (value == "J" || value == "Q" || value == "K") {return 10;}
32+
if (value == "A") {return 11;}
33+
else throw new Error("Invalid card");
2634
}
2735

2836
// The line below allows us to load the getCardValue function into tests in other files.
@@ -39,7 +47,13 @@ function assertEquals(actualOutput, targetOutput) {
3947

4048
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4149
// Examples:
50+
assertEquals(getCardValue("2♠"), 2);
4251
assertEquals(getCardValue("9♠"), 9);
52+
assertEquals(getCardValue("10♥"), 10);
53+
assertEquals(getCardValue("J♥"), 10);
54+
assertEquals(getCardValue("Q♦"), 10);
55+
assertEquals(getCardValue("K♦"), 10);
56+
assertEquals(getCardValue("A♣"), 11);
4357

4458
// Handling invalid cards
4559
try {
@@ -52,3 +66,8 @@ try {
5266
}
5367

5468
// What other invalid card cases can you think of?
69+
// decimal numbers
70+
// cards without suits
71+
// numbers above 10
72+
// negative numbers
73+
// letters outside J K Q and A

0 commit comments

Comments
 (0)