Skip to content

Commit 47e53a4

Browse files
refactor angle type checks and improve test assertions for clarity and consistency
1 parent fcd1c54 commit 47e53a4

File tree

6 files changed

+30
-38
lines changed

6 files changed

+30
-38
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
// Then, write the next test! :) Go through this process until all the cases are implemented
99

1010
function getAngleType(angle) {
11-
if(angle === 180){
12-
return "Straight angle"
11+
if (angle === 180) {
12+
return "Straight angle";
1313
}
14-
if(angle > 90 && angle < 180){
15-
return "Obtuse angle"
14+
if (angle > 90 && angle < 180) {
15+
return "Obtuse angle";
1616
}
1717
if (angle === 90) {
1818
return "Right angle";
1919
}
2020
if (angle < 90) {
2121
return "Acute angle";
2222
}
23-
if(angle > 180 && angle < 360){
24-
return "Reflex angle"
23+
if (angle > 180 && angle < 360) {
24+
return "Reflex angle";
2525
}
26-
// Run the tests, work out what Case 2 is testing, and implement the required code here.
27-
// Then keep going for the other cases, one at a time.
26+
// Run the tests, work out what Case 2 is testing, and implement the required code here.
27+
// Then keep going for the other cases, one at a time.
2828
}
2929

3030
// The line below allows us to load the getAngleType function into tests in other files.
@@ -70,11 +70,11 @@ assertEquals(obtuse, "Obtuse angle");
7070
// Then the function should return "Straight angle"
7171
// ====> write your test here, and then add a line to pass the test in the function above
7272
const straight = getAngleType(180);
73-
assertEquals(straight,"Straight angle")
73+
assertEquals(straight, "Straight angle");
7474

7575
// Case 5: Identify Reflex Angles:
7676
// When the angle is greater than 180 degrees and less than 360 degrees,
7777
// Then the function should return "Reflex angle"
7878
// ====> write your test here, and then add a line to pass the test in the function above
7979
const reflex = getAngleType(200);
80-
assertEquals(reflex,"Reflex angle")
80+
assertEquals(reflex, "Reflex angle");

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ function isProperFraction(numerator, denominator) {
1414
if (Math.abs(numerator) >= Math.abs(denominator)) {
1515
return false;
1616
}
17-
18-
if (isNaN(numerator)|| isNaN(denominator)) {
17+
18+
if (isNaN(numerator) || isNaN(denominator)) {
1919
return false;
2020
}
2121
}
2222

23-
2423
// The line below allows us to load the isProperFraction function into tests in other files.
2524
// This will be useful in the "rewrite tests with jest" step.
2625
module.exports = isProperFraction;
@@ -54,15 +53,15 @@ assertEquals(improperFraction, false);
5453
// target output: true
5554
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
5655
const negativeFraction = isProperFraction(-4, 7);
57-
assertEquals(negativeFraction,true)
56+
assertEquals(negativeFraction, true);
5857
// ====> complete with your assertion
5958

6059
// Equal Numerator and Denominator check:
6160
// Input: numerator = 3, denominator = 3
6261
// target output: false
6362
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
6463
const equalFraction = isProperFraction(3, 3);
65-
assertEquals(equalFraction,false)
64+
assertEquals(equalFraction, false);
6665
// ====> complete with your assertion
6766

6867
// Stretch:
@@ -72,5 +71,5 @@ assertEquals(equalFraction,false)
7271
//Input: numerator=NaN, denominator=3
7372
// target output: false
7473
// Explanation: the fraction NaN/3 is not a proper fraction because the numerator is not a number.The function should return false.
75-
const notANumberFraction=isProperFraction(NaN,3);
76-
assertEquals(notANumberFraction,false)
74+
const notANumberFraction = isProperFraction(NaN, 3);
75+
assertEquals(notANumberFraction, false);

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
1010
function getCardValue(card) {
11-
const rank=card.slice(0,-1);
12-
const numberRank=Number(rank)
13-
if(numberRank>=2 && numberRank<10){
11+
const rank = card.slice(0, -1);
12+
const numberRank = Number(rank);
13+
if (numberRank >= 2 && numberRank < 10) {
1414
return numberRank;
1515
}
16-
if(rank==="10" || rank==="J" || rank==="Q" || rank==="K"){
17-
return 10
16+
if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
17+
return 10;
1818
}
1919
if (rank === "A") {
2020
return 11;
@@ -37,14 +37,11 @@ function assertEquals(actualOutput, targetOutput) {
3737
}
3838

3939
function invalidCardRank(actualOutput, targetOutput) {
40-
console.assert(
41-
actualOutput === targetOutput,
42-
"Invalid card rank"
43-
);
40+
console.assert(actualOutput === targetOutput, "Invalid card rank");
4441
}
4542
// Acceptance criteria:
4643

47-
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will
44+
// Given a card string in the format "A♠" (representing a card in blackjack - the last character will always be an emoji for a suit, and all characters before will
4845
// be a number 2-10, or one letter of J, Q, K, A),
4946
// When the function getCardValue is called with this card string as input,
5047
// Then it should return the numerical card value
@@ -56,7 +53,7 @@ function invalidCardRank(actualOutput, targetOutput) {
5653
// When the function is called with such a card,
5754
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
5855
const fiveofHearts = getCardValue("5♥");
59-
assertEquals(fiveofHearts,5)
56+
assertEquals(fiveofHearts, 5);
6057

6158
const sixofHearts = getCardValue("6♥");
6259
assertEquals(sixofHearts, 6);
@@ -67,10 +64,9 @@ assertEquals(sixofHearts, 6);
6764
// When the function is called with such a card,
6865
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
6966
const faceCards = getCardValue("J♥");
70-
assertEquals(faceCards,10)
71-
72-
assertEquals(getCardValue("Q♥"),10);
67+
assertEquals(faceCards, 10);
7368

69+
assertEquals(getCardValue("Q♥"), 10);
7470

7571
// Handle Ace (A):
7672
// Given a card with a rank of "A",
@@ -84,4 +80,4 @@ assertEquals(aceofSpades, 11);
8480
// When the function is called with such a card,
8581
// Then it should throw an error indicating "Invalid card rank."
8682
const invalidCard = getCardValue("m");
87-
invalidCardRank(invalidCard, "Invalid card rank.");
83+
invalidCardRank(invalidCard, "Invalid card rank.");

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ test("should identify right angle (90°)", () => {
99
// REPLACE the comments with the tests
1010
// make your test descriptions as clear and readable as possible
1111

12-
1312
test("should identify acute angle (angle<90°)", () => {
1413
expect(getAngleType(80)).toEqual("Acute angle");
1514
});
@@ -18,12 +17,10 @@ test("should identify obtuse angle (angle>90°)", () => {
1817
expect(getAngleType(110)).toEqual("Obtuse angle");
1918
});
2019

21-
2220
test("should identify straight angle (angle<180°)", () => {
2321
expect(getAngleType(180)).toEqual("Straight angle");
2422
});
2523

26-
2724
test("should identify reflex angle (angle>180°)", () => {
2825
expect(getAngleType(190)).toEqual("Reflex angle");
29-
});
26+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ test("should return true for both negative numerator and denominator proper frac
2525
// Case 4: Identify Equal Numerator and Denominator:
2626
test("should return false for equal numerator and denominator", () => {
2727
expect(isProperFraction(2, 2)).toEqual(false);
28-
});
28+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ test("should return 11 for Ace of Spades", () => {
2929
test("should return invalid card for g of spades", () => {
3030
const gOfSpades = getCardValue("g♠");
3131
expect(gOfSpades).toEqual("Invalid card rank.");
32-
});
32+
});

0 commit comments

Comments
 (0)