Skip to content

Commit 49b88ad

Browse files
rewrote test with jest
1 parent 9eed6df commit 49b88ad

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,36 @@ 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+
// Test various obtuse angles, including boundary cases
24+
expect(getAngleType(91)).toEqual("Obtuse angle");
25+
expect(getAngleType(120)).toEqual("Obtuse angle");
26+
expect(getAngleType(179)).toEqual("Obtuse angle");
27+
});
28+
1829
// Case 4: Straight angle
30+
test(`should return "Straight angle" when (angle === 180)`, () => {
31+
expect(getAngleType(180)).toEqual("Straight angle");
32+
});
33+
1934
// Case 5: Reflex angles
35+
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
36+
// Test various reflex angles, including boundary cases
37+
expect(getAngleType(181)).toEqual("Reflex angle");
38+
expect(getAngleType(270)).toEqual("Reflex angle");
39+
expect(getAngleType(359)).toEqual("Reflex angle");
40+
});
41+
2042
// Case 6: Invalid angles
43+
test(`should throw an error when (angle < 0 or angle >= 360)`, () => {
44+
expect(() => getAngleType(-1)).toThrow("Invalid angle");
45+
expect(() => getAngleType(360)).toThrow("Invalid angle");
46+
});
47+
test(`should throw an error when (angle === 0)`, () => {
48+
expect(() => getAngleType(0)).toThrow("Invalid angle");
49+
});

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,28 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
77
// Special case: numerator is zero
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
10+
expect(isProperFraction(-5, 0)).toEqual(false);
1011
});
12+
13+
test(`should return true for positive proper fractions`, () => {
14+
expect(isProperFraction(1, 2)).toEqual(true);
15+
expect(isProperFraction(2, 5)).toEqual(true);
16+
});
17+
18+
test(`should return false for positive improper fractions or equal values`, () => {
19+
expect(isProperFraction(3, 2)).toEqual(false);
20+
expect(isProperFraction(5, 5)).toEqual(false);
21+
});
22+
23+
test(`should return true when numerator is zero`, () => {
24+
expect(isProperFraction(0, 5)).toEqual(true);
25+
expect(isProperFraction(0, -5)).toEqual(true);
26+
});
27+
28+
test(`should evaluate correctly with various negative number combinations`, () => {
29+
expect(isProperFraction(-1, 2)).toEqual(true);
30+
expect(isProperFraction(1, -2)).toEqual(true);
31+
expect(isProperFraction(-1, -2)).toEqual(true);
32+
expect(isProperFraction(-5, 2)).toEqual(false);
33+
expect(isProperFraction(5, -2)).toEqual(false);
34+
});

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,27 @@ 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 correct value for number cards (2-10)`), () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("5♠")).toEqual(5);
17+
expect(getCardValue("10♠")).toEqual(10);
18+
}
1419
// Face Cards (J, Q, K)
15-
// Invalid Cards
20+
test(`Should return 10 when given a face card (J, Q, K)`), () => {
21+
expect(getCardValue("J♠")).toEqual(10);
22+
expect(getCardValue("Q♠")).toEqual(10);
23+
expect(getCardValue("K♠")).toEqual(10);
24+
}
25+
// Invalid Card suits
26+
test(`Should throw an error when given an invalid card suit`), () => {
27+
expect(() => getCardValue("3-")).toThrow("Invalid card rank");
28+
expect(() => getCardValue("5X")).toThrow("Invalid card suit");
29+
30+
// Invalid Card ranks
31+
test(`Should throw an error when given an invalid card rank`), () => {
32+
expect(() => getCardValue("1♠")).toThrow("Invalid card rank");
33+
expect(() => getCardValue("11♠")).toThrow("Invalid card rank");
34+
}
1635

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

0 commit comments

Comments
 (0)