Skip to content

Commit 66afa7c

Browse files
author
Payman IB
committed
anew branch with just sprint 3 files
1 parent 8f3d6cf commit 66afa7c

23 files changed

+5257
-9
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,22 @@ function getAngleType(angle) {
1111
if (angle === 90) {
1212
return "Right angle";
1313
}
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.
14+
15+
if (angle < 90) {
16+
return "Acute angle";
17+
}
18+
19+
if (angle > 90 && angle < 180) {
20+
return "Obtuse angle";
21+
}
22+
23+
if (angle === 180) {
24+
return "Straight angle";
25+
}
26+
27+
if (angle > 180 && angle < 360) {
28+
return "Reflex angle";
29+
}
1630
}
1731

1832
// The line below allows us to load the getAngleType function into tests in other files.
@@ -50,14 +64,20 @@ assertEquals(acute, "Acute angle");
5064
// When the angle is greater than 90 degrees and less than 180 degrees,
5165
// Then the function should return "Obtuse angle"
5266
const obtuse = getAngleType(120);
67+
5368
// ====> write your test here, and then add a line to pass the test in the function above
69+
assertEquals(obtuse, "Obtuse angle");
5470

5571
// Case 4: Identify Straight Angles:
5672
// When the angle is exactly 180 degrees,
5773
// Then the function should return "Straight angle"
5874
// ====> write your test here, and then add a line to pass the test in the function above
75+
const straight = getAngleType(180);
76+
assertEquals(straight, "Straight angle");
5977

6078
// Case 5: Identify Reflex Angles:
6179
// When the angle is greater than 180 degrees and less than 360 degrees,
6280
// 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
81+
// ====> write your test here, and then add a line to pass the test in the function above
82+
const reflex = getAngleType(270);
83+
assertEquals(reflex, "Reflex angle");

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
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) {
11+
if (Math.abs(numerator) < Math.abs(denominator)) {
1212
return true;
1313
}
14+
else if (numerator >= denominator) {
15+
return false;
16+
}
1417
}
1518

1619
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,29 +34,38 @@ function assertEquals(actualOutput, targetOutput) {
3134
// Input: numerator = 2, denominator = 3
3235
// target output: true
3336
// Explanation: The fraction 2/3 is a proper fraction, where the numerator is less than the denominator. The function should return true.
37+
3438
const properFraction = isProperFraction(2, 3);
3539
assertEquals(properFraction, true);
3640

3741
// Improper Fraction check:
3842
// Input: numerator = 5, denominator = 2
3943
// target output: false
4044
// Explanation: The fraction 5/2 is an improper fraction, where the numerator is greater than or equal to the denominator. The function should return false.
45+
46+
4147
const improperFraction = isProperFraction(5, 2);
4248
assertEquals(improperFraction, false);
4349

4450
// Negative Fraction check:
4551
// Input: numerator = -4, denominator = 7
4652
// target output: true
4753
// 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.
54+
55+
4856
const negativeFraction = isProperFraction(-4, 7);
49-
// ====> complete with your assertion
57+
assertEquals(negativeFraction, true);
5058

5159
// Equal Numerator and Denominator check:
5260
// Input: numerator = 3, denominator = 3
5361
// target output: false
5462
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
63+
5564
const equalFraction = isProperFraction(3, 3);
56-
// ====> complete with your assertion
65+
assertEquals(equalFraction, false);
5766

5867
// Stretch:
5968
// What other scenarios could you test for?
69+
70+
const invalidFraction = isProperFraction(0, 5);
71+
assertEquals(invalidFraction, true);

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
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+
1113
if (rank === "A") {
1214
return 11;
1315
}
16+
else if ( 2 <= rank && rank <= 9 ){
17+
return Number(rank);
18+
}
19+
else if (rank === "10" || rank === "J" || rank === "Q" || rank === "K") {
20+
return 10;
21+
}
22+
else {
23+
throw new Error("Invalid card rank.");
24+
}
1425
}
15-
1626
// The line below allows us to load the getCardValue function into tests in other files.
1727
// This will be useful in the "rewrite tests with jest" step.
1828
module.exports = getCardValue;
@@ -40,18 +50,32 @@ assertEquals(aceofSpades, 11);
4050
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
4151
const fiveofHearts = getCardValue("5♥");
4252
// ====> write your test here, and then add a line to pass the test in the function above
43-
53+
assertEquals(fiveofHearts, 5);
4454
// Handle Face Cards (J, Q, K):
4555
// Given a card with a rank of "10," "J," "Q," or "K",
4656
// When the function is called with such a card,
4757
// Then it should return the value 10, as these cards are worth 10 points each in blackjack.
58+
const tenofDiamonds = getCardValue("10♦");
59+
const jackofClubs = getCardValue("J♣");
60+
const queenofHearts = getCardValue("Q♥");
61+
const kingofSpades = getCardValue("K♠");
4862

