Skip to content

Commit 4a75c58

Browse files
committed
completion of exercises for tests and implementation for sprint3
1 parent ad004aa commit 4a75c58

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19-
}
19+
if (angle > 0 && angle < 90) {
20+
return "Acute angle";
21+
} else if (angle === 90) {
22+
return "Right angle";
23+
} else if (angle > 90 && angle < 180) {
24+
return "Obtuse angle";
25+
} else if (angle === 180) {
26+
return "Straight angle";
27+
} else if (angle > 180 && angle < 360) {
28+
return "Reflex angle";
29+
} else {
30+
return "Invalid angle";
31+
}
32+
}
2033

2134
// The line below allows us to load the getAngleType function into tests in other files.
2235
// This will be useful in the "rewrite tests with jest" step.
@@ -35,3 +48,13 @@ function assertEquals(actualOutput, targetOutput) {
3548
// Example: Identify Right Angles
3649
const right = getAngleType(90);
3750
assertEquals(right, "Right angle");
51+
const acute = getAngleType(45);
52+
assertEquals(acute, "Acute angle");
53+
const obtuse = getAngleType(120);
54+
assertEquals(obtuse, "Obtuse angle");
55+
const straight = getAngleType(180);
56+
assertEquals(straight, "Straight angle");
57+
const reflex = getAngleType(270);
58+
assertEquals(reflex, "Reflex angle");
59+
const invalid = getAngleType(400);
60+
assertEquals(invalid, "Invalid angle");

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

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

1313
function isProperFraction(numerator, denominator) {
14+
15+
1416
// TODO: Implement this function
17+
if (denominator === 0) {
18+
return false;
19+
}
20+
if (Math.abs(numerator) < Math.abs(denominator)) {
21+
return true;
22+
} else {
23+
return false;
24+
}
1525
}
1626

1727
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -24,10 +34,19 @@ function assertEquals(actualOutput, targetOutput) {
2434
actualOutput === targetOutput,
2535
`Expected ${actualOutput} to equal ${targetOutput}`
2636
);
37+
2738
}
2839

2940
// TODO: Write tests to cover all cases.
3041
// What combinations of numerators and denominators should you test?
3142

3243
// Example: 1/2 is a proper fraction
3344
assertEquals(isProperFraction(1, 2), true);
45+
assertEquals(isProperFraction(2, 1), false);
46+
assertEquals(isProperFraction(-1, 2), true);
47+
assertEquals(isProperFraction(1, -2), true);
48+
assertEquals(isProperFraction(0, 2), true);
49+
assertEquals(isProperFraction(2, 2), false);
50+
assertEquals(isProperFraction(-2, -1), false);
51+
assertEquals(isProperFraction(-2, -2), false);
52+
assertEquals(isProperFraction(1, 0), false);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
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 of the string
28+
29+
// Validate the suit
30+
const validSuits = ["♠", "♥", "♦", "♣"];
31+
if (!validSuits.includes(suit)) {
32+
throw new Error("Invalid card: Invalid suit");
33+
}
34+
// Determine the value based on the rank
35+
if (rank === "A") {
36+
return 11;
37+
} else if (["J", "Q", "K"].includes(rank)) {
38+
return 10;
39+
} else if (!isNaN(rank) && parseInt(rank) >= 2 && parseInt(rank) <= 10) {
40+
return parseInt(rank);
41+
} else {
42+
throw new Error("Invalid card: Invalid rank");
43+
}
2644
}
2745

2846
// The line below allows us to load the getCardValue function into tests in other files.

0 commit comments

Comments
 (0)