Skip to content

Commit 20e062b

Browse files
committed
Aded jest test for getCardValue function
1 parent 36150a8 commit 20e062b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test(`should return true when numerator is zero`, () => {
1616

1717
// Special case: positive numerator and denominator
1818
test(`should return true when numerator is less than denominator`, () => {
19-
expect(isProperFraction(7, 9)).toEqual(true);
19+
expect(isProperFraction(5, 9)).toEqual(true);
2020
});
2121

2222
// Special case; negative numerator and positive denominatore
@@ -26,15 +26,15 @@ test(` should return true when numertaor is negative and less than demoniator`,
2626

2727
// special case: postive numerator and negative deminator
2828
test(`should return true when numerator is positive and less than denominator`, () => {
29-
expect(isProperFraction(5, -7)).toEqual(true);
29+
expect(isProperFraction(5, -9)).toEqual(true);
3030
});
3131

3232
// Special case: negative numerator and negative denominator
3333
test(`should return true when both are negative`, () => {
34-
expect(isProperFraction(-5, -7)).toEqual(true);
34+
expect(isProperFraction(-5, -9)).toEqual(true);
3535
});
3636

3737
// Special case: Equal values
3838
test(`should return false when numerator and denominator are equal`, () => {
39-
expect(isProperFraction(5, 5)).toEqual(false);
39+
expect(isProperFraction(4, 4)).toEqual(false);
4040
});

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,36 @@ const getCardValue = require("../implement/3-get-card-value");
55
// TODO: Write tests in Jest syntax to cover all possible outcomes.
66

77
// Case 1: Ace (A)
8-
test(`Should return 11 when given an ace card`, () => {
8+
test(`should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14+
test(`should return the correct value for number cards`, () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("10♣")).toEqual(10);
17+
expect(getCardValue("6♥")).toEqual(6);
18+
expect(getCardValue("9♦")).toEqual(9);
19+
expect(getCardValue("3♠")).toEqual(3);
20+
});
1421
// Face Cards (J, Q, K)
22+
test(`should return the correct value for face cards`, () => {
23+
expect(getCardValue("J♠")).toEqual(10);
24+
expect(getCardValue("Q♠")).toEqual(10);
25+
expect(getCardValue("K♠")).toEqual(10);
26+
});
1527
// Invalid Cards
28+
test("should throw error for invalid cards", () => {
29+
expect(() => getCardValue("1♠")).toThrow();
30+
expect(() => getCardValue("11♠")).toThrow();
31+
expect(() => getCardValue("Z♠")).toThrow();
32+
expect(() => getCardValue("A")).toThrow();
33+
expect(() => getCardValue("♠")).toThrow();
34+
expect(() => getCardValue("")).toThrow();
35+
expect(() => getCardValue(null)).toThrow();
36+
});
1637

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

0 commit comments

Comments
 (0)