Skip to content

Commit 6e28c70

Browse files
committed
fix restore original files
1 parent 4fddfd0 commit 6e28c70

6 files changed

Lines changed: 19 additions & 160 deletions

File tree

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,8 @@
1616

1717
function getAngleType(angle) {
1818
// TODO: Implement this function
19-
if (angle > 0 && angle < 90) {
20-
return "Acute angle";
21-
}
22-
if (angle === 90) return "Right angle";
23-
if (angle > 90 && angle < 180) {
24-
return "Obtuse angle";
25-
}
26-
if (angle === 180) return "Straight angle";
27-
else if (angle > 180 && angle < 360) {
28-
return "Reflex angle";
29-
} else {
30-
return "Invalid angle";
31-
}
3219
}
20+
3321
// The line below allows us to load the getAngleType function into tests in other files.
3422
// This will be useful in the "rewrite tests with jest" step.
3523
module.exports = getAngleType;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15-
if (denominator <= 0) {
16-
return false;
17-
}
18-
return numerator < denominator;
1915
}
2016

2117
// 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: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,6 @@
2323

2424
function getCardValue(card) {
2525
// TODO: Implement this function
26-
const validSuits = ["♠", "♥", "♦", "♣"];
27-
// Get the suit (last character) and rank (everything before it)
28-
const suit = card.slice(-1);
29-
const rank = card.slice(0, -1);
30-
console.log(suit, rank);
31-
32-
// Check that the suit is valid
33-
if (!validSuits.includes(suit)) {
34-
throw new Error("Invalid card");
35-
}
36-
// Ace
37-
if (rank === "A") {
38-
return 11;
39-
}
40-
41-
if (rank === "J" || rank === "Q" || rank === "K") {
42-
return 10;
43-
}
44-
45-
if (
46-
rank === "2" ||
47-
rank === "3" ||
48-
rank === "4" ||
49-
rank === "5" ||
50-
rank === "6" ||
51-
rank === "7" ||
52-
rank === "8" ||
53-
rank === "9" ||
54-
rank === "10"
55-
) {
56-
return Number(rank);
57-
}
58-
59-
throw new Error("Invalid card");
6026
}
6127

6228
// The line below allows us to load the getCardValue function into tests in other files.
@@ -71,30 +37,18 @@ function assertEquals(actualOutput, targetOutput) {
7137
);
7238
}
7339

74-
// // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
75-
// // Examples:
76-
// assertEquals(getCardValue("9♠"), 9);
77-
78-
// // Handling invalid cards
79-
// try {
80-
// getCardValue("invalid");
40+
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
41+
// Examples:
42+
assertEquals(getCardValue("9♠"), 9);
8143

82-
// // This line will not be reached if an error is thrown as expected
83-
// console.error("Error was not thrown for invalid card 😢");
84-
// } catch (e) {
85-
// console.log("Error thrown for invalid card 🎉");
86-
// }
44+
// Handling invalid cards
45+
try {
46+
getCardValue("invalid");
8747

88-
// // What other invalid card cases can you think of?
89-
// //invalid rank
90-
// getCardValue("1♠");
91-
// getCardValue("11♣");
92-
// getCardValue("0♦");
93-
// getCardValue("B♥");
94-
// getCardValue("X♠");
48+
// This line will not be reached if an error is thrown as expected
49+
console.error("Error was not thrown for invalid card 😢");
50+
} catch (e) {
51+
console.log("Error thrown for invalid card 🎉");
52+
}
9553

96-
// //invalid suit
97-
// getCardValue("AX");
98-
// getCardValue("5*");
99-
// getCardValue("10H");
100-
// getCardValue("QS");
54+
// What other invalid card cases can you think of?

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

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

