Skip to content

Commit 4455f27

Browse files
committed
1-implement-and-rewrite-tests file has completed
1 parent 8f3d6cf commit 4455f27

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010
function getAngleType(angle) {
1111
if (angle === 90) {
1212
return "Right angle";
13+
} else if (angle === 45) {
14+
return "Acute angle";
15+
} else if (angle > 90 && angle < 180) {
16+
return "Obtuse angle";
17+
} else if (angle === 180) {
18+
return "Straight angle";
19+
} else if (angle > 180 && angle < 360) {
20+
return "Reflec angle";
21+
} else {
22+
return "Invalid angle";
1323
}
14-
// Run the tests, work out what Case 2 is testing, and implement the required code here.
15-
// Then keep going for the other cases, one at a time.
1624
}
1725

1826
// The line below allows us to load the getAngleType function into tests in other files.
@@ -50,14 +58,17 @@ assertEquals(acute, "Acute angle");
5058
// When the angle is greater than 90 degrees and less than 180 degrees,
5159
// Then the function should return "Obtuse angle"
5260
const obtuse = getAngleType(120);
53-
// ====> write your test here, and then add a line to pass the test in the function above
61+
assertEquals(obtuse, "Obtuse angle");
5462

5563
// Case 4: Identify Straight Angles:
5664
// When the angle is exactly 180 degrees,
5765
// Then the function should return "Straight angle"
58-
// ====> write your test here, and then add a line to pass the test in the function above
66+
const straight = getAngleType(180);
67+
assertEquals(straight, "Straight angle");
5968

6069
// Case 5: Identify Reflex Angles:
6170
// When the angle is greater than 180 degrees and less than 360 degrees,
6271
// Then the function should return "Reflex angle"
63-
// ====> write your test here, and then add a line to pass the test in the function above
72+
73+
const reflex = getAngleType(181);
74+
assertEquals(reflex, "Reflec angle");

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
// write one test at a time, and make it pass, build your solution up methodically
99

1010
function isProperFraction(numerator, denominator) {
11-
if (numerator < denominator) {
12-
return true;
13-
}
11+
return Math.abs(numerator) < Math.abs(denominator);
1412
}
1513

1614
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -46,14 +44,26 @@ assertEquals(improperFraction, false);
4644
// target output: true
4745
// 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.
4846
const negativeFraction = isProperFraction(-4, 7);
47+
assertEquals(negativeFraction, true);
4948
// ====> complete with your assertion
5049

5150
// Equal Numerator and Denominator check:
5251
// Input: numerator = 3, denominator = 3
5352
// target output: false
5453
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5554
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
55+
assertEquals(equalFraction, false);
5756

5857
// Stretch:
5958
// What other scenarios could you test for?
59+
const negativeDenominator = isProperFraction(4, -7);
60+
assertEquals(negativeDenominator, true);
61+
62+
const zeroNumerator = isProperFraction(0, 3);
63+
assertEquals(zeroNumerator, true);
64+
65+
const zeroDenominator = isProperFraction(4, 0);
66+
assertEquals(zeroDenominator, false);
67+
68+
const zero = isProperFraction(0, 0);
69+
assertEquals(zero, false);

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
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+
let rank = card.length === 1 ? card : card.slice(0, -1);
1112
if (rank === "A") {
1213
return 11;
1314
}
15+
16+
if (["J", "Q", "K", "10"].includes(rank)) {
17+
return 10;
18+
}
19+
const number = parseInt(rank);
20+
if (number >= 2 && number <= 9) {
21+
return number;
22+
}
23+
return "Invalid card rank";
1424
}
1525

1626
// The line below allows us to load the getCardValue function into tests in other files.
@@ -28,7 +38,9 @@ function assertEquals(actualOutput, targetOutput) {
2838
}
2939
// Acceptance criteria:
3040

31-
// 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 be a number 2-10, or one letter of J, Q, K, A),
41+
// Given a card string in the format "A♠" (representing a card in
42+
// blackjack - the last character will always be an emoji for a suit,
43+
// and all characters before will be a number 2-10, or one letter of J, Q, K, A),
3244
// When the function getCardValue is called with this card string as input,
3345
// Then it should return the numerical card value
3446
const aceofSpades = getCardValue("A♠");
@@ -39,19 +51,25 @@ assertEquals(aceofSpades, 11);
3951
// When the function is called with such a card,
4052
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4153
const fiveofHearts = getCardValue("5♥");
42-
// ====> write your test here, and then add a line to pass the test in the function above
54+
assertEquals(fiveofHearts, 5);
4355

4456
// Handle Face Cards (J, Q, K):
4557
// Given a card with a rank of "10," "J," "Q," or "K",
4658
// When the function is called with such a card,
4759
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
60+
const faceCards = getCardValue("J");
61+
assertEquals(faceCards, 10);
4862

4963
// Handle Ace (A):
5064
// Given a card with a rank of "A",
5165
// When the function is called with an Ace,
5266
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
67+
const ace = getCardValue("A");
68+
assertEquals(ace, 11);
5369

5470
// Handle Invalid Cards:
5571
// Given a card with an invalid rank (neither a number nor a recognized face card),
5672
// When the function is called with such a card,
5773
// Then it should throw an error indicating "Invalid card rank."
74+
const invalidCard = getCardValue("BJ");
75+
assertEquals(invalidCard, "Invalid card rank");

0 commit comments

Comments
 (0)