Skip to content

Commit 30dfbd8

Browse files
committed
Transferred all of my changes to the updated foldersand removed all other subfolders.
1 parent 154071d commit 30dfbd8

26 files changed

+174
-618
lines changed

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

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

1010
function isProperFraction(numerator, denominator) {
11-
<<<<<<<< HEAD:Sprint-3/implement/2-is-proper-fraction.js
1211
if (Math.abs(numerator) < denominator) return true; // This version of code works correctly for proper and negative fractions.
1312
if (Math.abs(numerator) >= Math.abs(denominator)) return false;
1413
if (Math.abs(numerator) === Math.abs(denominator)) return false;
15-
========
14+
1615
if (numerator < denominator) {
1716
return true;
1817
}
19-
>>>>>>>> main:Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js
18+
2019
}
2120

2221
// The line below allows us to load the isProperFraction function into tests in other files.

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
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-
<<<<<<<< HEAD:Sprint-3/implement/3-get-card-value.js
1211
const rank = card.slice(0, -1); // get the rank (before the suit symbol)
1312

1413
if (!isNaN(rank)) {
@@ -26,16 +25,17 @@ function getCardValue(card) {
2625
}
2726

2827
// if the rank is not a number or a face card, throw an error(invalid card rank).
29-
========
30-
if (rank === "A") {
31-
return 11;
32-
}
33-
}
28+
29+
// if (rank === "x") {
30+
// return 11;
31+
// }
32+
33+
3434

3535
// The line below allows us to load the getCardValue function into tests in other files.
3636
// This will be useful in the "rewrite tests with jest" step.
3737
module.exports = getCardValue;
38-
>>>>>>>> main:Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js
38+
3939

4040
// You need to write assertions for your function to check it works in different cases
4141
// we're going to use this helper function to make our assertions easier to read
@@ -85,8 +85,8 @@ assertEquals(kingofSpades, 10);
8585
// Given a card with an invalid rank (neither a number nor a recognized face card),
8686
// When the function is called with such a card,
8787
// Then it should throw an error indicating "Invalid card rank."
88-
try {
89-
getCardValue("Z♠");
90-
} catch (error) {
91-
console.log("Caught error:", error.message); // Should say "Invalid card rank"
92-
}
88+
// try {
89+
// getCardValue("Z♠");
90+
// } catch (error) {
91+
// console.log("Caught error:", error.message); // Should say "Invalid card rank"
92+
// }

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,33 @@ test("should identify right angle (90°)", () => {
1212
// Case 2: Identify Acute Angles:
1313
// When the angle is less than 90 degrees,
1414
// Then the function should return "Acute angle"
15+
test("should identify acute angle (< 90°)", () => {
16+
expect(getAngleType(45)).toEqual("Acute angle");
17+
});
18+
// Case 2: identify Acute Angles, When the angle is less than 90 degrees, than the function should return "Acute angle".
1519

1620
// Case 3: Identify Obtuse Angles:
1721
// When the angle is greater than 90 degrees and less than 180 degrees,
1822
// Then the function should return "Obtuse angle"
23+
test("should identify obtuse angle (> 90° and < 180°)", () => {
24+
expect(getAngleType(120)).toEqual("Obtuse angle");
25+
});
26+
// Case 3: identify Obtuse Angles, When the angle is greater than 90 degrees and less than 180 degrees, than the function should return "Obtuse Angle".
27+
1928

2029
// Case 4: Identify Straight Angles:
2130
// When the angle is exactly 180 degrees,
2231
// Then the function should return "Straight angle"
32+
test("should identify straight angle (180°)", () => {
33+
expect(getAngleType(180)).toEqual("Straight angle");
34+
});
35+
// Case 4: identify Straight Angles, When the angle is exactly 180 degrees, than the function should return "Straight angle".
2336

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+
test("should identify reflex angle (> 180° and < 360°)", () => {
41+
expect(getAngleType(270)).toEqual("Reflex angle");
42+
});
43+
// Case 5: identify Reflex Angles, When the angle is greater than 180 degrees and less than 360 degrees, the function should return "Reflex Angle".
44+

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ test("should return true for a proper fraction", () => {
77
});
88

99
// Case 2: Identify Improper Fractions:
10+
est("should return false for improper fractions", () => {
11+
const improperFraction = isProperFraction(5, 2);
12+
expect(improperFraction).toEqual(false);
13+
});
1014

1115
// Case 3: Identify Negative Fractions:
16+
test("should return true for negative fractions", () => {
17+
const negativeFraction = isProperFraction(-4, 7);
18+
expect(negativeFraction).toEqual(true);
19+
});
20+
1221

1322
// Case 4: Identify Equal Numerator and Denominator:
23+
test("should return false for equal numerator and denominator", () => {
24+
const equalFraction = isProperFraction(3, 3);
25+
expect(equalFraction).toEqual(false);
26+
});
27+

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,58 @@
22
// We will use the same function, but write tests for it using Jest in this file.
33
const getCardValue = require("../implement/3-get-card-value");
44

5+
6+
// Case 4: Handle Ace (A):
57
test("should return 11 for Ace of Spades", () => {
68
const aceofSpades = getCardValue("A♠");
79
expect(aceofSpades).toEqual(11);
810
});
911

1012
// Case 2: Handle Number Cards (2-10):
13+
test("should return correct values for number cards", () => {
14+
expect(getCardValue("5♥")).toEqual(5);
15+
expect(getCardValue("10♦")).toEqual(10);
16+
});
17+
18+
1119
// Case 3: Handle Face Cards (J, Q, K):
12-
// Case 4: Handle Ace (A):
20+
test("should return for face cards J, Q, K", () => {
21+
expect(getCardValue("J♣")).toEqual(10);
22+
expect(getCardValue("Q♦")).toEqual(10);
23+
expect(getCardValue("K♠")).toEqual(10);
24+
});
25+
26+
27+
1328
// Case 5: Handle Invalid Cards:
29+
test("throws an error or invalid card", () => {
30+
expect(() => getCardValue("Z♠")).toThrow("Invalid card");
31+
});
32+
33+
test("should throw error for malformed numeric input", () => {
34+
expect(() => getCardValue("2.9999♠")).toThrow("Invalid card rank");
35+
});
36+
37+
test("should throw error for repeated characters in rank", () => {
38+
expect(() => getCardValue("3AAAA♠")).toThrow("Invalid card rank");
39+
});
40+
41+
test("should throw error for number beyond valid range", () => {
42+
expect(() => getCardValue("11♠")).toThrow("Invalid card rank");
43+
});
44+
45+
test("should throw error for missing suit", () => {
46+
expect(() => getCardValue("Q")).toThrow("Invalid card rank");
47+
});
48+
49+
test("should throw error for non-string input", () => {
50+
expect(() => getCardValue(5)).toThrow("Card must be a string");
51+
});
52+
53+
// try {
54+
// getCardValue("Z♠");
55+
//} catch (error) {
56+
// console.log("Caught error:", error.message);
57+
//}
58+
59+

Sprint-3/1-key-implement/1-get-angle-type.js

Whitespace-only changes.

Sprint-3/2-practice-tdd/count.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0; // start a count with 0
3+
for (let char of stringOfCharacters) {
4+
// repeat for each character in the string
5+
if (char === findCharacter) {
6+
// check if the character matches the one we are looking for.
7+
count++; // if it does increase the count by 1.
8+
}
9+
}
10+
11+
return count;
12+
313
}
14+
console.log(countChar("aAaAaAaAa", "a")); // example usage should return 5.
415

516
module.exports = countChar;
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
let ord = "th";
3+
4+
if (n % 10 == 1 && n % 100 != 11) {
5+
ord = "st";
6+
} else if (n % 10 == 2 && n % 100 != 12) {
7+
ord = "nd";
8+
} else if (n % 10 == 3 && n % 100 != 13) {
9+
ord = "rd";
10+
}
11+
12+
return n + ord;
313
}
14+
console.log(getOrdinalNumber(1)); // The output should be "1st"
15+
16+
// in this function, we got the ordinal number for 1.
17+
// we used a simple if statement to check if the number is 1 and return "1st".
18+
419

