Skip to content

Commit d9a6067

Browse files
author
Arthur
committed
fix it now
1 parent e25d0a4 commit d9a6067

5 files changed

Lines changed: 89 additions & 25 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
15-
return numerator< denominator ;
16-
14+
return Math.abs(numerator) < Math.abs(denominator);
1715
}
1816

1917
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -36,5 +34,5 @@ assertEquals(isProperFraction(1, 2), true);
3634
assertEquals(isProperFraction(2, 1), false);
3735
assertEquals(isProperFraction(2, 2), false);
3836

39-
4037
assertEquals(isProperFraction(0, 2), true);
38+
assertEquals(isProperFraction(-2, 1), false);

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

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,21 @@
2020
// execute the code to ensure all tests pass.
2121

2222
function getCardValue(card) {
23-
const rank = card.slice(0, -1);
23+
const rank = card.slice(0, -1);
2424

25-
26-
27-
if (rank === "A"){
28-
return 11 ;
25+
if (rank === "A") {
26+
return 11;
27+
} else if (rank === "J" || rank === "Q" || rank === "K") {
28+
return 10;
2929
}
30-
else if (rank === "J" || rank === "Q" || rank === "K"){
31-
return 10 ;
32-
};
33-
3430

35-
const value = Number(rank);
31+
const value = Number(rank);
3632

37-
if( value>=2 && value <= 10 ){
38-
return value};
33+
if (value >= 2 && value <= 10) {
34+
return value;
35+
}
3936

40-
throw new Error("invalid card!");
37+
throw new Error("Invalid card!");
4138
}
4239
// The line below allows us to load the getCardValue function into tests in other files.
4340
// This will be useful in the "rewrite tests with jest" step.
@@ -64,22 +61,20 @@ try {
6461
} catch (e) {
6562
console.log("Error thrown for invalid card 🎉");
6663
}
67-
6864

69-
try {
65+
try {
7066
getCardValue("null");
7167

7268
console.error("Error was not thrown for null card 😢");
7369
} catch (e) {
74-
console.log("Error thrown for invalid card 🎉")
70+
console.log("Error thrown for invalid card 🎉");
7571
}
7672

77-
try {
73+
try {
7874
getCardValue("0");
7975

8076
console.error("Error was not thrown for 0 card 😢");
8177
} catch (e) {
82-
console.log("Error thrown for invalid card 🎉")
78+
console.log("Error thrown for invalid card 🎉");
8379
}
8480
// What other invalid card cases can you think of?
85-

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

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

1616
// Case 2: Right angle
17+
18+
test(`Right angle`, () => {
19+
expect(getAngleType(90)).toEqual("Right angle");
20+
});
21+
1722
// Case 3: Obtuse angles
23+
24+
test(`Obtuse angle`, () => {
25+
expect(getAngleType(91)).toEqual("Obtuse angle");
26+
expect(getAngleType(135)).toEqual("Obtuse angle");
27+
expect(getAngleType(179)).toEqual("Obtuse angle");
28+
});
29+
1830
// Case 4: Straight angle
31+
32+
test(`Straight angle`, () => {
33+
expect(getAngleType(180)).toEqual("Straight angle");
34+
});
35+
1936
// Case 5: Reflex angles
37+
38+
test("reflex angle", () => {
39+
expect(getAngleType(181)).toEqual("Reflex angle");
40+
expect(getAngleType(270)).toEqual("Reflex angle");
41+
expect(getAngleType(359)).toEqual("Reflex angle");
42+
});
43+
2044
// Case 6: Invalid angles
45+
test("invalid angle", () => {
46+
expect(getAngleType(-10)).toEqual("Invalid angle");
47+
expect(getAngleType(361)).toEqual("Invalid angle");
48+
});

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
55
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
66

77
// Special case: numerator is zero
8-
test(`should return false when denominator is zero`, () => {
8+
9+
// Case 1: Denominator is Zero (The Impossible Pizza)
10+
test("should return false when denominator is zero", () => {
911
expect(isProperFraction(1, 0)).toEqual(false);
12+
expect(isProperFraction(0, 0)).toEqual(false);
13+
});
14+
15+
// Case 2: Numerator is Zero (Empty Plate)
16+
test("should return true when numerator is zero and denominator is not zero", () => {
17+
expect(isProperFraction(0, 2)).toEqual(true);
18+
});
19+
20+
// Case 3: Normal Positive Fractions
21+
test("should handle normal positive numbers correctly", () => {
22+
expect(isProperFraction(1, 2)).toEqual(true); // Small top, big bottom -> True!
23+
expect(isProperFraction(3, 2)).toEqual(false); // Big top, small bottom -> False!
24+
expect(isProperFraction(2, 2)).toEqual(false); // Same size (whole pizza) -> False!
25+
});
26+
27+
// Case 4: Negative Numbers (Minus Signs)
28+
test("should ignore minus signs and look only at the size of the numbers", () => {
29+
expect(isProperFraction(-1, 2)).toEqual(true); // 1 is smaller than 2 -> True!
30+
expect(isProperFraction(1, -2)).toEqual(true); // 1 is smaller than 2 -> True!
31+
expect(isProperFraction(-3, 2)).toEqual(false); // 3 is bigger than 2 -> False!
32+
expect(isProperFraction(-2, -2)).toEqual(false); // Same size -> False!
1033
});

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,27 @@ test(`Should return 11 when given an ace card`, () => {
1414
// Face Cards (J, Q, K)
1515
// Invalid Cards
1616

17+
test(`Number Cards (2-10)`, () => {
18+
expect(getCardValue("2♠")).toEqual(2);
19+
expect(getCardValue("5♠")).toEqual(5);
20+
expect(getCardValue("10♠")).toEqual(10);
21+
});
22+
23+
test(`Should return 11 when given an ace card`, () => {
24+
expect(getCardValue("A♠")).toEqual(11);
25+
});
26+
27+
test(`Should return 10 when given an face card`, () => {
28+
expect(getCardValue("J♠")).toEqual(10);
29+
expect(getCardValue("Q♠")).toEqual(10);
30+
expect(getCardValue("K♠")).toEqual(10);
31+
});
32+
33+
test(`Should return 10 when given an face card`, () => {
34+
expect(() => getCardValue("B♠")).toThrow("Invalid card!");
35+
expect(() => getCardValue("14♠")).toThrow("Invalid card!");
36+
});
37+
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)