Skip to content

Commit 7fe2790

Browse files
committed
sprint3 coursework done.
1 parent 5d8d05c commit 7fe2790

File tree

11 files changed

+85
-21
lines changed

11 files changed

+85
-21
lines changed

Sprint-3/2-mandatory-rewrite/1-get-angle-type.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
function getAngleType(angle) {
22
if (angle === 90) return "Right angle";
3-
// replace with your completed function from key-implement
3+
if (angle < 90) return "Acute angle";
4+
if (angle > 90 && angle < 180) return "Obtuse angle";
5+
if (angle === 180) return "Straight angle";
6+
if (angle > 180 && angle < 360) return "Reflex angle";
7+
}
48

59
}
610

Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ test("should identify right angle (90°)", () => {
44
expect(getAngleType(90)).toEqual("Right angle");
55
});
66

7-
// REPLACE the comments with the tests
8-
// make your test descriptions as clear and readable as possible
9-
107
// Case 2: Identify Acute Angles:
118
// When the angle is less than 90 degrees,
129
// Then the function should return "Acute angle"
10+
test("should identify acute angles (less than 90°)", () => {
11+
expect(getAngleType(45)).toEqual("Acute angle");
12+
});
1313

1414
// Case 3: Identify Obtuse Angles:
1515
// When the angle is greater than 90 degrees and less than 180 degrees,
1616
// Then the function should return "Obtuse angle"
17+
test("should identify obtuse angles (greater than 90° and less than 180°)", () => {
18+
expect(getAngleType(120)).toEqual("Obtuse angle");
19+
});
1720

1821
// Case 4: Identify Straight Angles:
1922
// When the angle is exactly 180 degrees,
2023
// Then the function should return "Straight angle"
24+
test("should identify straight angle (180°)", () => {
25+
expect(getAngleType(180)).toEqual("Straight angle");
26+
});
2127

22-
// Case 5: Identify Reflex Angles:
23-
// When the angle is greater than 180 degrees and less than 360 degrees,
24-
// Then the function should return "Reflex angle"
28+
/
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
function isProperFraction(numerator, denominator) {
22
if (numerator < denominator) return true;
33
// add your completed function from key-implement here
4+
if (Math.abs(numerator) < Math.abs(denominator)) {
5+
return true;
6+
} else {
7+
return false;
8+
}
49
}
510

6-
module.exports = isProperFraction;
11+
module.exports = isProperFraction;

Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ test("should return true for a proper fraction", () => {
55
});
66

77
// Case 2: Identify Improper Fractions:
8+
test("should return false for an improper fraction", () => {
9+
expect(isProperFraction(5, 2)).toEqual(false);
10+
});
811

912
// Case 3: Identify Negative Fractions:
13+
test("should return true for a negative proper fraction", () => {
14+
expect(isProperFraction(-4, 7)).toEqual(true);
15+
});
1016

1117
// Case 4: Identify Equal Numerator and Denominator:
18+
test("should return false when numerator and denominator are equal", () => {
19+
expect(isProperFraction(3, 3)).toEqual(false);
20+
});
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function getCardValue(card) {
2-
// replace with your code from key-implement
3-
return 11;
2+
const rank = card.slice(0, -1);
3+
if (rank === "A") return 11;
4+
if (rank === "J" || rank === "Q" || rank === "K" || rank === "10") return 10;
5+
if (!isNaN(rank)) return Number(rank);
6+
throw new Error("Invalid card rank.");
47
}
5-
module.exports = getCardValue;
8+
9+
module.exports = getCardValue;

Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@ const getCardValue = require("./3-get-card-value");
33
test("should return 11 for Ace of Spades", () => {
44
const aceofSpades = getCardValue("A♠");
55
expect(aceofSpades).toEqual(11);
6-
});
6+
});
77

88
// Case 2: Handle Number Cards (2-10):
9+
test("should return correct number for number cards", () => {
10+
expect(getCardValue("5♥")).toEqual(5);
11+
expect(getCardValue("10♦")).toEqual(10);
12+
});
13+
914
// Case 3: Handle Face Cards (J, Q, K):
15+
test("should return 10 for face cards J, Q, K", () => {
16+
expect(getCardValue("J♣")).toEqual(10);
17+
expect(getCardValue("Q♦")).toEqual(10);
18+
expect(getCardValue("K♥")).toEqual(10);
19+
});
20+
1021
// Case 4: Handle Ace (A):
22+
// (Already tested above with Ace of Spades)
23+
1124
// Case 5: Handle Invalid Cards:
25+
test("should throw error for invalid cards", () => {
26+
expect(() => getCardValue("Z♠")).toThrow("Invalid card rank.");
27+
expect(() => getCardValue("1♠")).toThrow("Invalid card rank.");
28+
});
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
for (let char of stringOfCharacters) {
4+
if (char === findCharacter) count++;
5+
}
6+
return count;
37
}
48

5-
module.exports = countChar;
9+
module.exports = countChar;

Sprint-3/3-mandatory-practice/implement/count.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// implement a function countChar that counts the number of times a character occurs in a string
21
const countChar = require("./count");
2+
33
// Given a string str and a single character char to search for,
44
// When the countChar function is called with these inputs,
55
// Then it should:
@@ -22,3 +22,10 @@ test("should count multiple occurrences of a character", () => {
2222
// And a character char that does not exist within the case-sensitive str,
2323
// When the function is called with these inputs,
2424
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
25+
26+
test("should return 0 if character does not occur", () => {
27+
const str = "Hello World";
28+
const char = "z";
29+
const count = countChar(str, char);
30+
expect(count).toEqual(0);
31+
});
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
const suffixes = ["th", "st", "nd", "rd"];
3+
const v = num % 100;
4+
if (v >= 11 && v <= 13) {
5+
return num + "th";
6+
} else {
7+
const suffix = suffixes[(num % 10)] || "th";
8+
return num + suffix;
9+
}
310
}
411

5-
module.exports = getOrdinalNumber;
12+
module.exports = getOrdinalNumber;

Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const getOrdinalNumber = require("./get-ordinal-number");
1010

1111
test("should return '1st' for 1", () => {
1212
expect(getOrdinalNumber(1)).toEqual("1st");
13-
});
13+
});

0 commit comments

Comments
 (0)