Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9372367
applied angle tests
rivakutu Jun 5, 2025
a4fa235
added tests
rivakutu Jun 5, 2025
ea3b833
get card
rivakutu Jun 5, 2025
160782d
get angle completion
rivakutu Jun 5, 2025
03d4d32
get angle tests
rivakutu Jun 5, 2025
58113a5
is proper fraction complete
rivakutu Jun 5, 2025
02cc899
is proper fraction test complete
rivakutu Jun 5, 2025
d8c6e50
updated
rivakutu Jun 5, 2025
8541c1b
get-card tests completed
rivakutu Jun 5, 2025
300f27a
get card value completed
rivakutu Jun 5, 2025
234601f
count completed
rivakutu Jun 5, 2025
4c09bc3
count tests completed
rivakutu Jun 5, 2025
2a6afb4
get ordinal number completed
rivakutu Jun 5, 2025
ac4e3c5
get ordinal number test completed
rivakutu Jun 5, 2025
2f40b44
repeat completed
rivakutu Jun 5, 2025
a7f8489
repeat test completed
rivakutu Jun 5, 2025
4551545
card-validator implementation
rivakutu Jun 5, 2025
f5770e7
find questoions answered
rivakutu Jun 5, 2025
bd8522b
password validator completed
rivakutu Jun 5, 2025
c166bd1
password validator tests
rivakutu Jun 5, 2025
facd23d
added more expect statements to reflex angle and obtuse angle tests
rivakutu Jun 17, 2025
e77d856
made the function more simpler but robust
rivakutu Jun 17, 2025
badfd94
minor if statement appearing adjustment
rivakutu Jun 17, 2025
09ed00d
updated the test cases to mathematical correctness
rivakutu Jun 17, 2025
959cbed
fixed variable mismatch
rivakutu Jun 17, 2025
6130cd8
corrected test cases
rivakutu Jun 17, 2025
3b23fd2
updated function names to start with lower case
rivakutu Jun 17, 2025
934f970
explaining the importance of index++
rivakutu Jun 17, 2025
d70bd76
function names updated to match requirements
rivakutu Jun 17, 2025
a85bce4
added more robust testing. includes more edges cases and utilizes the…
rivakutu Jun 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 190) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
}

// we're going to use this helper function to make our assertions easier to read
Expand Down Expand Up @@ -44,13 +48,18 @@ assertEquals(acute, "Acute angle");
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(obtuse, "Obtuse angle");

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

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(190);
assertEquals(reflex, "Reflex angle");
15 changes: 14 additions & 1 deletion Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator < denominator) return true;
if (numerator > denominator) return false;
if (Math.abs(numerator) < denominator) return true;
if (numerator === denominator) return false;
if (denominator === 0) return false;
}

// here's our helper again
Expand Down Expand Up @@ -41,13 +45,22 @@ assertEquals(improperFraction, false);
// 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.
const negativeFraction = isProperFraction(-4, 7);
// ====> complete with your assertion
assertEquals(negativeFraction, true);

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

// Stretch:
// What other scenarios could you test for?
// Denominator not equal to 0 check
// input: numerator = 3, denominator = 0
// target output: false;
//Explanation: 3/0 causes is mathematically impossible

const zeroFraction = isProperFraction(3, 0);
assertEquals(zeroFraction, false);
12 changes: 10 additions & 2 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
// write one test at a time, and make it pass, build your solution up methodically
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers
function getCardValue(card) {
if (rank === "A") return 11;
if (rank === "A" || rank === "A♠") return 11;
if (rank === "10" || rank === "J" || rank === "K" || rank === "Q") return 10;
else return "Invalid card rank";
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -34,18 +36,24 @@ assertEquals(aceofSpades, 11);
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("5♥");
// ====> write your test here, and then add a line to pass the test in the function above
assertEquals(fiveofHearts, 5);

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

// Handle Ace (A):
// Given a card with a rank of "A",
// When the function is called with an Ace,
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack.

const Acards = getCardValue("A");
assertEquals(Acards, 11);
// Handle Invalid Cards:
// Given a card with an invalid rank (neither a number nor a recognized face card),
// When the function is called with such a card,
// Then it should throw an error indicating "Invalid card rank."
const InvalidCards = getCardValue("22");
assertEquals(InvalidCards, "Invalid card rank");
16 changes: 6 additions & 10 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// replace with your completed function from key-implement

if (angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
}








// Don't get bogged down in this detail
// Jest uses CommonJS module syntax by default as it's quite old
// We will upgrade our approach to ES6 modules in the next course module, so for now
// We will upgrade our approach to ES6 modules in the next course module, so for now
// we have just written the CommonJS module.exports syntax for you
module.exports = getAngleType;
module.exports = getAngleType;
16 changes: 16 additions & 0 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ test("should identify right angle (90°)", () => {
// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
test("should identify Acute angle(45)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
});

// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
test("should identify Obtuse angle", () => {
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(170)).toEqual("Obtuse angle");
expect(getAngleType(105)).toEqual("Obtuse angle");
});

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
test("should identify Straight angle", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
test("should identify Reflex angle", () => {
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359.999)).toEqual("Reflex angle");
expect(getAngleType(270)).toEqual("Reflex angle");
});
10 changes: 7 additions & 3 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
if (denominator === 0) {
throw new Error("Denominator cannot be 0");
}
const absoluteNumerator = Math.abs(numerator);
const absoluteDenominator = Math.abs(denominator);
return absoluteNumerator < absoluteDenominator;
}

module.exports = isProperFraction;
module.exports = isProperFraction;
18 changes: 14 additions & 4 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const isProperFraction = require("./2-is-proper-fraction");