63+
assertEquals(tenofDiamonds, 10);
64+
assertEquals(jackofClubs, 10);
65+
assertEquals(queenofHearts, 10);
66+
assertEquals(kingofSpades, 10);
4967
// Handle Ace (A):
5068
// Given a card with a rank of "A",
5169
// When the function is called with an Ace,
5270
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.
53-
71+
const aceofDiamonds = getCardValue("A♦");
72+
assertEquals(aceofDiamonds, 11);
5473
// Handle Invalid Cards:
5574
// Given a card with an invalid rank (neither a number nor a recognized face card),
5675
// When the function is called with such a card,
5776
// Then it should throw an error indicating "Invalid card rank."
77+
const invalidCard1 = () => getCardValue("1♠");
78+
assertEquals(invalidCard1 instanceof Function, true);
79+
80+
const invalidCard2 = () => getCardValue("B♥");
81+
assertEquals(invalidCard2 instanceof Function, true);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This statement loads the getAngleType function you wrote in the implement directory.
22
// We will use the same function, but write tests for it using Jest in this file.
3+
//const { test } = require("picomatch");
34
const getAngleType = require("../implement/1-get-angle-type");
45

56
test("should identify right angle (90°)", () => {
@@ -13,14 +14,30 @@ test("should identify right angle (90°)", () => {
1314
// When the angle is less than 90 degrees,
1415
// Then the function should return "Acute angle"
1516

17+
test("should identify acute angle (<90°)", () => {
18+
expect(getAngleType(45)).toEqual("Acute angle");
19+
})
20+
1621
// Case 3: Identify Obtuse Angles:
1722
// When the angle is greater than 90 degrees and less than 180 degrees,
1823
// Then the function should return "Obtuse angle"
1924

25+
test("should identify obtuse angle (>90° and <180°)", () => {
26+
expect(getAngleType(120)).toEqual("Obtuse angle");
27+
})
28+
2029
// Case 4: Identify Straight Angles:
2130
// When the angle is exactly 180 degrees,
2231
// Then the function should return "Straight angle"
2332

33+
test("should identify straight angle (180°)", () => {
34+
expect(getAngleType(180)).toEqual("Straight angle");
35+
})
36+
2437
// Case 5: Identify Reflex Angles:
2538
// When the angle is greater than 180 degrees and less than 360 degrees,
2639
// Then the function should return "Reflex angle"
40+
41+
test("should identify reflex angle (>180° and <360°)", () => {
42+
expect(getAngleType(270)).toEqual("Reflex angle");
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,7 +7,22 @@ test("should return true for a proper fraction", () => {
77
});
88

99
// Case 2: Identify Improper Fractions:
10+
test("should return false for an improper fraction", () =>{
11+
expect(isProperFraction(5, 2)).toEqual(false);
12+
});
1013

1114
// Case 3: Identify Negative Fractions:
15+
test("should return true for negative proper fraction", () => (
16+
expect(isProperFraction(-4,7)).toEqual(true)
17+
));
1218

1319
// Case 4: Identify Equal Numerator and Denominator:
20+
test("should return false when numerator equals denominator", () => {
21+
expect(isProperFraction(3,3)).toEqual(false);
22+
});
23+
24+
// Stretch:
25+
// What other scenarios could you test for?
26+
test("should return true for negative proper fraction with negative denominator", () => {
27+
expect(isProperFraction(4,-7)).toEqual(true);
28+
});

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This statement loads the getCardValue function you wrote in the implement directory.
22
// We will use the same function, but write tests for it using Jest in this file.
3+
// const { test } = require("picomatch");
34
const getCardValue = require("../implement/3-get-card-value");
45

56
test("should return 11 for Ace of Spades", () => {
@@ -8,6 +9,27 @@ test("should return 11 for Ace of Spades", () => {
89
});
910

1011
// Case 2: Handle Number Cards (2-10):
12+
test("should return numeric value for number cards (2-10)", () => {
13+
const fiveofHearts = getCardValue("5♥");
14+
expect(fiveofHearts).toEqual(5);
15+
});
1116
// Case 3: Handle Face Cards (J, Q, K):
17+
test("should return 10 for face cards (J, Q, K) and 10", () => {
18+
expect(getCardValue("10♦")).toEqual(10);
19+
expect(getCardValue("J♣")).toEqual(10);
20+
expect(getCardValue("Q♥")).toEqual(10);
21+
expect(getCardValue("K♠")).toEqual(10);
22+
});
1223
// Case 4: Handle Ace (A):
24+
test("should return 11 for Ace (A)", () => {
25+
expect(getCardValue("A♦")).toEqual(11);
26+
});
1327
// Case 5: Handle Invalid Cards:
28+
test("should throw an error for invalid card rank", () => {
29+
expect(() => {
30+
getCardValue("1♠");
31+
}).toThrow("Invalid card rank.");
32+
expect(() => {
33+
getCardValue("B♥");
34+
}).toThrow("Invalid card rank.");
35+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1763210812403" clover="3.2.0">
3+
<project timestamp="1763210812404" name="All files">
4+
<metrics statements="0" coveredstatements="0" conditionals="0" coveredconditionals="0" methods="0" coveredmethods="0" elements="0" coveredelements="0" complexity="0" loc="0" ncloc="0" packages="0" files="0" classes="0"/>
5+
</project>
6+
</coverage>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)