Skip to content

Commit f092667

Browse files
committed
completed jest testing on card game and proper fractions
1 parent 8270fd6 commit f092667

3 files changed

Lines changed: 58 additions & 30 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function assertEquals(actualOutput, targetOutput) {
3030
);
3131
}
3232

33-
// TODO: Write tests to cover all cases.
3433
// What combinations of numerators and denominators should you test?
3534

3635
// Example: 1/2 is a proper fraction

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33
const isProperFraction = require("../implement/2-is-proper-fraction");
44

55

6-
// Special case: numerator is zero
7-
test(`should return false when denominator is zero`, () => {
8-
expect(isProperFraction(1,2 )).toEqual(true);
9-
expect(isProperFraction(2,1)).toEqual(false);
10-
expect(isProperFraction(5,5)).toEqual(false);
11-
expect(isProperFraction(0,5)).toEqual(true);
12-
expect(isProperFraction(5,0)).toEqual(false);
13-
expect(isProperFraction(0,0)).toEqual(false);
14-
expect(isProperFraction(-1,2)).toEqual(true);
15-
expect(isProperFraction(1,-2)).toEqual(false);
16-
expect(isProperFraction(-2,-1)).toEqual(true);
17-
expect(isProperFraction(-1,-2)).toEqual(false);
18-
expect(isProperFraction(0.5,1)).toEqual(true);
19-
expect(isProperFraction(1.5,1)).toEqual(false);
20-
expect(isProperFraction(Infinity,2)).toEqual(false);
21-
expect(isProperFraction(2,Infinity)).toEqual(false);
22-
expect(isProperFraction(NaN,2)).toEqual(false)
23-
expect(isProperFraction(2,NaN)).toEqual(false);
24-
expect(isProperFraction(999999999, 1000000000)).toEqual(true)
25-
26-
27-
28-
29-
30-
31-
32-
6+
test("should correctly identify proper fractions", () => {
7+
// Whole number fractions
8+
expect(isProperFraction(1, 2)).toEqual(true);
9+
expect(isProperFraction(2, 1)).toEqual(false);
10+
expect(isProperFraction(5, 5)).toEqual(false);
11+
12+
// Zero
13+
expect(isProperFraction(0, 5)).toEqual(true);
14+
expect(isProperFraction(5, 0)).toEqual(false);
15+
expect(isProperFraction(0, 0)).toEqual(false);
16+
17+
// Negative numbers
18+
expect(isProperFraction(-1, 2)).toEqual(true);
19+
expect(isProperFraction(1, -2)).toEqual(false);
20+
expect(isProperFraction(-2, -1)).toEqual(true);
21+
expect(isProperFraction(-1, -2)).toEqual(false);
22+
23+
// Decimal numbers
24+
expect(isProperFraction(0.5, 1)).toEqual(true);
25+
expect(isProperFraction(1.5, 1)).toEqual(false);
26+
27+
// Infinity
28+
expect(isProperFraction(Infinity, 2)).toEqual(false);
29+
expect(isProperFraction(2, Infinity)).toEqual(false);
30+
31+
// NaN
32+
expect(isProperFraction(NaN, 2)).toEqual(false);
33+
expect(isProperFraction(2, NaN)).toEqual(false);
34+
35+
// Large numbers
36+
expect(isProperFraction(999999999, 1000000000)).toEqual(true);
3337
});

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,42 @@
22
// We will use the same function, but write tests for it using Jest in this file.
33
const getCardValue = require("../implement/3-get-card-value");
44

5-
// TODO: Write tests in Jest syntax to cover all possible outcomes.
65

76
// Case 1: Ace (A)
87
test(`Should return 11 when given an ace card`, () => {
98
expect(getCardValue("A♠")).toEqual(11);
109
});
1110

12-
// Suggestion: Group the remaining test data into these categories:
11+
// Suggestion: Group the remaining test data into these categories: // ♠ ♥ ♦ ♣
1312
// Number Cards (2-10)
13+
test(`Should return the card's numeric rank for cards 2 through 10`, () =>{
14+
expect(getCardValue("2♠")).toEqual(2);
15+
expect(getCardValue("3♥")).toEqual(3);
16+
expect(getCardValue("4♦")).toEqual(4);
17+
expect(getCardValue("5♣")).toEqual(5);
18+
expect(getCardValue("6♠")).toEqual(6);
19+
expect(getCardValue("7♥")).toEqual(7);
20+
expect(getCardValue("8♦")).toEqual(8);
21+
expect(getCardValue("9♣")).toEqual(9);
22+
expect(getCardValue("10♠")).toEqual(10);
23+
24+
})
1425
// Face Cards (J, Q, K)
26+
test(`should return 10 When the card is a face card ("J", "Q", "K")`, () => {
27+
expect(getCardValue("j♠")).toEqual(10);
28+
expect(getCardValue("k♦")).toEqual(10);
29+
expect(getCardValue("q♣")).toEqual(10);
30+
31+
})
1532
// Invalid Cards
33+
test("should throw an error when an invalid card is played", () => {
34+
expect(() => getCardValue("")).toThrow("No card was played");
35+
expect(() => getCardValue("1009♣")).toThrow("Invalid card played, rank and suit cannot be less " +
36+
"than 1 or more than 3")
37+
38+
});
39+
40+
1641

1742
// To learn how to test whether a function throws an error as expected in Jest,
1843
// please refer to the Jest documentation:

0 commit comments

Comments
 (0)