Skip to content

Commit abe2eb3

Browse files
committed
Rewrite test messages to describe behaviours instead of exact values
1 parent 9737d08 commit abe2eb3

5 files changed

Lines changed: 72 additions & 101 deletions

File tree

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

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,40 @@ import { getAngleType } from "../implement/1-get-angle-type.js";
66
// TODO: Write tests to cover all cases, including boundary and invalid cases.
77
// Example: Identify Right Angles
88

9+
test("Classifies acute angles", () => {
10+
const acute1 = getAngleType(1);
11+
assert.equal(acute1, "Acute angle");
12+
const acute89 = getAngleType(89);
13+
assert.equal(acute89, "Acute angle");
14+
});
15+
916
test("Classifies right angles", () => {
1017
const right = getAngleType(90);
1118
assert.equal(right, "Right angle");
1219
});
1320

14-
test("Classifies invalid angle 0 degrees", () => {
15-
const invalid = getAngleType(0);
16-
assert.equal(invalid, "Invalid angle");
17-
});
18-
19-
test("Classifies acute angle 1 degrees", () => {
20-
const acute = getAngleType(1);
21-
assert.equal(acute, "Acute angle");
22-
});
23-
24-
test("Classifies acute angle 89 degrees", () => {
25-
const acute = getAngleType(89);
26-
assert.equal(acute, "Acute angle");
21+
test("Classifies obtuse angles", () => {
22+
const obtuse91 = getAngleType(91);
23+
assert.equal(obtuse91, "Obtuse angle");
24+
const obtuse179 = getAngleType(179);
25+
assert.equal(obtuse179, "Obtuse angle");
2726
});
2827

29-
test("Classifies obtuse angle 91 degrees", () => {
30-
const obtuse = getAngleType(91);
31-
assert.equal(obtuse, "Obtuse angle");
32-
});
33-
34-
test("Classifies obtuse angle 179 degrees", () => {
35-
const obtuse = getAngleType(179);
36-
assert.equal(obtuse, "Obtuse angle");
37-
});
38-
39-
test("Classifies straight angle 180 degrees", () => {
28+
test("Classifies straight angles", () => {
4029
const straight = getAngleType(180);
4130
assert.equal(straight, "Straight angle");
4231
});
4332

44-
test("Classifies reflex angle 181 degrees", () => {
45-
const reflex = getAngleType(181);
46-
assert.equal(reflex, "Reflex angle");
47-
});
48-
49-
test("Classifies reflex angle 359 degrees", () => {
50-
const reflex = getAngleType(359);
51-
assert.equal(reflex, "Reflex angle");
33+
test("Classifies reflex angles", () => {
34+
const reflex181 = getAngleType(181);
35+
assert.equal(reflex181, "Reflex angle");
36+
const reflex359 = getAngleType(359);
37+
assert.equal(reflex359, "Reflex angle");
5238
});
5339

54-
test("Classifies invalid angle 360 degrees", () => {
55-
const invalid = getAngleType(360);
56-
assert.equal(invalid, "Invalid angle");
40+
test("Classifies invalid angles", () => {
41+
const invalid360 = getAngleType(360);
42+
assert.equal(invalid360, "Invalid angle");
43+
const invalid0 = getAngleType(0);
44+
assert.equal(invalid0, "Invalid angle");
5745
});

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

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,72 +19,65 @@ test("Arbitrary non-card string", () => {
1919

2020
// TODO: What other invalid card cases can you think of?
2121

22-
test("Arbitrary non-card string '19♠'", () => {
22+
test("Card with number rank outside range 2-10", () => {
2323
assert.throws(
2424
() => getCardValue("19♠"),
2525
/Expected a number followed by a suit, but got "19♠"/,
2626
"Expected clear error"
2727
);
28+
assert.throws(
29+
() => getCardValue("-3♦"),
30+
/Expected a number followed by a suit, but got "-3♦"/,
31+
"Expected clear error"
32+
);
2833
});
2934

30-
test("Arbitrary non-card string 'P♦'", () => {
35+
test("Card with letter rank other than the correct options", () => {
3136
assert.throws(
3237
() => getCardValue("P♦"),
3338
/Expected a number followed by a suit, but got "P♦"/,
3439
"Expected clear error"
3540
);
36-
});
37-
38-
test("Arbitrary non-card string 's♦'", () => {
3941
assert.throws(
4042
() => getCardValue("s♦"),
4143
/Expected a number followed by a suit, but got "s♦"/,
4244
"Expected clear error"
4345
);
44-
});
45-
46-
test("Arbitrary non-card string 'sOup♦'", () => {
4746
assert.throws(
48-
() => getCardValue("soUp♦"),
49-
/Expected a number followed by a suit, but got "soUp♦"/,
47+
() => getCardValue("soUp♣"),
48+
/Expected a number followed by a suit, but got "soUp♣"/,
5049
"Expected clear error"
5150
);
5251
});
5352

54-
test("Arbitrary non-card string '-3♦'", () => {
53+
test("Card with valid number rank lacking suit", () => {
5554
assert.throws(
56-
() => getCardValue("-3♦"),
57-
/Expected a number followed by a suit, but got "-3♦"/,
55+
() => getCardValue("5"),
56+
/Expected a number followed by a suit, but got "5"/,
5857
"Expected clear error"
5958
);
6059
});
6160

62-
test("Arbitrary non-card string '5'", () => {
61+
test("Card with valid letter rank lacking suit", () => {
6362
assert.throws(
64-
() => getCardValue("5"),
65-
/Expected a number followed by a suit, but got "5"/,
63+
() => getCardValue("Q"),
64+
/Expected a number followed by a suit, but got "Q"/,
6665
"Expected clear error"
6766
);
6867
});
6968

70-
test("Arbitrary non-card string 'Q'", () => {
69+
test("Card with valid suit lacking rank", () => {
7170
assert.throws(
72-
() => getCardValue("Q"),
73-
/Expected a number followed by a suit, but got "Q"/,
71+
() => getCardValue("♠"),
72+
/Expected a number followed by a suit, but got "♠"/,
7473
"Expected clear error"
7574
);
7675
});
7776

7877
//Valid cases
7978

80-
test("Valid card 'A♣'", () => {
79+
test("Valid cards", () => {
8180
assert.equal(getCardValue("A♣"), 11);
82-
});
83-
84-
test("Valid card '10♣'", () => {
8581
assert.equal(getCardValue("10♣"), 10);
86-
});
87-
88-
test("Valid card 'K♠'", () => {
8982
assert.equal(getCardValue("K♠"), 10);
9083
});

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getAngleType } from "../implement/1-get-angle-type.js";
55

66
// Case 1: Acute angles
77

8-
test(`should return "Acute angle" when (0 < angle < 90)`, () => {
8+
test(`Classifies acute angles`, () => {
99
// Test various acute angles, including boundary cases
1010
expect(getAngleType(1)).toEqual("Acute angle");
1111
expect(getAngleType(45)).toEqual("Acute angle");
@@ -14,35 +14,35 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1414

1515
// Case 2: Right angle
1616

17-
test(`should return "Right angle" when (angle = 90)`, () => {
17+
test(`Classifies right angles`, () => {
1818
expect(getAngleType(90)).toEqual("Right angle");
1919
});
2020

2121
// Case 3: Obtuse angles
2222

23-
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
23+
test(`Classifies obtuse angles`, () => {
2424
expect(getAngleType(91)).toEqual("Obtuse angle");
2525
expect(getAngleType(135)).toEqual("Obtuse angle");
2626
expect(getAngleType(179)).toEqual("Obtuse angle");
2727
});
2828

2929
// Case 4: Straight angle
3030

31-
test(`should return "Straight angle" when (angle = 180)`, () => {
31+
test(`Classifies straight angles`, () => {
3232
expect(getAngleType(180)).toEqual("Straight angle");
3333
});
3434

3535
// Case 5: Reflex angles
3636

37-
test(`should return "Reflex angle" when (180 < angle < 360)`, () => {
37+
test(`Classifies reflex angles`, () => {
3838
expect(getAngleType(181)).toEqual("Reflex angle");
3939
expect(getAngleType(270)).toEqual("Reflex angle");
4040
expect(getAngleType(359)).toEqual("Reflex angle");
4141
});
4242

4343
// Case 6: Invalid angles
4444

45-
test(`should return "Invalid angle" when (angle =< 0 and angle >= 360)`, () => {
45+
test(`Classifies invalid angles`, () => {
4646
expect(getAngleType(0)).toEqual("Invalid angle");
4747
expect(getAngleType(-1)).toEqual("Invalid angle");
4848
expect(getAngleType(360)).toEqual("Invalid angle");

‎implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,30 @@ import { isProperFraction } from "../implement/2-is-proper-fraction.js";
33
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
44

55
// Special case: numerator is zero
6-
test(`should return false when denominator is zero`, () => {
6+
test(`Edge case: division by zero`, () => {
77
expect(isProperFraction(1, 0)).toEqual(false);
88
});
99

10-
test(`should return true when 1 and 2 is passed`, () => {
10+
test(`Basic proper fraction`, () => {
1111
expect(isProperFraction(1, 2)).toEqual(true);
1212
});
1313

14-
test(`should return false when 4 and 2 is passed`, () => {
14+
test(`Basic improper fraction`, () => {
1515
expect(isProperFraction(4, 2)).toEqual(false);
1616
});
1717

18-
test(`should return false when edge case 2 and 2 is passed`, () => {
18+
test(`Edge case improper fraction`, () => {
1919
expect(isProperFraction(2, 2)).toEqual(false);
2020
});
2121

22-
test(`should return true when -5 and 8 is passed`, () => {
22+
test(`Negative proper fraction`, () => {
2323
expect(isProperFraction(-5, 8)).toEqual(true);
2424
});
2525

26-
test(`should return false when -8 and 5 is passed`, () => {
26+
test(`Negative improper fraction`, () => {
2727
expect(isProperFraction(-8, 5)).toEqual(false);
2828
});
2929

30-
test(`should return true when 0 and 5 is passed`, () => {
30+
test(`Edge case proper fraction`, () => {
3131
expect(isProperFraction(0, 5)).toEqual(true);
32-
});
33-
34-
test(`should return true when 3 and -7 is passed`, () => {
35-
expect(isProperFraction(3, -7)).toEqual(true);
36-
});
32+
});

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,70 +10,64 @@ test(`Should return 11 when given an ace card`, () => {
1010
// Suggestion: Group the remaining test data into these categories:
1111
// Number Cards (2-10)
1212

13-
test(`Should return 10 when given '10♣' `, () => {
13+
test(`Cards with valid number rank`, () => {
1414
expect(getCardValue("10♣")).toEqual(10);
1515
});
1616

1717
// Face Cards (J, Q, K)
1818

19-
test(`Should return 10 when given 'K♠' `, () => {
19+
test(`Cards with valid letter rank`, () => {
2020
expect(getCardValue("K♠")).toEqual(10);
21-
});
22-
23-
test(`Should return 11 when given 'A♣'`, () => {
2421
expect(getCardValue("A♣")).toEqual(11);
2522
});
2623

2724
// Invalid Cards
2825

29-
test(`Should throw error when given 'invalid'`, () => {
26+
test(`Card with invalid string`, () => {
3027
expect(() => {
3128
getCardValue("invalid");
3229
}).toThrow(/Expected a number followed by a suit, but got "invalid"/);
3330
});
3431

35-
test(`Should throw error when given '19♠'`, () => {
32+
test(`Card with number rank outside range 2-10`, () => {
3633
expect(() => {
3734
getCardValue("19♠");
3835
}).toThrow(/Expected a number followed by a suit, but got "19♠"/);
36+
expect(() => {
37+
getCardValue("-3♦");
38+
}).toThrow(/Expected a number followed by a suit, but got "-3♦"/);
3939
});
4040

41-
test(`Should throw error when given 'P♦'`, () => {
41+
test(`Card with letter rank other than the correct options`, () => {
4242
expect(() => {
4343
getCardValue("P♦");
4444
}).toThrow(/Expected a number followed by a suit, but got "P♦"/);
45-
});
46-
47-
test(`Should throw error when given 's♦'`, () => {
4845
expect(() => {
4946
getCardValue("s♦");
5047
}).toThrow(/Expected a number followed by a suit, but got "s♦"/);
51-
});
52-
53-
test(`Should throw error when given 'sOup♦'`, () => {
5448
expect(() => {
5549
getCardValue("sOup♦");
5650
}).toThrow(/Expected a number followed by a suit, but got "sOup♦"/);
5751
});
5852

59-
test(`Should throw error when given '-3♦'`, () => {
60-
expect(() => {
61-
getCardValue("-3♦");
62-
}).toThrow(/Expected a number followed by a suit, but got "-3♦"/);
63-
});
64-
65-
test(`Should throw error when given '5'`, () => {
53+
test(`Card with valid number rank lacking suit`, () => {
6654
expect(() => {
6755
getCardValue("5");
6856
}).toThrow(/Expected a number followed by a suit, but got "5"/);
6957
});
7058

71-
test(`Should throw error when given 'Q'`, () => {
59+
test(`Card with valid letter rank lacking suit`, () => {
7260
expect(() => {
7361
getCardValue("Q");
7462
}).toThrow(/Expected a number followed by a suit, but got "Q"/);
7563
});
7664

65+
test(`Card with valid suit lacking rank`, () => {
66+
expect(() => {
67+
getCardValue("♠");
68+
}).toThrow(/Expected a number followed by a suit, but got "♠"/);
69+
});
70+
7771
// To learn how to test whether a function throws an error as expected in Jest,
7872
// please refer to the Jest documentation:
7973
// https://jestjs.io/docs/expect#tothrowerror

0 commit comments

Comments
 (0)