Skip to content

Commit 62f2bc9

Browse files
committed
corrected the branch to individual folders of sprint-3 implement and rewrite tests
1 parent 3372770 commit 62f2bc9

File tree

6 files changed

+119
-1
lines changed

6 files changed

+119
-1
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,22 @@
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+
if (angle === 90) {
22+
return "Right angle";
23+
}
24+
if (angle > 90 && angle < 180) {
25+
return "Obtuse angle";
26+
}
27+
if (angle === 180) {
28+
return "Straight angle";
29+
}
30+
if (angle > 180 && angle < 360) {
31+
return "Reflex angle";
32+
}
33+
return "Invalid angle";
1934
}
2035

2136
// The line below allows us to load the getAngleType function into tests in other files.
@@ -35,3 +50,21 @@ function assertEquals(actualOutput, targetOutput) {
3550
// Example: Identify Right Angles
3651
const right = getAngleType(90);
3752
assertEquals(right, "Right angle");
53+
54+
const acute = getAngleType(45);
55+
assertEquals(acute, "Acute angle");
56+
57+
const obtuse = getAngleType(135);
58+
assertEquals(obtuse, "Obtuse angle");
59+
60+
const straight = getAngleType(180);
61+
assertEquals(straight, "Straight angle");
62+
63+
const reflex = getAngleType(270);
64+
assertEquals(reflex, "Reflex angle");
65+
66+
const invalid = getAngleType(-45);
67+
assertEquals(invalid, "Invalid angle");
68+
69+
const invalid2 = getAngleType(361);
70+
assertEquals(invalid2, "Invalid angle");

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

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

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

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

3242
// Example: 1/2 is a proper fraction
3343
assertEquals(isProperFraction(1, 2), true);
44+
assertEquals(isProperFraction(2, 1), false);
45+
assertEquals(isProperFraction(0, 1), true);
46+
assertEquals(isProperFraction(-1, 2), false);
47+
assertEquals(isProperFraction(1, -2), false);
48+
assertEquals(isProperFraction(-1, -2), false);
49+
assertEquals(isProperFraction(3, 4), true);
50+
assertEquals(isProperFraction(4, 3), 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,15 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
const rank = card.slice(0, -1);
27+
const suit = card.slice(-1);
28+
if (rank === "A") {
29+
return 11;
30+
}
31+
if (rank === "J" || rank === "Q" || rank === "K") {
32+
return 10;
33+
}
34+
return parseInt(rank);
2635
}
2736

2837
// The line below allows us to load the getCardValue function into tests in other files.
@@ -50,3 +59,12 @@ try {
5059
} catch (e) {}
5160

5261
// What other invalid card cases can you think of?
62+
assertEquals(getCardValue("A"), 11); // Missing suit
63+
try {
64+
getCardValue("11♠"); // Invalid rank
65+
console.error("Error was not thrown for invalid rank");
66+
} catch (e) {}
67+
68+
try { getCardValue("9X"); // Invalid suit
69+
console.error("Error was not thrown for invalid suit");
70+
} catch (e) {}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,34 @@ 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+
expect(getAngleType(90)).toEqual("Right angle");
19+
});
20+
1721
// Case 3: Obtuse angles
22+
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
23+
expect(getAngleType(91)).toEqual("Obtuse angle");
24+
expect(getAngleType(135)).toEqual("Obtuse angle");
25+
expect(getAngleType(179)).toEqual("Obtuse angle");
26+
});
27+
1828
// Case 4: Straight angle
29+
test(`should return "Straight angle" when (angle === 180)`, () => {
30+
expect(getAngleType(180)).toEqual("Straight angle");
31+
});
32+
1933
// Case 5: Reflex angles
34+
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
35+
expect(getAngleType(181)).toEqual("Reflex angle");
36+
expect(getAngleType(270)).toEqual("Reflex angle");
37+
expect(getAngleType(359)).toEqual("Reflex angle");
38+
});
39+
2040
// Case 6: Invalid angles
41+
test(`should return "Invalid angle" when (angle < 0)`, () => {
42+
expect(getAngleType(-1)).toEqual("Invalid angle");
43+
});
44+
45+
test(`should return "Invalid angle" when (angle > 360)`, () => {
46+
expect(getAngleType(361)).toEqual("Invalid angle");
47+
});

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ 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+
test(`should return true when numerator is zero and denominator is positive`, () => {
13+
expect(isProperFraction(0, 1)).toEqual(true);
14+
});
15+
16+
test(`should return false when numerator is zero and denominator is negative`, () => {
17+
expect(isProperFraction(0, -1)).toEqual(false);
18+
});

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,23 @@ 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+
test(`Should return the numeric value for number cards`, () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("10♠")).toEqual(10);
17+
});
1418
// Face Cards (J, Q, K)
19+
test(`Should return 10 for face cards`, () => {
20+
expect(getCardValue("J♠")).toEqual(10);
21+
expect(getCardValue("Q♠")).toEqual(10);
22+
expect(getCardValue("K♠")).toEqual(10);
23+
});
1524
// Invalid Cards
25+
test(`Should throw an error for invalid cards`, () => {
26+
expect(() => getCardValue("invalid")).toThrow();
27+
expect(() => getCardValue("A")).toThrow(); // Missing suit
28+
expect(() => getCardValue("11♠")).toThrow(); // Invalid rank
29+
expect(() => getCardValue("9X")).toThrow(); // Invalid suit
30+
});
1631

1732
// To learn how to test whether a function throws an error as expected in Jest,
1833
// please refer to the Jest documentation:

0 commit comments

Comments
 (0)