Skip to content

Commit 789b34f

Browse files
committed
completed implement-and-rewrite-tests
1 parent 3372770 commit 789b34f

File tree

7 files changed

+109
-3
lines changed

7 files changed

+109
-3
lines changed

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

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

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19+
// if angle is between 0 and 90 then return acute angle
20+
if (angle > 0 && angle < 90) {
21+
return "Acute angle";
22+
}
23+
24+
// if it is exactly 90 return right angle
25+
else if (angle === 90) {
26+
return "Right angle";
27+
}
28+
// greater than 90 less than 180 return obtuse angle
29+
else if (angle > 90 && angle < 180) {
30+
return "Obtuse angle";
31+
}
32+
// if exactly 180 return straight angle
33+
else if (angle === 180) {
34+
return "Straight angle";
35+
}
36+
// greater than 180 less than 360 return reflex angle
37+
else if (angle > 180 && angle < 360) {
38+
return "Reflex angle";
39+
}
40+
// everything greater than 360 return invalid angle
41+
else {
42+
return "Invalid angle";
43+
}
44+
// return a string tells user which angle
1945
}
2046

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

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

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

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator === 0) return false;
16+
return Math.abs(numerator) < Math.abs(denominator);
1517
}
1618

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

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26+
27+
// if card is an ace return 11
28+
if (card === "A") {
29+
return 11;
30+
}
31+
32+
// if card is face "J", "Q", "K"
33+
else if (card === "J" || card === "Q" || card === "K") {
34+
return 10;
35+
}
36+
37+
// if card is a number card and card is bigger than 2 and less than 10 ("2" to "10"), should return its numerical value
38+
else if (Number(card) >= 2 && Number(card) <= 10) {
39+
return Number(card);
40+
} else {
41+
throw new Error("Error invalid card");
42+
}
2643
}
2744

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

4057
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
4158
// Examples:
42-
assertEquals(getCardValue("9"), 9);
59+
assertEquals(getCardValue("9"), 9);
4360

4461
// Handling invalid cards
4562
try {

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 right angles, including boundary cases
19+
expect(getAngleType(90)).toEqual("Right angle");
20+
});
1721
// Case 3: Obtuse angles
22+
test(`should return "Obtuse angles" when (angle > 90 && < 180)`, () => {
23+
// Test various obtuse angles, including boundary cases
24+
expect(getAngleType(96)).toEqual("Obtuse angle");
25+
expect(getAngleType(142)).toEqual("Obtuse angle");
26+
expect(getAngleType(178)).toEqual("Obtuse angle");
27+
});
1828
// Case 4: Straight angle
29+
test(`should return "Straight angle" when (angle === 180)`, () => {
30+
// Test various straight angles, including boundary cases
31+
expect(getAngleType(180)).toEqual("Straight angle");
32+
});
1933
// Case 5: Reflex angles
34+
test(`should return "Reflex angles" when (angle > 180 && < 360)`, () => {
35+
// Test various reflex angles, including boundary cases
36+
expect(getAngleType(199)).toEqual("Reflex angle");
37+
expect(getAngleType(245)).toEqual("Reflex angle");
38+
expect(getAngleType(306)).toEqual("Reflex angle");
39+
});
2040
// Case 6: Invalid angles
41+
test(`should return "Invalid angles" when (angle > 180 && < 360)`, () => {
42+
// Test various invalid angles, including boundary cases
43+
expect(getAngleType(360)).toEqual("Invalid angle");
44+
});

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,18 @@ 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(`for positive`, () => {
13+
expect(isProperFraction(6, 7)).toEqual(true);
14+
expect(isProperFraction(2, 4)).toEqual(true);
15+
});
16+
17+
test(`should return false for improper fractions`, () => {
18+
expect(isProperFraction(8, 6)).toEqual(false);
19+
expect(isProperFraction(4, 2)).toEqual(false);
20+
});
21+
22+
test(`negative combinations`, () => {
23+
expect(isProperFraction(-5, 9)).toEqual(true);
24+
expect(isProperFraction(-2, 0)).toEqual(false);
25+
});

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,35 @@ const getCardValue = require("../implement/3-get-card-value");
66

77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
9-
expect(getCardValue("A")).toEqual(11);
9+
expect(getCardValue("A")).toEqual(11);
1010
});
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
1414
// Face Cards (J, Q, K)
1515
// Invalid Cards
1616

17+
// Case 2: Face (J, Q, K)
18+
test(`Should return 10 when given an face card`, () => {
19+
expect(getCardValue("J")).toEqual(10);
20+
});
21+
22+
test(`Should return 10 when given an face card`, () => {
23+
expect(getCardValue("Q")).toEqual(10);
24+
});
25+
26+
test(`Should return 10 when given an face card`, () => {
27+
expect(getCardValue("K")).toEqual(10);
28+
});
29+
// Case 3: Number Cards (2-10)
30+
test(`Should return numerical value when given an number card`, () => {
31+
expect(getCardValue("5")).toEqual(5);
32+
});
33+
34+
test(`Should return error if the card string is invalid`, () => {
35+
expect(() => getCardValue("17")).toThrow("Error invalid card");
36+
});
37+
1738
// To learn how to test whether a function throws an error as expected in Jest,
1839
// please refer to the Jest documentation:
1940
// https://jestjs.io/docs/expect#tothrowerror
20-

Sprint-3/2-practice-tdd/count.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ test("should count multiple occurrences of a character", () => {
2222
// And a character `char` that does not exist within `str`.
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of `char` were found.
25+
26+
// test(``);

0 commit comments

Comments
 (0)