Skip to content

Commit e61fd75

Browse files
committed
Completion of 1-implement-and-rewrite-tests tasks
1 parent 0e99abc commit e61fd75

File tree

6 files changed

+114
-2
lines changed

6 files changed

+114
-2
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
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+
}
1932
}
2033

2134
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +48,18 @@ function assertEquals(actualOutput, targetOutput) {
3548
// Example: Identify Right Angles
3649
const right = getAngleType(90);
3750
assertEquals(right, "Right angle");
51+
52+
const acute = getAngleType(70);
53+
assertEquals(acute, "Acute angle");
54+
55+
const obtuse = getAngleType(140);
56+
assertEquals(obtuse, "Obtuse angle");
57+
58+
const straight = getAngleType(180);
59+
assertEquals(straight, "Straight angle");
60+
61+
const reflex = getAngleType(190);
62+
assertEquals(reflex, "Reflex angle");
63+
64+
const invalid = getAngleType(370);
65+
assertEquals(invalid, "Invalid angle");

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

Lines changed: 9 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 (numerator < denominator) {
16+
return "true";
17+
} else {
18+
return "false";
19+
}
1520
}
1621

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

3237
// Example: 1/2 is a proper fraction
3338
assertEquals(isProperFraction(1, 2), true);
39+
40+
assertEquals(isProperFraction(1, 2), "true");
41+
assertEquals(isProperFraction(2, 2), "false");
42+
assertEquals(isProperFraction(7, 4), "false");

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
rankCard = card.slice(0, 1);
27+
if (rankCard === "A") {
28+
return 11;
29+
} else if (rankCard === "J" || rankCard === "Q" || rankCard === "K") {
30+
return 10;
31+
} else if (+rankCard >= 2 && +rankCard <= 10) {
32+
return +rankCard;
33+
} else {
34+
return rankCard.toThrow();
35+
}
2636
}
2737

2838
// The line below allows us to load the getCardValue function into tests in other files.
@@ -47,6 +57,6 @@ try {
4757

4858
// This line will not be reached if an error is thrown as expected
4959
console.error("Error was not thrown for invalid card");
50-
} catch (e) {}
60+
} catch (e) { }
5161

52-
// What other invalid card cases can you think of?
62+
// What other invalid card cases can you think of? "13♠"

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1414
});
1515

1616
// Case 2: Right angle
17+
test(`should return "Right angle" when (angle === 90)`, () => {
18+
// Test various acute angles, including boundary cases
19+
expect(getAngleType(90)).toEqual("Right angle");
20+
});
1721
// Case 3: Obtuse angles
22+
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
23+
// Test various acute angles, including boundary cases
24+
expect(getAngleType(91)).toEqual("Obtuse angle");
25+
expect(getAngleType(145)).toEqual("Obtuse angle");
26+
expect(getAngleType(179)).toEqual("Obtuse angle");
27+
});
1828
// Case 4: Straight angle
29+
test(`should return "Straight angle" when (angle === 180)`, () => {
30+
// Test various acute angles, including boundary cases
31+
expect(getAngleType(180)).toEqual("Straight angle");
32+
});
1933
// Case 5: Reflex angles
34+
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
35+
// Test various acute angles, including boundary cases
36+
expect(getAngleType(181)).toEqual("Reflex angle");
37+
expect(getAngleType(245)).toEqual("Reflex angle");
38+
expect(getAngleType(359)).toEqual("Reflex angle");
39+
});
2040
// Case 6: Invalid angles
41+
test(`should return "Invalid angle" when (angle > 360)`, () => {
42+
// Test various acute angles, including boundary cases
43+
expect(getAngleType(90)).toEqual("Invalid angle");
44+
});

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11+
12+
13+
// Special case: positives
14+
test(`should return false when denominator is zero`, () => {
15+
expect(isProperFraction(1, 7)).toEqual(false);
16+
});
17+
18+
// Special case: negatives
19+
test(`should return false when denominator is zero`, () => {
20+
expect(isProperFraction(1, -7)).toEqual(false);
21+
});
22+
23+
// Special case: zero
24+
test(`should return false when denominator is zero`, () => {
25+
expect(isProperFraction(10, 0)).toEqual(false);
26+
});

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,34 @@ test(`Should return 11 when given an ace card`, () => {
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14+
15+
test("Should return 2–10 for their respective card values", () => {
16+
const cards = ["2", "3", "4", "5", "6", "7", "8", "9", "10"];
17+
cards.forEach(card => {
18+
expect(getCardValue(card)).toEqual(Number(card));
19+
});
20+
});
21+
1422
// Face Cards (J, Q, K)
23+
test("Should return 2–10 for their respective card values", () => {
24+
const cards = ["J", "Q", "K"];
25+
cards.forEach(card => {
26+
expect(getCardValue(card)).toEqual(10);
27+
});
28+
});
29+
1530
// Invalid Cards
1631

32+
test("Should return invalid for their respective card values", () => {
33+
const cards = ["L", "M", "N"];
34+
cards.forEach(card => {
35+
expect(getCardValue(card)).toEqual(Number("Invalid"));
36+
37+
});
38+
});
39+
40+
41+
1742
// To learn how to test whether a function throws an error as expected in Jest,
1843
// please refer to the Jest documentation:
1944
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)