Skip to content

Commit de6c0ad

Browse files
committed
rewrite-tests-with-jest is done.
1 parent 4b85e00 commit de6c0ad

4 files changed

Lines changed: 92 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15-
return numerator < denominator;
15+
if (denominator === 0) {
16+
return false;
17+
}
18+
19+
return Math.abs(numerator) < Math.abs(denominator);
1620
}
1721

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

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

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

1616
// Case 2: Right angle
17+
test(`should return "Right angle" when angle is 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(120)).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 is 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" for invalid angles`, () => {
42+
expect(getAngleType(0)).toEqual("Invalid angle");
43+
expect(getAngleType(-10)).toEqual("Invalid angle");
44+
expect(getAngleType(360)).toEqual("Invalid angle");
45+
expect(getAngleType(400)).toEqual("Invalid angle");
46+
});

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,43 @@ 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+
// Positive proper fraction
13+
test("should return true for a proper positive fraction", () => {
14+
expect(isProperFraction(1, 2)).toEqual(true);
15+
});
16+
17+
// Positive improper fraction
18+
test("should return false for an improper positive fraction", () => {
19+
expect(isProperFraction(5, 2)).toEqual(false);
20+
});
21+
22+
// Equal numerator and denominator
23+
test("should return false when numerator equals denominator", () => {
24+
expect(isProperFraction(4, 4)).toEqual(false);
25+
});
26+
27+
// Zero numerator
28+
test("should return true when numerator is zero", () => {
29+
expect(isProperFraction(0, 5)).toEqual(true);
30+
});
31+
32+
// Zero denominator
33+
test("should return false when denominator is zero", () => {
34+
expect(isProperFraction(1, 0)).toEqual(false);
35+
});
36+
37+
// Both numerator and denominator are negative
38+
test("should return true for a proper fraction with both values negative", () => {
39+
expect(isProperFraction(-1, -2)).toEqual(true);
40+
});
41+
42+
// Negative numerator, positive denominator
43+
test("should return true when numerator is negative and denominator is positive", () => {
44+
expect(isProperFraction(-1, 2)).toEqual(true);
45+
});
46+
47+
// Positive numerator, negative denominator
48+
test("should return false when numerator is positive and denominator is negative", () => {
49+
expect(isProperFraction(1, -2)).toEqual(false);
50+
});

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
1111

12+
// Case 2: Number cards (2–10)
13+
test("should return the correct value for number cards", () => {
14+
expect(getCardValue("2♥")).toEqual(2);
15+
expect(getCardValue("5♦")).toEqual(5);
16+
expect(getCardValue("10♣")).toEqual(10);
17+
});
18+
19+
// Case 3: Face cards (J, Q, K)
20+
test("should return 10 for face cards", () => {
21+
expect(getCardValue("J♠")).toEqual(10);
22+
expect(getCardValue("Q♥")).toEqual(10);
23+
expect(getCardValue("K♦")).toEqual(10);
24+
});
25+
26+
// Case 4: Invalid cards
27+
test("should throw an error for invalid cards", () => {
28+
expect(() => getCardValue("1♠")).toThrow();
29+
expect(() => getCardValue("11♣")).toThrow();
30+
expect(() => getCardValue("Z♥")).toThrow();
31+
expect(() => getCardValue("invalid")).toThrow();
32+
});
1233
// Suggestion: Group the remaining test data into these categories:
1334
// Number Cards (2-10)
1435
// Face Cards (J, Q, K)
@@ -17,4 +38,3 @@ test(`Should return 11 when given an ace card`, () => {
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-

0 commit comments

Comments
 (0)