Skip to content

Commit d0fa6f8

Browse files
rewrite tests with jest
1 parent a8b6057 commit d0fa6f8

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ assertEquals(isProperFraction(1, 2), true);
3535
assertEquals(isProperFraction(93, 112), true);
3636
assertEquals(isProperFraction(2, 1), false);
3737
assertEquals(isProperFraction(80, 80), false);
38+
assertEquals(isProperFraction(-10, -15), true);
39+
assertEquals(isProperFraction(-35, 25), false);
40+
assertEquals(isProperFraction(1, 0), false);
41+
assertEquals(isProperFraction(0, 1), true);
3842
console.log("Execution finished! If any test failed, console.assert errors will appear above.");

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,21 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11+
// proper fractions
12+
test(`should return true when denominator is higher than numerator`, () => {
13+
expect(isProperFraction(0, 1)).toEqual(true);
14+
expect(isProperFraction(2, 7)).toEqual(true);
15+
expect(isProperFraction(89, 101)).toEqual(true);
16+
});
17+
// Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs
18+
test(`should return true when negative/positive numerator is less than the positive/negative denominator`, () => {
19+
expect(isProperFraction(-20, -30)).toEqual(true);
20+
expect(isProperFraction(-1, 2)).toEqual(true);
21+
expect(isProperFraction(58, -68)).toEqual(true);
22+
});
23+
// Special case: numerator or denominator is negative, we consider the absolute values for fractions so ignore the negative signs
24+
test(`should return false when negative/positive numerator is greater than the positive/negative denominator`, () => {
25+
expect(isProperFraction(-50, 10)).toEqual(false);
26+
expect(isProperFraction(100, -2)).toEqual(false);
27+
expect(isProperFraction(-1, -0)).toEqual(false);
28+
});

Sprint-3/1-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
@@ -3,12 +3,29 @@
33
const getCardValue = require("../implement/3-get-card-value");
44

55
// TODO: Write tests in Jest syntax to cover all possible outcomes.
6-
6+
//["♠", "♥", "♦", "♣"];
77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
11-
11+
//Case 2: Face Cards(J, Q,K)
12+
test(`Should return 10 when given a face card`, () => {
13+
expect(getCardValue("J♠")).toEqual(10);
14+
expect(getCardValue("K♣")).toEqual(10);
15+
expect(getCardValue("J♦")).toEqual(10);
16+
});
17+
//case 3: Number Cards (2-10)
18+
test(`Should return the number when given a number card`, () => {
19+
expect(getCardValue("4♠")).toEqual(4);
20+
expect(getCardValue("9♣")).toEqual(9);
21+
expect(getCardValue("2♦")).toEqual(2);
22+
});
23+
//Case 4: Invalid cards
24+
test(`Should return the invalid suit or invalid rank when given an invalid card`, () => {
25+
expect(getCardValue("4🎉")).toEqual("Invalid suit");
26+
expect(getCardValue("20♣")).toEqual("Invalid rank");
27+
expect(getCardValue("Apple")).toEqual("Invalid card");
28+
});
1229
// Suggestion: Group the remaining test data into these categories:
1330
// Number Cards (2-10)
1431
// Face Cards (J, Q, K)

0 commit comments

Comments
 (0)