Skip to content

Commit 8228a9f

Browse files
committed
Jest files implemented
1 parent 02bb64f commit 8228a9f

File tree

3 files changed

+79
-17
lines changed

3 files changed

+79
-17
lines changed

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 = 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(135)).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 return "Invalid angle" when angle < 0 or angle >= 360`, () => {
44+
expect(getAngleType(-1)).toEqual("Invalid angle");
45+
expect(getAngleType(360)).toEqual("Invalid angle");
46+
});
Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1-
// This statement loads the isProperFraction function you wrote in the implement directory.
2-
// We will use the same function, but write tests for it using Jest in this file.
31
const isProperFraction = require("../implement/2-is-proper-fraction");
42

5-
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
6-
7-
// Special case: numerator is zero
3+
// Special case: denominator is zero
84
test(`should return false when denominator is zero`, () => {
95
expect(isProperFraction(1, 0)).toEqual(false);
106
});
7+
8+
// Proper fractions with positive numbers
9+
test(`should return true when the numerator is smaller than the denominator`, () => {
10+
expect(isProperFraction(1, 2)).toEqual(true);
11+
expect(isProperFraction(3, 4)).toEqual(true);
12+
});
13+
14+
// Improper fractions with positive numbers
15+
test(`should return false when the numerator is equal to or greater than the denominator`, () => {
16+
expect(isProperFraction(2, 2)).toEqual(false);
17+
expect(isProperFraction(5, 4)).toEqual(false);
18+
});
19+
20+
// Proper fractions with negative values
21+
test(`should return true when the absolute value of the numerator is smaller than the absolute value of the denominator`, () => {
22+
expect(isProperFraction(-1, 2)).toEqual(true);
23+
expect(isProperFraction(1, -2)).toEqual(true);
24+
});
25+
26+
// Improper fractions with negative values
27+
test(`should return false when the absolute value of the numerator is equal to or greater than the absolute value of the denominator`, () => {
28+
expect(isProperFraction(-3, 2)).toEqual(false);
29+
expect(isProperFraction(3, -2)).toEqual(false);
30+
expect(isProperFraction(-2, -2)).toEqual(false);
31+
});
32+
33+
// Special case: numerator is zero
34+
test(`should return true when numerator is zero and denominator is not zero`, () => {
35+
expect(isProperFraction(0, 5)).toEqual(true);
36+
expect(isProperFraction(0, -5)).toEqual(true);
37+
});
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
// This statement loads the getCardValue function you wrote in the implement directory.
2-
// We will use the same function, but write tests for it using Jest in this file.
31
const getCardValue = require("../implement/3-get-card-value");
42

5-
// TODO: Write tests in Jest syntax to cover all possible outcomes.
6-
73
// Case 1: Ace (A)
8-
test(`Should return 11 when given an ace card`, () => {
4+
test(`should return 11 when given an ace card`, () => {
95
expect(getCardValue("A♠")).toEqual(11);
6+
expect(getCardValue("A♥")).toEqual(11);
107
});
118

12-
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
15-
// Invalid Cards
9+
// Case 2: Number cards
10+
test(`should return the numeric value for number cards`, () => {
11+
expect(getCardValue("2♥")).toEqual(2);
12+
expect(getCardValue("7♣")).toEqual(7);
13+
expect(getCardValue("10♦")).toEqual(10);
14+
});
1615

17-
// To learn how to test whether a function throws an error as expected in Jest,
18-
// please refer to the Jest documentation:
19-
// https://jestjs.io/docs/expect#tothrowerror
16+
// Case 3: Face cards
17+
test(`should return 10 for face cards`, () => {
18+
expect(getCardValue("J♣")).toEqual(10);
19+
expect(getCardValue("Q♦")).toEqual(10);
20+
expect(getCardValue("K♥")).toEqual(10);
21+
});
2022

23+
// Case 4: Invalid cards
24+
test(`should throw an error for invalid cards`, () => {
25+
expect(() => getCardValue("invalid")).toThrow();
26+
expect(() => getCardValue("1♠")).toThrow();
27+
expect(() => getCardValue("A")).toThrow();
28+
expect(() => getCardValue("A★")).toThrow();
29+
});

0 commit comments

Comments
 (0)