520
module.exports = getOrdinalNumber;

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@ const getOrdinalNumber = require("./get-ordinal-number");
88
// When the number is 1,
99
// Then the function should return "1st"
1010

11-
test("should return '1st' for 1", () => {
11+
12+
test("append 'st' to numbers ending in 1, except those ending in 11", () => {
1213
expect(getOrdinalNumber(1)).toEqual("1st");
14+
expect(getOrdinalNumber(21)).toEqual("21st");
15+
expect(getOrdinalNumber(121)).toEqual("121st");
16+
});
17+
18+
test("appends 'nd' to numbers ending in 2, except those ending in 12", () => {
19+
expect(getOrdinalNumber(2)).toEqual("2nd");
20+
expect(getOrdinalNumber(22)).toEqual("22nd");
21+
});
22+
23+
test("appends 'rd' to numbers ending in 3, except those ending in 13", () => {
24+
expect(getOrdinalNumber(3)).toEqual("3rd");
25+
expect(getOrdinalNumber(23)).toEqual("23rd");
1326
});
27+
28+
test("appends 'th' to numbers ending in 11, 12, or 13 and all others not ending in 1, 2, or 3", () => {
29+
expect(getOrdinalNumber(11)).toEqual("11th");
30+
expect(getOrdinalNumber(12)).toEqual("12th");
31+
expect(getOrdinalNumber(13)).toEqual("13th");
32+
expect(getOrdinalNumber(111)).toEqual("111th");
33+
expect(getOrdinalNumber(112)).toEqual("112th");
34+
expect(getOrdinalNumber(113)).toEqual("113th");
35+
36+
//general `th` cases
37+
38+
expect(getOrdinalNumber(0)).toEqual("0th");
39+
expect(getOrdinalNumber(4)).toEqual("4th");
40+
expect(getOrdinalNumber(10)).toEqual("10th");
41+
expect(getOrdinalNumber(24)).toEqual("24th");
42+
expect(getOrdinalNumber(100)).toEqual("100th");
43+
expect(getOrdinalNumber(104)).toEqual("104th");
44+
});
45+
46+
test("handles edge cases for higher numbers", () => {
47+
expect(getOrdinalNumber(1011)).toEqual("1011th");
48+
expect(getOrdinalNumber(1012)).toEqual("1012th");
49+
expect(getOrdinalNumber(1013)).toEqual("1013th");
50+
expect(getOrdinalNumber(1021)).toEqual("1021st");
51+
expect(getOrdinalNumber(1022)).toEqual("1022nd");
52+
expect(getOrdinalNumber(1023)).toEqual("1023rd");
53+
});

Sprint-3/2-practice-tdd/implement/count.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)