Skip to content

Commit 2211656

Browse files
author
JorvanW
committed
Removed code to fit submission requirements
1 parent 919dba4 commit 2211656

8 files changed

Lines changed: 18 additions & 144 deletions

File tree

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,6 @@
1515
// execute the code to ensure all tests pass.
1616

1717
function getAngleType(angle) {
18-
{
19-
if (angle > 0 && angle < 90) {
20-
return "Acute angle";
21-
}
22-
if (angle === 90) {
23-
return "Right angle";
24-
}
25-
if (angle > 90 && angle < 180) {
26-
return "Obtuse angle";
27-
}
28-
if (angle === 180) {
29-
return "Straight angle";
30-
}
31-
if (angle > 180 && angle < 360) {
32-
return "Reflex angle";
33-
}
34-
return "Invalid angle";
35-
}
36-
37-
3818
// TODO: Implement this function
3919
}
4020

@@ -55,6 +35,3 @@ function assertEquals(actualOutput, targetOutput) {
5535
// Example: Identify Right Angles
5636
const right = getAngleType(90);
5737
assertEquals(right, "Right angle");
58-
59-
60-

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// After you have implemented the function, write tests to cover all the cases, and
1111
// execute the code to ensure all tests pass.
1212

13+
function isProperFraction(numerator, denominator) {
14+
// TODO: Implement this function
15+
}
1316

1417
// The line below allows us to load the isProperFraction function into tests in other files.
1518
// This will be useful in the "rewrite tests with jest" step.
@@ -28,18 +31,3 @@ function assertEquals(actualOutput, targetOutput) {
2831

2932
// Example: 1/2 is a proper fraction
3033
assertEquals(isProperFraction(1, 2), true);
31-
32-
function isProperFraction(numerator, denominator) {
33-
if (denominator === 0) {
34-
return false;
35-
}
36-
if (numerator < denominator && numerator > 0) {
37-
return true;
38-
}
39-
return false;
40-
}
41-
console.log(isProperFraction(2,3)); // true
42-
43-
44-
module.exports = isProperFraction;
45-

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,9 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
const suit = card.slice(-1);
26-
const rank = card.slice(0, -1);
27-
28-
const validSuits = ["♠", "♥", "♦", "♣"];
29-
30-
if (!validSuits.includes(suit)) {
31-
throw new Error("Invalid card");
32-
}
33-
34-
if (rank === "A") {
35-
return 11;
36-
}
37-
38-
if (["J", "Q", "K"].includes(rank)) {
39-
return 10;
40-
}
41-
42-
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) {
43-
return Number(rank);
44-
}
45-
46-
throw new Error("Invalid card");
25+
// TODO: Implement this function
4726
}
4827

49-
5028
// The line below allows us to load the getCardValue function into tests in other files.
5129
// This will be useful in the "rewrite tests with jest" step.
5230
module.exports = getCardValue;
@@ -74,6 +52,3 @@ try {
7452
}
7553

