Skip to content

Commit 97ae1f5

Browse files
Complete Jest tests
1 parent 48b1a54 commit 97ae1f5

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@ import { getAngleType } from "../implement/1-get-angle-type.js";
33
// TODO: Write tests in Jest syntax to cover all cases/outcomes,
44
// including boundary and invalid cases.
55

6+
test("90 degrees is a right angle", () => {
7+
expect(getAngleType(90)).toEqual("Right angle");
8+
});
9+
10+
test("obtuse angle", () => {
11+
expect(getAngleType(120)).toEqual("Obtuse angle");
12+
});
13+
14+
test("180 degrees is a straight angle", () => {
15+
expect(getAngleType(180)).toEqual("Straight angle");
16+
});
17+
18+
test("Reflex angle", () => {
19+
expect(getAngleType(270)).toEqual("Reflex angle");
20+
});
21+
22+
test("Invalid angle", () => {
23+
expect(getAngleType(0)).toEqual("Invalid angle");
24+
expect(getAngleType(360)).toEqual("Invalid angle");
25+
expect(getAngleType(-10)).toEqual("Invalid angle");
26+
});
27+
628
// Case 1: Acute angles
729
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
830
// Test various acute angles, including boundary cases
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import { isProperFraction } from "../implement/2-is-proper-fraction.js";
22

33
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
4+
test(`should return true for proper fractions`, () => {
5+
expect(isProperFraction(1, 2)).toEqual(true);
6+
expect(isProperFraction(2, 5)).toEqual(true);
7+
});
8+
9+
test(`should return false when numerator is not smaller`, () => {
10+
expect(isProperFraction(5, 5)).toEqual(false);
11+
expect(isProperFraction(7, 5)).toEqual(false);
12+
});
413

514
// Special case: numerator is zero
615
test(`should return false when denominator is zero`, () => {
716
expect(isProperFraction(1, 0)).toEqual(false);
817
});
18+
19+
test(`should return true when numerator is zero`, () => {
20+
expect(isProperFraction(0, 5)).toEqual(true);
21+
});

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import { getCardValue } from "../implement/3-get-card-value.js";
22

3-
// TODO: Write tests in Jest syntax to cover all possible outcomes.
3+
test("Should return 2 for a number card", () => {
4+
expect(getCardValue("2♥")).toEqual(2);
5+
});
6+
7+
test("Number card (2-10)", () => {
8+
expect(getCardValue("7♦")).toEqual(7);
9+
expect(getCardValue("4♣")).toEqual(4);
10+
});
11+
12+
test("Face Cards (J, Q, K)", () => {
13+
expect(getCardValue("J♣")).toEqual(10);
14+
expect(getCardValue("Q♦")).toEqual(10);
15+
expect(getCardValue("K♥")).toEqual(10);
16+
});
417

518
// Case 1: Ace (A)
619
test(`Should return 11 when given an ace card`, () => {
720
expect(getCardValue("A♠")).toEqual(11);
821
});
922

23+
test("Invalid cards throw an error", () => {
24+
expect(() => getCardValue("2x")).toThrow();
25+
expect(() => getCardValue(invalid)).toThrow();
26+
});
27+
1028
// Suggestion: Group the remaining test data into these categories:
1129
// Number Cards (2-10)
1230
// Face Cards (J, Q, K)
@@ -15,4 +33,3 @@ test(`Should return 11 when given an ace card`, () => {
1533
// To learn how to test whether a function throws an error as expected in Jest,
1634
// please refer to the Jest documentation:
1735
// https://jestjs.io/docs/expect#tothrowerror
18-

0 commit comments

Comments
 (0)