Skip to content

Glasgow | Mansoor Munawar | Structuring and Testing Data | Sprint 3 #662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cf4537d
created getAngleTpe and assertion function
MansoorM11 Jul 11, 2025
7835f78
created isProperfraction function and added tests for it
MansoorM11 Jul 11, 2025
d157d6a
implemented getCard function and created test for it
MansoorM11 Jul 11, 2025
17c240e
added jest to main directory and createted test with jest for angle t…
MansoorM11 Jul 14, 2025
9aab60a
added code for getAngly function to identify straight angle and creat…
MansoorM11 Jul 14, 2025
833720c
created test to identify straight angle and reflex angle using jest
MansoorM11 Jul 14, 2025
790e134
created test using jest for is proper fractions
MansoorM11 Jul 14, 2025
f0a954a
fixed some bugs in the code and fixed variable names for easier reada…
MansoorM11 Jul 14, 2025
2456dd3
created test for card value function using jest
MansoorM11 Jul 14, 2025
ab4d3f3
created function for countChar and created test for it using jest
MansoorM11 Jul 14, 2025
a73c5dd
created formula for getOrdinalNumber function
MansoorM11 Jul 16, 2025
c72f1cb
created test for getOrdinal number function using Jest
MansoorM11 Jul 16, 2025
668ca1f
created a repeat function in JavaScript
MansoorM11 Jul 16, 2025
45fecfe
added two more test for repeat function using Jest
MansoorM11 Jul 16, 2025
b1775b2
added functionality for repeat function that takes into account negat…
MansoorM11 Jul 16, 2025
dc1663b
added a test for repeat function which checks for negative values
MansoorM11 Jul 16, 2025
2f3e10c
fixed a typo within a test
MansoorM11 Jul 17, 2025
5f9ef73
refactor my if-statement for better readability
MansoorM11 Jul 18, 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
17 changes: 12 additions & 5 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";
else if (angle < 90) return "Acute angle";
else if (angle > 90 && angle < 180) return "Obtuse angle";
else if (angle > 180 && angle < 360) return "Reflex angle";
else if (angle === 180) return "Straight angle";
// read to the end, complete line 36, then pass your test here
}

// we're going to use this helper function to make our assertions easier to read
Expand Down Expand Up @@ -44,13 +48,16 @@ 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:
const reflex = getAngleType(181);
assertEquals(reflex, "Reflex angle");
// 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
19 changes: 15 additions & 4 deletions 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,10 @@
// 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 (Math.abs(numerator) < Math.abs(denominator)) return true;
else if (numerator === denominator) return false;
else if (numerator > denominator) return false;
else return false;
}

Choose a reason for hiding this comment

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

Can you see any way you could combine these 3 return false conditions into one line?


// here's our helper again
Expand Down Expand Up @@ -39,15 +42,23 @@ assertEquals(improperFraction, false);
// Input: numerator = -4, denominator = 7
// target output: true
// 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);
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?

// Negative Fraction check:
// Input: numerator = -4, denominator = -7
// target output: true
// Explanation: The fraction -4/-7 is a proper fraction because the absolute value of the numerator (4) is less than the absolute value of denominator (7). The function should return true.
const negativeDenominator = isProperFraction(-4, -7);

assertEquals(negativeDenominator, true);
26 changes: 19 additions & 7 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,13 @@
// 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;
let rank = card.slice(0, -1);

if (rank === "A") return 11;
else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10")
return 10;
else if (Number(rank) >= 2 && Number(rank) <= 9) return Number(rank);
else return "Invalid card rank.";
}

// You need to write assertions for your function to check it works in different cases
Expand All @@ -25,27 +31,33 @@ function assertEquals(actualOutput, targetOutput) {
// 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),
// When the function getCardValue is called with this card string as input,
// Then it should return the numerical card value
const aceofSpades = getCardValue("A♠");
assertEquals(aceofSpades, 11);
const aceOfSpades = getCardValue("A♠");
assertEquals(aceOfSpades, 11);

// Handle Number Cards (2-10):
// Given a card with a rank between "2" and "9",
// When the function is called with such a card,
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5).
const fiveofHearts = getCardValue("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 kingOfHearts = getCardValue("K♥");
assertEquals(kingOfHearts, 10);
const tenOfHearts = getCardValue("10♥");
assertEquals(tenOfHearts, 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 aceOfHearts = getCardValue("A♥");
assertEquals(aceOfHearts, 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 invalidCard = getCardValue("S");
assertEquals(invalidCard, "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

else if (angle < 90) return "Acute angle";
else if (angle > 90 && angle < 180) return "Obtuse angle";
else if (angle > 180 && angle < 360) return "Reflex angle";
else if (angle === 180) return "Straight 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;
15 changes: 12 additions & 3 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,24 @@ 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 actute angle (55°)", () => {
expect(getAngleType(55)).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 (95°)", () => {
expect(getAngleType(95)).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 (180°)", () => {
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 Reflext angle (200°))", () => {
expect(getAngleType(200)).toEqual("Reflex angle");
});
6 changes: 3 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,6 @@
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
if (Math.abs(numerator) < Math.abs(denominator)) return true;
else return false;
}