7654
// What other invalid card cases can you think of?
77-
// logging cards without suits to throw error
78-
79-

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +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 === 90)`, () => {
18-
// Test various acute angles, including boundary cases
19-
expect(getAngleType(90)).toEqual("Right angle");
20-
});
21-
2217
// Case 3: Obtuse angles
23-
test(`should return "Obtuse angle" when (90 < angle < 180)`, () => {
24-
// Test various obtuse angles, including boundary cases
25-
expect(getAngleType(91)).toEqual("Obtuse angle");
26-
expect(getAngleType(135)).toEqual("Obtuse angle");
27-
expect(getAngleType(179)).toEqual("Obtuse angle");
28-
});
29-
30-
// Case 4: Straight angle
31-
test(`should return "Straight angle" when (angle === 180)`, () => {
32-
// Test various acute angles, including boundary cases
33-
expect(getAngleType(180)).toEqual("Straight angle");
34-
});
35-
18+
// Case 4: Straight angle
3619
// 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-
});
43-
4420
// Case 6: Invalid angles
45-
test(`should return "Invalid angle" when (angle < 0 || angle > 360)`, () => {
46-
// Test various invalid angles
47-
expect(getAngleType(-1)).toEqual("Invalid angle");
48-
expect(getAngleType(361)).toEqual("Invalid angle");
49-
});

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,3 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
1010
});
11-
12-
test(`should return false when numerator is zero`, () => {
13-
expect(isProperFraction(0, 1)).toEqual(false);
14-
});
15-
16-
test(`should return false when numerator is negative`, () => {
17-
expect(isProperFraction(-1, 2)).toEqual(false);
18-
});
19-
20-
test(`should return false when denominator is negative`, () => {
21-
expect(isProperFraction(1, -2)).toEqual(false);
22-
});
23-
24-
test(`should return false when both numerator and denominator are negative`, () => {
25-
expect(isProperFraction(-1, -2)).toEqual(false);
26-
});
27-
28-
test(`should return true when numerator is less than denominator`, () => {
29-
expect(isProperFraction(1, 2)).toEqual(true);
30-
});
31-
32-
test(`should return false when numerator is equal to denominator`, () => {
33-
expect(isProperFraction(2, 2)).toEqual(false);
34-
});
35-
36-
test(`should return false when numerator is greater than denominator`, () => {
37-
expect(isProperFraction(3, 2)).toEqual(false);
38-
});

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,10 @@ test(`Should return 11 when given an ace card`, () => {
1010
});
1111

1212
// Suggestion: Group the remaining test data into these categories:
13-
// Case 2 Number Cards (2-10)
14-
test(`Should return the same number when given a number card of any suit`, () => {
15-
expect(getCardValue("3♠")).toEqual(3);
16-
});
17-
18-
// Case 3 Face Cards (J, Q, K)
19-
test(`Should return 10 when given an any face card`, () => {
20-
expect(getCardValue("J♠")).toEqual(10);
21-
expect(getCardValue("Q♥")).toEqual(10)
22-
expect(getCardValue("K♦")).toEqual(10)
23-
});
24-
25-
13+
// Number Cards (2-10)
14+
// Face Cards (J, Q, K)
2615
// Invalid Cards
27-
// test(`Cards without suits return as Invalid card`, () => {
28-
// expect(getCardValue("10")).toEqual(new Error);
29-
// });
30-
test('Cards without suits return as Invalid card', () => {
31-
expect(() => {
32-
getCardValue("10");
33-
}).toThrow("Invalid card");
34-
});
16+
3517
// To learn how to test whether a function throws an error as expected in Jest,
3618
// please refer to the Jest documentation:
3719
// https://jestjs.io/docs/expect#tothrowerror

Sprint-3/3-dead-code/exercise-1.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Find the instances of unreachable and redundant code - remove them!
22
// The sayHello function should continue to work for any reasonable input it's given.
33

4-
let testName = "Aman";
4+
let testName = "Jerry";
55
const greeting = "hello";
66

77
function sayHello(greeting, name) {
8+
const greetingStr = greeting + ", " + name + "!";
89
return `${greeting}, ${name}!`;
10+
console.log(greetingStr);
911
}
1012

13+
testName = "Aman";
14+
1115
const greetingMessage = sayHello(greeting, testName);
1216

1317
console.log(greetingMessage); // 'hello, Aman!'

Sprint-3/3-dead-code/exercise-2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
// The countAndCapitalisePets function should continue to work for any reasonable input it's given, and you shouldn't modify the pets variable.
33

44
const pets = ["parrot", "hamster", "horse", "dog", "hamster", "cat", "hamster"];
5+
const capitalisedPets = pets.map((pet) => pet.toUpperCase());
56
const petsStartingWithH = pets.filter((pet) => pet[0] === "h");
67

8+
function logPets(petsArr) {
9+
petsArr.forEach((pet) => console.log(pet));
10+
}
11+
712
function countAndCapitalisePets(petsArr) {
813
const petCount = {};
914

0 commit comments

Comments
 (0)