Skip to content

Commit b561db4

Browse files
committed
reset 1-imp... to main
1 parent 478b72b commit b561db4

File tree

6 files changed

+25
-128
lines changed

6 files changed

+25
-128
lines changed

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

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

1717
function getAngleType(angle) {
18-
if (angle > 360)
19-
angleType = "Invalid"
20-
else if (angle > 180){
21-
angleType = "Reflex angle"
22-
}
23-
else if (angle == 180){
24-
angleType = "Straight angle"
25-
}
26-
else if (angle > 90){
27-
angleType = "Obtuse angle"
28-
}
29-
else if ( angle == 90){
30-
angleType = "Right angle"
31-
}
32-
else {
33-
angleType = "Acute angle"
34-
}
35-
36-
return angleType
18+
// TODO: Implement this function
3719
}
3820

39-
console.log(getAngleType(320));
40-
41-
4221
// The line below allows us to load the getAngleType function into tests in other files.
4322
// This will be useful in the "rewrite tests with jest" step.
4423
module.exports = getAngleType;
@@ -51,7 +30,7 @@ function assertEquals(actualOutput, targetOutput) {
5130
`Expected ${actualOutput} to equal ${targetOutput}`
5231
);
5332
}
54-
assertEquals(getAngleType(320), "Acute angle");
33+
5534
// TODO: Write tests to cover all cases, including boundary and invalid cases.
5635
// Example: Identify Right Angles
5736
const right = getAngleType(90);

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

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

1313
function isProperFraction(numerator, denominator) {
14-
if (numerator >= denominator) {
15-
return false;
16-
} else {
17-
return true;
18-
}
14+
// TODO: Implement this function
1915
}
2016

2117
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -35,8 +31,3 @@ function assertEquals(actualOutput, targetOutput) {
3531

3632
// Example: 1/2 is a proper fraction
3733
assertEquals(isProperFraction(1, 2), true);
38-
assertEquals(isProperFraction(5, 6), true);
39-
assertEquals(isProperFraction(1, 100), true);
40-
assertEquals(isProperFraction(3, 2), false);
41-
assertEquals(isProperFraction(9, 9), false);
42-
assertEquals(isProperFraction(100, 2), false);

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

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,31 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
const cardSuit = card.slice(card.length - 1);
26-
const cardRank = card.slice(0, card.length - 1);
27-
let cardValue;
28-
if (
29-
["♠", "♥", "♦", "♣"].includes(cardSuit) &&
30-
["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"].includes(
31-
cardRank
32-
)
33-
) {
34-
if (cardRank == "1") {
35-
throw "invalid";
36-
}
37-
38-
switch (cardRank) {
39-
case "A":
40-
return 11;
41-
case "K":
42-
case "Q":
43-
case "J":
44-
return 10;
45-
//case "1": throw RangeError("invalid")
46-
default:
47-
return parseInt(cardRank);
48-
}
49-
} else {
50-
throw "invalid";
51-
}
25+
// TODO: Implement this function
5226
}
5327

5428
// The line below allows us to load the getCardValue function into tests in other files.
5529
// This will be useful in the "rewrite tests with jest" step.
5630
module.exports = getCardValue;
5731

5832
// Helper functions to make our assertions easier to read.
59-
// function assertEquals(actualOutput, targetOutput) {
60-
// console.assert(
61-
// actualOutput === targetOutput,
62-
// `Expected ${actualOutput} to equal ${targetOutput}`
33+
function assertEquals(actualOutput, targetOutput) {
34+
console.assert(
35+
actualOutput === targetOutput,
36+
`Expected ${actualOutput} to equal ${targetOutput}`
37+
);
38+
}
6339

6440
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
65-
//invalid card cases can you think of?
41+
// Examples:
42+
assertEquals(getCardValue("9♠"), 9);
43+
44+
// Handling invalid cards
45+
try {
46+
getCardValue("invalid");
47+
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+
52+
// 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: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,8 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1313
expect(getAngleType(89)).toEqual("Acute angle");
1414
});
1515