//testing for proper fractions
test("should return true for a proper fraction", () => {
expect(isProperFraction(2, 3)).toEqual(true);
expect(isProperFraction(-2, 3)).toEqual(true);
expect(isProperFraction(2, -3)).toEqual(true);
});

// Case 2: Identify Improper Fractions:

// Case 3: Identify Negative Fractions:
//testing for zero denominator
test("should throw error for denominator zero", () => {
expect(() => isProperFraction(3, 0)).toThrow("Denominator cannot be 0");
});

// Case 4: Identify Equal Numerator and Denominator:
// testing for negative fractions
test("should correctly handle negative fractions", () => {
expect(isProperFraction(-2, -3)).toEqual(true);
expect(isProperFraction(-3, -2)).toEqual(false);
expect(isProperFraction(-3, 2)).toEqual(false);
expect(isProperFraction(3, -2)).toEqual(false);
});
36 changes: 32 additions & 4 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
function getCardValue(rank) {
if (typeof rank !== "string" || rank.length < 2) {
throw new Error("Invalid card format");
}

const card = rank.slice(0, -1); // removing last character to get card rank
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

card is the name of the original parameter and is supposed to include both the rank and the suit of a card.
rank is part without the suit.

// array of valid ranks
const validRanks = [
"A",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"J",
"Q",
"K",
];
// actual values of ranks in respective order
const rankValues = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10];
const index = validRanks.indexOf(card); // getting a rank
if (index !== -1) {
// if index rank actually exists return the rankValue
return rankValues[index];
} else {
throw new Error("Invalid card rank");
}
}
module.exports = getCardValue;
module.exports = getCardValue;
23 changes: 19 additions & 4 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
const getCardValue = require("./3-get-card-value");

test("should return 11 for Ace of Spades", () => {
const aceofSpades = getCardValue("A♠");
expect(aceofSpades).toEqual(11);
});
test("should return 11 for Ace of Spade", () => {
expect(getCardValue("A♠")).toEqual(11);
});

// Case 2: Handle Number Cards (2-10):
test("should handle number cards", () => {
expect(getCardValue("3♥")).toEqual(3);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♦")).toEqual(10);
});
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for face cards", () => {
expect(getCardValue("J♥")).toEqual(10);
expect(getCardValue("Q♠")).toEqual(10);
expect(getCardValue("K♥")).toEqual(10);
});
// Case 4: Handle Ace (A):
test("should return 11 for Ace cards", () => {
expect(getCardValue("A♥")).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should throw error for invalid cards", () => {
expect(() => getCardValue("22♦")).toThrow("Invalid card rank");
});
4 changes: 2 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
return stringOfCharacters.split(findCharacter).length - 1;
}

module.exports = countChar;
module.exports = countChar;
6 changes: 6 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
test("should check for no occurrence characters", () => {
const str = "aaaaa";
const char = "b";
const count = countChar(str, char);
expect(count).toEqual(0);
});
7 changes: 5 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function getOrdinalNumber(num) {
return "1st";
if (num === 1) return "1st";
if (num === 2) return "2nd";
if (num === 3) return "3rd";
if (num === 4) return "4th";
Comment on lines +2 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrdinalNumber(11) should return "11th", and getOrdinalNumber(101) should return "101st".
You might consider looking up the rules online or asking an AI tool to clarify how ordinal numbers are formed.

}

module.exports = getOrdinalNumber;
module.exports = getOrdinalNumber;
25 changes: 23 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,26 @@ const getOrdinalNumber = require("./get-ordinal-number");
// Then the function should return "1st"

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

// Case 2: Identify the ordinal number for 2
// when the number is 2
// Then the function should return "2nd"
test("should return '2nd' for 2", () => {
expect(getOrdinalNumber(2)).toEqual("2nd");
});

//Case 3: Identify the ordinal number of 3
// when the number is 3
// Then the function should return "3rd"
test("should return '3rd' for 3", () => {
expect(getOrdinalNumber(3)).toEqual("3rd");
});

//Case 4: Identify the ordinal number of 4
// when the number is 4
// Then the function should return "4th"
test("should return '4th'for 4", () => {
expect(getOrdinalNumber(4)).toEqual("4th");
});
8 changes: 5 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function repeat() {
return "hellohellohello";
function repeat(str, count) {
if (str === "") return "Input string is empty!";
if (count < 0) return "Invalid count value";
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why give an empty string special treatment?

  2. How would the caller distinguish the result of the following two function calls?

  • repeat("Invalid count value", 1)
  • repeat("abc", -1)
    Both function calls return the same value.

return str.repeat(count);
}

module.exports = repeat;
module.exports = repeat;
28 changes: 23 additions & 5 deletions Sprint-3/3-mandatory-practice/implement/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,41 @@ const repeat = require("./repeat");
// Then it should repeat the str count times and return a new string containing the repeated str values.

test("should repeat the string count times", () => {
const str = "hello";
const count = 3;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hellohellohello");
});
const str = "hello";
const count = 3;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hellohellohello");
});

// case: handle Count of 1:
// Given a target string str and a count equal to 1,
// When the repeat function is called with these inputs,
// Then it should return the original str without repetition, ensuring that a count of 1 results in no repetition.
test("should repeat the string 1 time", () => {
const str = "hello";
const count = 1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("hello");
});

// case: Handle Count of 0:
// Given a target string str and a count equal to 0,
// When the repeat function is called with these inputs,
// Then it should return an empty string, ensuring that a count of 0 results in an empty output.
test("should return empty string when count is 0", () => {
const str = "hello";
const count = 0;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("");
});

// case: Negative Count:
// Given a target string str and a negative integer count,
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
test("should throw negative counts not valid", () => {
const str = "hello";
const count = -1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual("Invalid count value");
});
Loading