module.exports = isProperFraction;
module.exports = isProperFraction;
17 changes: 15 additions & 2 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ test("should return true for a proper fraction", () => {
});

// Case 2: Identify Improper Fractions:

test("should return flase for inproper fraction", () => {
expect(isProperFraction(256, 40)).toEqual(false);
});
test("should return flase for inproper fraction", () => {
expect(isProperFraction(8, 4)).toEqual(false);
});
// Case 3: Identify Negative Fractions:

test("should return true for negative fraction (-2,4)", () => {
expect(isProperFraction(-2, 4)).toEqual(true);
});
test("should return false for negative fraction (-10,-4)", () => {
expect(isProperFraction(-10, -4)).toEqual(false);
});
// Case 4: Identify Equal Numerator and Denominator:
test("should return flase for inproper fraction", () => {
expect(isProperFraction(3, 3)).toEqual(false);
});
12 changes: 9 additions & 3 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function getCardValue(card) {
// replace with your code from key-implement
return 11;
// replace with your code from key-implement
let rank = card.slice(0, -1);

if (rank === "A") return 11;
else if (rank === "K" || rank === "Q" || rank === "J" || rank === "10")
return 10;
else if (Number(rank) >= 2 && Number(rank) <= 9) return Number(rank);
else return "Invalid card rank.";
}
module.exports = getCardValue;
module.exports = getCardValue;
30 changes: 27 additions & 3 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,35 @@
const getCardValue = require("./3-get-card-value");

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

// Case 2: Handle Number Cards (2-10):
test("should return 10 for 10 of Hearts", () => {
const tenOfHearts = getCardValue("10♥");
expect(tenOfHearts).toEqual(10);
});
test("should return 5 for 10 of Spades", () => {
const fiveOfHearts = getCardValue("5♠");
expect(fiveOfHearts).toEqual(5);
});
// Case 3: Handle Face Cards (J, Q, K):
test("should return 10 for Kings of Spades", () => {
const tenOfHearts = getCardValue("K♠");
expect(tenOfHearts).toEqual(10);
});
test("should return 10 for Queen of Hearts", () => {
const queenOfHearts = getCardValue("Q♥");
expect(queenOfHearts).toEqual(10);
});
// Case 4: Handle Ace (A):
test("should return 11 for Ace of Hearts", () => {
const AceOfHearts = getCardValue("A♥");
expect(AceOfHearts).toEqual(11);
});
// Case 5: Handle Invalid Cards:
test("should return Invalid Card for letters", () => {
const AceOfHearts = getCardValue("SS");
expect(AceOfHearts).toEqual("Invalid card rank.");
});
10 changes: 8 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/count.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
function countChar(stringOfCharacters, findCharacter) {
return 5
let occurance = 0;
for (const letter of stringOfCharacters) {
if (findCharacter === letter) {
occurance++;
}
}
return occurance;
}

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 count zero occurrences of a character", () => {
const str = "aaaaa";
const char = "b";
const count = countChar(str, char);
expect(count).toEqual(0);
});
13 changes: 11 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,14 @@
function getOrdinalNumber(num) {
return "1st";
let lastTwoNumber = num % 100;
if (lastTwoNumber === 11 || lastTwoNumber === 12 || lastTwoNumber === 13)
return `${num}th`;
let lastDigit = num % 10;
if (lastDigit === 1) return `${num}st`;
else if (lastDigit === 2) return `${num}nd`;
else if (lastDigit === 3) return `${num}rd`;
else return `${num}th`;
}

module.exports = getOrdinalNumber;
console.log(getOrdinalNumber(100));

module.exports = getOrdinalNumber;
20 changes: 18 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,21 @@ 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");
});

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

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

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

test("should return '21st' for 21", () => {
expect(getOrdinalNumber(21)).toEqual("21st");
});
11 changes: 8 additions & 3 deletions Sprint-3/3-mandatory-practice/implement/repeat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
function repeat() {
return "hellohellohello";
function repeat(str, count) {
if (count < 0) {
return "Negative numbers are not accepted";
}
return str.repeat(count);
}

module.exports = repeat;
console.log(repeat("hello", -100));
console.log(repeat("hell0", 0));
module.exports = repeat;
Loading