16-
//Case 2: Right angle
17-
test(`should return "Right angle" when (angle === 90)`, () => {
18-
expect(getAngleType(90)).toEqual("Right angle");
19-
});
20-
16+
// Case 2: Right angle
2117
// Case 3: Obtuse angles
22-
test(`should return "Obtuse angle" when (90> angle < 180)`,() =>{
23-
expect(getAngleType(91)).toEqual("Obtuse angle")
24-
expect(getAngleType(127)).toEqual("Obtuse angle")
25-
expect(getAngleType(179)).toEqual("Obtuse angle")
26-
});
27-
2818
// Case 4: Straight angle
29-
test(`Should return "Straight angle" when ( angle === 180)`,()=>{
30-
expect(getAngleType(180)).toEqual("Straight angle")
31-
});
32-
3319
// Case 5: Reflex angles
34-
test(`should return "Reflex angle" when (180> angle <=360)`,()=>{
35-
expect(getAngleType(181)).toEqual("Reflex angle")
36-
expect(getAngleType(270)).toEqual("Reflex angle")
37-
expect(getAngleType(359)).toEqual("Reflex angle")
38-
39-
});
4020
// Case 6: Invalid angles
41-
test(`should return "Invalid angle" when(360>)`,()=>{
42-
expect(getAngleType(361)).toEqual("Invalid")
43-
});

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,4 @@ const isProperFraction = require("../implement/2-is-proper-fraction");
77
// Special case: numerator is zero
88
test(`should return false when denominator is zero`, () => {
99
expect(isProperFraction(1, 0)).toEqual(false);
10-
expect(isProperFraction(0,0)).toEqual(false)
11-
});
12-
13-
// Where the numerator is > than the denominator
14-
test(`should return false when the (numerator > denominator)`,()=>{
15-
expect(isProperFraction(4,2)).toEqual(false)
16-
expect(isProperFraction(100,6)).toEqual(false)
17-
expect(isProperFraction(5,-10)).toEqual(false)
18-
});
19-
20-
// Where the fraction is correct
21-
test(`Should return a true when the (numerator < denominator)`,()=>{
22-
expect(isProperFraction(1,2)).toEqual(true)
23-
expect(isProperFraction(6,8)).toEqual(true)
24-
expect(isProperFraction(-1,2)).toEqual(true)
2510
});

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,14 @@ const getCardValue = require("../implement/3-get-card-value");
77
// Case 1: Ace (A)
88
test(`Should return 11 when given an ace card`, () => {
99
expect(getCardValue("A♠")).toEqual(11);
10-
expect(getCardValue("A♣")).toEqual(11);
11-
expect(getCardValue("A♥")).toEqual(11);
12-
expect(getCardValue("A♦")).toEqual(11);
1310
});
1411

1512
// Suggestion: Group the remaining test data into these categories:
1613
// Number Cards (2-10)
17-
test(`Should return 11 when given an ace card`, () => {
18-
expect(getCardValue("7♠")).toEqual(7);
19-
expect(getCardValue("9♣")).toEqual(9);
20-
expect(getCardValue("3♥")).toEqual(3);
21-
expect(getCardValue("5♦")).toEqual(5);
22-
});
2314
// Face Cards (J, Q, K)
24-
test(`Should return 11 when given an ace card`, () => {
25-
expect(getCardValue("J♠")).toEqual(10);
26-
expect(getCardValue("K♣")).toEqual(10);
27-
expect(getCardValue("Q♥")).toEqual(10);
28-
expect(getCardValue("K♦")).toEqual(10);
29-
});
30-
//Invalid Cards
31-
test("throws on invalid card", () => {
32-
expect(() => {
33-
getCardValue("JJ"); }).toThrow("invalid");
34-
expect(() => {
35-
getCardValue("1♠"); }).toThrow("invalid");
36-
expect(() => {
37-
getCardValue("A1"); }).toThrow("invalid");
15+
// Invalid Cards
3816

39-
});
4017
// To learn how to test whether a function throws an error as expected in Jest,
4118
// please refer to the Jest documentation:
4219
// https://jestjs.io/docs/expect#tothrowerror
20+

0 commit comments

Comments
 (0)