Skip to content

Commit c822d53

Browse files
committed
sprint 3 implement and rewrite - i modified the implement part of get-card-value add line 37 to 40 and also done with the rewrite tests with jest tasks.
1 parent e3ae6db commit c822d53

5 files changed

Lines changed: 81 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ function getCardValue(card) {
3434

3535
const faceCardValues = {'A': 11, 'J': 10, 'Q': 10, 'K': 10};
3636

37+
if(faceCardValues[value] === undefined && (Number(value) < 2 || Number(value) > 10)) {
38+
throw new Error("Invalid card");
39+
}
40+
3741
if (faceCardValues[value] !== undefined) {
3842
return faceCardValues[value];
3943
}
@@ -59,11 +63,8 @@ function assertEquals(actualOutput, targetOutput) {
5963
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
6064
// Examples:
6165
assertEquals(getCardValue("9♠"), 9);
62-
6366
assertEquals(getCardValue("A♥"),11);
6467
assertEquals(getCardValue("10♠"),10);
65-
66-
6768
assertEquals(getCardValue("2♠"), 2);
6869
assertEquals(getCardValue("K♠"), 10);
6970
assertEquals(getCardValue("q♦"), 10);

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,36 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1414
});
1515

1616
// Case 2: Right angle
17+
test(`should return "Right angle" when (Angle ===90)`, () => {
18+
// Test various acute angles, including boundary cases
19+
expect(getAngleType(90)).toEqual("Right angle");
20+
21+
});
22+
1723
// Case 3: Obtuse angles
24+
test(`should return "Obtuse angle" when ( 90 < angle < 180)`, () => {
25+
// Test various acute angles, including boundary cases
26+
expect(getAngleType(91)).toEqual("Obtuse angle");
27+
expect(getAngleType(125)).toEqual("Obtuse angle");
28+
expect(getAngleType(179)).toEqual("Obtuse angle");
29+
});
30+
1831
// Case 4: Straight angle
32+
test(`should return "Straight angle" when (angle === 180)`, () => {
33+
// Test various acute angles, including boundary cases
34+
expect(getAngleType(180)).toEqual("Straight angle");
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)).toEqual("Reflex angle");
42+
});
2043
// Case 6: Invalid angles
44+
test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => {
45+
// Test various invalid angles
46+
expect(getAngleType(-1)).toEqual("Invalid angle");
47+
expect(getAngleType(361)).toEqual("Invalid angle");
48+
expect(getAngleType(0)).toEqual("Invalid angle");
49+
});

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@
33
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.
6+
test(`should return True when denominator is positive and less than numerator`, () => {
7+
expect(isProperFraction(1, 2)).toEqual(true);
8+
expect(isProperFraction(-1, 2)).toEqual(true );
9+
expect(isProperFraction(20, 21)).toEqual(true );
10+
expect(isProperFraction(60, 90)).toEqual(true );
11+
});
12+
13+
test(`should return false when denominator greater than numerator`, () => {
14+
expect(isProperFraction(10, 1)).toEqual(false);
15+
expect(isProperFraction(11, 1)).toEqual(false);
16+
});
17+
18+
test(`should return false when denominator and numerators are Equal`, () => {
19+
expect(isProperFraction(1, 1)).toEqual(false);
20+
expect(isProperFraction(-1,-1)).toEqual(false);
21+
expect(isProperFraction(-1, 1)).toEqual(false);
22+
});
623

724
// Special case: numerator is zero
825
test(`should return false when denominator is zero`, () => {
926
expect(isProperFraction(1, 0)).toEqual(false);
27+
expect(isProperFraction(-1, 0)).toEqual(false);
28+
expect(isProperFraction(0, 0)).toEqual(false);
1029
});

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,34 @@ test(`Should return 11 when given an ace card`, () => {
1111

1212
// Suggestion: Group the remaining test data into these categories:
1313
// Number Cards (2-10)
14+
test(`Should return 10 when given a number card`, () => {
15+
expect(getCardValue("2♠")).toEqual(2);
16+
expect(getCardValue("3♦")).toEqual(3);
17+
expect(getCardValue("4♣")).toEqual(4);
18+
expect(getCardValue("5♠")).toEqual(5);
19+
expect(getCardValue("6♦")).toEqual(6);
20+
expect(getCardValue("7♣")).toEqual(7);
21+
expect(getCardValue("8♠")).toEqual(8);
22+
expect(getCardValue("9♦")).toEqual(9);
23+
expect(getCardValue("10♣")).toEqual(10);
24+
});
1425
// Face Cards (J, Q, K)
26+
test(`Should return 10 when given a number card`, () => {
27+
expect(getCardValue("K♠")).toEqual(10);
28+
expect(getCardValue("q♦")).toEqual(10);
29+
expect(getCardValue("J♣")).toEqual(10);
30+
});
31+
1532
// Invalid Cards
33+
test(`Should return Invalid Cards when given invalid inputs`, () => {
34+
expect(() => getCardValue("")).toThrow();
35+
expect(() => getCardValue("11")).toThrow();
36+
expect(() => getCardValue("♠10")).toThrow();
37+
expect(() => getCardValue("invalid")).toThrow();
38+
expect(() => getCardValue("1♠")).toThrow();
39+
expect(() => getCardValue("ab")).toThrow();
40+
41+
});
1642

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"keywords": [],
1010
"author": "Code Your Future",
1111
"license": "ISC",
12-
"dependencies": {
13-
"jest": "^29.7.0"
12+
"devDependencies": {
13+
"jest": "^30.4.2"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)