Skip to content

Commit 474cd2e

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
Added jest tests to rewrite-tests-with-jest for 1, 2 and 3
1 parent a7c6832 commit 474cd2e

3 files changed

Lines changed: 136 additions & 8 deletions

File tree

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,43 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1010
// Test various acute angles, including boundary cases
1111
expect(getAngleType(1)).toEqual("Acute angle");
1212
expect(getAngleType(45)).toEqual("Acute angle");
13-
expect(getAngleType(89)).toEqual("Acute angle");
13+
expect(getAngleType(89.99)).toEqual("Acute angle");
1414
});
1515

1616
// Case 2: Right angle
17+
test(`should return "Right angle" when angle == 90)`, () => {
18+
// Test right angle
19+
expect(getAngleType(90)).toEqual("Right angle");
20+
});
21+
1722
// Case 3: Obtuse angles
23+
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
24+
// Test various obtuse angles, including boundary cases
25+
expect(getAngleType(90.01)).toEqual("Obtuse angle");
26+
expect(getAngleType(135)).toEqual("Obtuse angle");
27+
expect(getAngleType(179)).toEqual("Obtuse angle");
28+
});
29+
1830
// Case 4: Straight angle
31+
test(`should return "Straight angle" when angle == 180)`, () => {
32+
// Test straight angle
33+
expect(getAngleType(180)).toEqual("Straight angle");
34+
});
35+
1936
// Case 5: Reflex angles
37+
test(`should return "Reflex Angle" when (180 < angle < 360)`, () => {
38+
// Test various reflex angles, including boundary cases
39+
expect(getAngleType(181)).toEqual("Reflex angle");
40+
expect(getAngleType(270)).toEqual("Reflex angle");
41+
expect(getAngleType(359.99)).toEqual("Reflex angle");
42+
});
43+
2044
// Case 6: Invalid angles
45+
test(`should return "Invalid Angle" when invalid`, () => {
46+
// Test various invalid angles
47+
expect(getAngleType(-1)).toEqual("Invalid angle");
48+
expect(getAngleType(0)).toEqual("Invalid angle");
49+
expect(getAngleType(360)).toEqual("Invalid angle");
50+
expect(getAngleType(10000)).toEqual("Invalid angle");
51+
expect(getAngleType("Im not an angle")).toEqual("Invalid angle");
52+
});

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

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,53 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
44

55
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
66

7-
// Special case: numerator is zero
8-
test(`should return false when denominator is zero`, () => {
7+
test('should return true when the numerator is less than the denominator (1 and 2)', () => {
8+
expect(isProperFraction(1, 2)).toEqual(true);
9+
});
10+
11+
test('should return true when the numerator is less than the denominator using decimals (0.1 and 2)', () => {
12+
expect(isProperFraction(0.1, 2)).toEqual(true);
13+
});
14+
15+
test('should return true when the numerator is less than the denominator and numerator is negative (-1 and 2)', () => {
16+
expect(isProperFraction(-1, 2)).toEqual(true);
17+
});
18+
19+
test('should return true when the numerator is less than the denominator and denominator is negative (1 and -2)', () => {
20+
expect(isProperFraction(1, -2)).toEqual(true);
21+
});
22+
23+
test('should return true for large numbers when numerator is less than denominator (1,000,000 and 2,000,000)', () => {
24+
expect(isProperFraction(1000000, 2000000)).toEqual(true);
25+
});
26+
27+
28+
test('should return false when the numerator is greater than the denominator (2 and 1)', () => {
29+
expect(isProperFraction(2, 1)).toEqual(false);
30+
});
31+
32+
test('should return false when the numerator is larger than the denominator with decimals (2 and 0.1)', () => {
33+
expect(isProperFraction(2, 0.1)).toEqual(false);
34+
});
35+
36+
test('should return false when the numerator is larger than the denominator (2 and -1)', () => {
37+
expect(isProperFraction(2, -1)).toEqual(false);
38+
});
39+
40+
test('should return false when the numerator is larger than the denominator (-2 and 1)', () => {
41+
expect(isProperFraction(-2, 1)).toEqual(false);
42+
});
43+
44+
test('should return false for large numbers when the numerator is larger than the denominator (2,000,000 and 1,000,000)', () => {
45+
expect(isProperFraction(2000000, 1000000)).toEqual(false);
46+
});
47+
48+
// Special case: denominator is zero
49+
test('should return false when denominator is zero', () => {
950
expect(isProperFraction(1, 0)).toEqual(false);
1051
});
52+
53+
// Special case: numerator is string
54+
test('should return false when denominator is zero', () => {
55+
expect(isProperFraction("hello", 0)).toEqual(false);
56+
});

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

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

12-
// Suggestion: Group the remaining test data into these categories:
13-
// Number Cards (2-10)
14-
// Face Cards (J, Q, K)
12+
// Number Cards (2-10)
13+
test(`Should return 2 when given a "2♠" card`, () => {
14+
expect(getCardValue("2♠")).toEqual(2);
15+
});
16+
17+
test(`Should return 9 when given a "9♠" card`, () => {
18+
expect(getCardValue("9♠")).toEqual(9);
19+
});
20+
21+
test(`Should return 10 when given a "10♥" card`, () => {
22+
expect(getCardValue("10♥")).toEqual(10);
23+
});
24+
25+
// Face Cards (J, Q, K)
26+
test(`Should return 10 when given a Jack "J♥" card`, () => {
27+
expect(getCardValue("J♥")).toEqual(10);
28+
});
29+
30+
test(`Should return 10 when given a Queen "Q♦" card`, () => {
31+
expect(getCardValue("Q♦")).toEqual(10);
32+
});
33+
34+
test(`Should return 10 when given a King "K♦" card`, () => {
35+
expect(getCardValue("K♦")).toEqual(10);
36+
});
37+
1538
// Invalid Cards
39+
test(`Should return error when given a string`, () => {
40+
expect(() => { getCardValue("invalid");}).toThrow("Invalid card");
41+
});
42+
43+
test(`Should return error when given a wrong letter`, () => {
44+
expect(() => { getCardValue("L♦");}).toThrow("Invalid card");
45+
});
46+
47+
test(`Should return error when given a wrong letter`, () => {
48+
expect(() => { getCardValue("L♦");}).toThrow("Invalid card");
49+
});
50+
51+
test(`Should return error when given a wrong number`, () => {
52+
expect(() => { getCardValue("11♦");}).toThrow("Invalid card");
53+
});
54+
55+
test(`Should return error when given a wrong order`, () => {
56+
expect(() => { getCardValue("♦2");}).toThrow("Invalid card");
57+
});
58+
59+
test(`Should return error when given no suit`, () => {
60+
expect(() => { getCardValue("3");}).toThrow("Invalid card");
61+
});
62+
63+
test(`Should return error when given only suit`, () => {
64+
expect(() => { getCardValue("♦");}).toThrow("Invalid card");
65+
});
66+
1667

1768
// To learn how to test whether a function throws an error as expected in Jest,
1869
// please refer to the Jest documentation:
19-
// https://jestjs.io/docs/expect#tothrowerror
20-
70+
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)