Skip to content

Commit 4b42ede

Browse files
committed
i've now learned how to move files from 1 branch to another : |
1 parent 3372770 commit 4b42ede

File tree

6 files changed

+128
-25
lines changed

6 files changed

+128
-25
lines changed

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

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

1717
function getAngleType(angle) {
18-
// TODO: Implement this function
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
1937
}
2038

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

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

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

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

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

3236
// Example: 1/2 is a proper fraction
3337
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: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,44 @@
2222
// execute the code to ensure all tests pass.
2323

2424
function getCardValue(card) {
25-
// TODO: Implement this function
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+
}
2652
}
2753

2854
// The line below allows us to load the getCardValue function into tests in other files.
2955
// This will be useful in the "rewrite tests with jest" step.
3056
module.exports = getCardValue;
3157

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

4064
// TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
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?
65+
//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: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => {
1313
expect(getAngleType(89)).toEqual("Acute angle");
1414
});
1515

16-
// Case 2: Right angle
16+
//Case 2: Right angle
17+
test(`should return "Right angle" when (angle === 90)`, () => {
18+
expect(getAngleType(90)).toEqual("Right angle");
19+
});
20+
1721
// 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+
1828
// Case 4: Straight angle
29+
test(`Should return "Straight angle" when ( angle === 180)`,()=>{
30+
expect(getAngleType(180)).toEqual("Straight angle")
31+
});
32+
1933
// 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+
});
2040
// 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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,19 @@ 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)
1025
});

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,36 @@ 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);
1013
});
1114

1215
// Suggestion: Group the remaining test data into these categories:
1316
// 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+
});
1423
// Face Cards (J, Q, K)
15-
// Invalid Cards
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");
1638

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

0 commit comments

Comments
 (0)