1616
// Case 2: Right angle
17-
test(`should return "Right angle" when angle is 90`, () => {
18-
expect(getAngleType(90)).toEqual("Right angle");
19-
});
2017
// Case 3: Obtuse angles
21-
test(`should return "Obtuse angle" when angel is >90 & <180`, () => {
22-
expect(getAngleType(100)).toEqual("Obtuse angle");
23-
expect(getAngleType(95)).toEqual("Obtuse angle");
24-
});
2518
// Case 4: Straight angle
26-
test(`should return "Straight angle" when angle === 180`, () => {
27-
expect(getAngleType(180)).toEqual("Straight angle");
28-
});
2919
// Case 5: Reflex angles
30-
test('should return "Reflex angle" when 180 < angle < 360', () => {
31-
expect(getAngleType(181)).toEqual("Reflex angle");
32-
expect(getAngleType(260)).toEqual("Reflex angle");
33-
expect(getAngleType(359)).toEqual("Reflex angle");
34-
});
35-
3620
// Case 6: Invalid angles
37-
test('should return "Invalid angle" for angles outside the valid range', () => {
38-
expect(getAngleType(0)).toEqual("Invalid angle");
39-
expect(getAngleType(-10)).toEqual("Invalid angle");
40-
expect(getAngleType(360)).toEqual("Invalid angle");
41-
expect(getAngleType(500)).toEqual("Invalid angle");
42-
});
Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
1+
// This statement loads the isProperFraction function you wrote in the implement directory.
2+
// We will use the same function, but write tests for it using Jest in this file.
13
const isProperFraction = require("../implement/2-is-proper-fraction");
24

3-
test("should return true when numerator is less than denominator", () => {
4-
expect(isProperFraction(1, 2)).toEqual(true);
5-
expect(isProperFraction(3, 4)).toEqual(true);
6-
});
7-
8-
test("should return false when numerator is greater than denominator", () => {
9-
expect(isProperFraction(5, 2)).toEqual(false);
10-
expect(isProperFraction(10, 3)).toEqual(false);
11-
});
12-
13-
test("should return false when numerator equals denominator", () => {
14-
expect(isProperFraction(4, 4)).toEqual(false);
15-
});
16-
17-
test("should return true when numerator is zero and denominator is positive", () => {
18-
expect(isProperFraction(0, 5)).toEqual(true);
19-
});
5+
// TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories.
206

21-
test("should return false when denominator is zero", () => {
7+
// Special case: numerator is zero
8+
test(`should return false when denominator is zero`, () => {
229
expect(isProperFraction(1, 0)).toEqual(false);
2310
});
24-
25-
test("should return false when numerator and denominator are zero", () => {
26-
expect(isProperFraction(0, 0)).toEqual(false);
27-
});
28-
29-
test("should return true when numerator is negative and denominator is positive", () => {
30-
expect(isProperFraction(-1, 6)).toEqual(true);
31-
});
32-
33-
test("should return false when denominator is negative", () => {
34-
expect(isProperFraction(1, -5)).toEqual(false);
35-
});
36-
37-
test("should return false when both numerator and denominator are negative", () => {
38-
expect(isProperFraction(-4, -5)).toEqual(false);
39-
});

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

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,6 @@ const getCardValue = require("../implement/3-get-card-value");
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
1010
});
11-
// Case 2: Number cards (2–10)
12-
test("should return the value of number cards", () => {
13-
expect(getCardValue("2♠")).toEqual(2);
14-
expect(getCardValue("5♦")).toEqual(5);
15-
expect(getCardValue("10♣")).toEqual(10);
16-
});
17-
18-
// Case 3: Face cards (J, Q, K)
19-
test("should return 10 for face cards", () => {
20-
expect(getCardValue("J♠")).toEqual(10);
21-
expect(getCardValue("Q♥")).toEqual(10);
22-
expect(getCardValue("K♦")).toEqual(10);
23-
});
24-
25-
// Case 4: Invalid cards
26-
test("should return error for invalid cards", () => {
27-
expect(() => {
28-
getCardValue("1♠");
29-
}).toThrow("Invalid card");
30-
expect(() => {
31-
getCardValue("11♠");
32-
}).toThrow("Invalid card");
33-
expect(() => {
34-
getCardValue("X♦");
35-
}).toThrow("Invalid card");
36-
expect(() => {
37-
getCardValue("");
38-
}).toThrow("Invalid card");
39-
});
4011

4112
// Suggestion: Group the remaining test data into these categories:
4213
// Number Cards (2-10)
@@ -46,3 +17,4 @@ test("should return error for invalid cards", () => {
4617
// To learn how to test whether a function throws an error as expected in Jest,
4718
// please refer to the Jest documentation:
4819
// https://jestjs.io/docs/expect#tothrowerror
20+

0 commit comments

Comments
 (0)