Skip to content

Commit ced98d6

Browse files
committed
Made small test with jest changes
1 parent 3934b5d commit ced98d6

File tree

5 files changed

+37
-64
lines changed

5 files changed

+37
-64
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
function getAngleType(angle) {
1111
if (angle === 90) {
1212
return "Right angle";
13-
} else if (angle < 90 && angle > 0) {
13+
} else if (angle < 90) {
1414
return "Acute angle";
1515
} else if (angle > 90 && angle < 180) {
1616
return "Obtuse angle";

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,7 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
// Handle invalid denominators (e.g., divide by zero)
12-
if (denominator === 0) {
13-
return false;
14-
}
15-
16-
// Compare absolute values for proper fraction check
17-
if (Math.abs(numerator) < Math.abs(denominator)) {
18-
return true;
19-
} else {
20-
return false;
21-
}
11+
return Math.abs(numerator) < Math.abs(denominator);
2212
}
2313

2414
// The line below allows us to load the isProperFraction function into tests in other files.

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

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,20 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
// Extract rank (everything except the last character, which is the suit)
12-
const rank = card.slice(0, -1);
11+
let rank = card.slice(0, card.length - 1);
1312

14-
// Handle Ace
1513
if (rank === "A") {
1614
return 11;
17-
}
1815

19-
// Handle Face Cards
20-
if (["K", "Q", "J", "10"].includes(rank)) {
16+
} else if ((parseInt(rank) >= 2 && parseInt(rank)) && parseInt(rank) < 11){
17+
return parseInt(rank)
18+
}
19+
else if( rank === "J" || rank === "Q" || rank === "K") {
2120
return 10;
2221
}
23-
24-
// Handle Number Cards (2–9)
25-
if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) {
26-
return Number(rank);
22+
else{
23+
throw new Error("Invalid card rank.")
2724
}
28-
29-
// Handle invalid inputs
30-
throw new Error("Invalid card rank");
3125
}
3226

3327
// The line below allows us to load the getCardValue function into tests in other files.
@@ -62,32 +56,27 @@ assertEquals(fiveofHearts, 5);
6256
// Given a card with a rank of "10," "J," "Q," or "K",
6357
// When the function is called with such a card,
6458
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
65-
const jackOfDiamonds = getCardValue("J♦");
66-
assertEquals(jackOfDiamonds, 10);
67-
68-
const queenOfClubs = getCardValue("Q♣");
69-
assertEquals(queenOfClubs, 10);
70-
71-
const kingOfSpades = getCardValue("K♠");
72-
assertEquals(kingOfSpades, 10);
73-
74-
const tenOfHearts = getCardValue("10♥");
75-
assertEquals(tenOfHearts, 10);
59+
const cardOfJ = getCardValue("J♥");
60+
assertEquals(cardOfJ, 10);
61+
const cardOfQ = getCardValue("Q♠");
62+
assertEquals(cardOfQ, 10);
63+
const cardOfK = getCardValue("K♠");
64+
assertEquals(cardOfK, 10);
7665

7766

7867
// Handle Ace (A):
7968
// Given a card with a rank of "A",
8069
// When the function is called with an Ace,
8170
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
82-
const aceofClubs = getCardValue("A");
83-
assertEquals(aceofClubs, 11);
71+
const aceOfHeart = getCardValue("A");
72+
assertEquals(aceOfHeart, 11);
8473

8574
// Handle Invalid Cards:
8675
// Given a card with an invalid rank (neither a number nor a recognized face card),
8776
// When the function is called with such a card,
8877
// Then it should throw an error indicating "Invalid card rank."
8978
try {
90-
getCardValue("X");
79+
assertEquals(getCardValue("X♥"), "Invalid card rank");
9180
} catch (error) {
92-
assertEquals(error.message, "Invalid card rank");
81+
console.log(error.message);
9382
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
44

55
test("should return true for a proper fraction", () => {
66
expect(isProperFraction(2, 3)).toEqual(true);
7-
});
7+
});
88

99
// Case 2: Identify Improper Fractions:
10-
test("should return false for an improper fraction (numerator > denominator)", () => {
11-
expect(isProperFraction(5, 3)).toEqual(false);
10+
test("should return false for improper fraction", () => {
11+
expect(isProperFraction(5, 2)).toEqual(false);
1212
});
1313

1414
// Case 3: Identify Negative Fractions:
15-
test("should correctly handle negative fractions", () => {
16-
expect(isProperFraction(-1, 3)).toEqual(true);
17-
expect(isProperFraction(1, -3)).toEqual(true);
18-
expect(isProperFraction(-4, 3)).toEqual(false);
15+
test("should return true for negative fraction", () => {
16+
expect(isProperFraction(-4, 7)).toEqual(true);
1917
});
2018

2119
// Case 4: Identify Equal Numerator and Denominator:
22-
test("should return false when numerator and denominator are equal", () => {
20+
test("should return false for Equal Numerator fraction", () => {
2321
expect(isProperFraction(3, 3)).toEqual(false);
2422
});

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,25 @@ test("should return 11 for Ace of Spades", () => {
99

1010
// Case 2: Handle Number Cards (2-10):
1111
test("should return correct value for number cards", () => {
12-
expect(getCardValue("2♥")).toEqual(2);
13-
expect(getCardValue("5♦")).toEqual(5);
14-
expect(getCardValue("9♣")).toEqual(9);
15-
expect(getCardValue("10♠")).toEqual(10);
12+
const fiveheart = getCardValue("5♥");
13+
expect(fiveheart).toEqual(5);
1614
});
1715

1816
// Case 3: Handle Face Cards (J, Q, K):
19-
test("should return 10 for face cards (J, Q, K)", () => {
20-
expect(getCardValue("J♦")).toEqual(10);
21-
expect(getCardValue("Q♥")).toEqual(10);
22-
expect(getCardValue("K♣")).toEqual(10);
17+
test("Case 3: Handle Face Cards (J, Q, K)", () => {
18+
const cardOfJ = getCardValue("J♥");
19+
expect(cardOfJ).toEqual(10);
2320
});
2421

2522
// Case 4: Handle Ace (A):
26-
test("should return 11 for Ace of any suit", () => {
27-
expect(getCardValue("A♣")).toEqual(11);
28-
expect(getCardValue("A♦")).toEqual(11);
29-
expect(getCardValue("A♥")).toEqual(11);
23+
test("Case 4: Handle Face Cards (J, Q, K)", () => {
24+
const aceOfHeart = getCardValue("A♥");
25+
expect(aceOfHeart).toEqual(11);
3026
});
3127

3228
// Case 5: Handle Invalid Cards:
33-
test("should throw an error for invalid card ranks", () => {
34-
expect(() => getCardValue("X♣")).toThrow("Invalid card rank");
35-
expect(() => getCardValue("1♠")).toThrow("Invalid card rank");
36-
expect(() => getCardValue("Z♦")).toThrow("Invalid card rank");
29+
test("Case 5: Handle Invalid Cards", () => {
30+
expect(() => {
31+
getCardValue("21♠");
32+
}).toThrow("Invalid card rank");
3733
});

0 commit comments

Comments
 (0)