-
-
Notifications
You must be signed in to change notification settings - Fork 195
SA|ITP MAY 2025|INNOCENT NIWATWINE| Structuring and Data Testing| Sprint 3 #635
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
dc1f406
f6ce63f
baa47b4
a4f694b
587adda
e2b4873
1596344
a83f08e
507b947
d97db43
9b5d41f
e8b4dfe
4b2bd59
b74d0a0
b6dfb6a
5812f25
99aeed5
37729c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,15 @@ | |
// 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; | ||
} else if (numerator >= denominator) { | ||
return false; | ||
} else if (numerator === 1) { | ||
return true; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this solution work for negative improper fractions, like -7/4? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could not because i found out what i did only checks numerator>=denominator and it didnt include the negative improper fractions ,i have tried to correct it, Thank you |
||
} | ||
|
||
|
||
// here's our helper again | ||
function assertEquals(actualOutput, targetOutput) { | ||
|
@@ -39,15 +46,19 @@ 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); | ||
// ====> 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? | ||
const unitFraction = isProperFraction(1, 9); | ||
assertEquals(unitFraction, true); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (numerator >= denominator) return false; | ||
// add your completed function from key-implement here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you are checking a condition which will give a true or false value, and you are then returning the same true or false value. Can you see a way to rewrite this that would simplify the function? |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const faceCards = ["10", "J", "Q", "K"]; | ||
const rank = card.slice(0, -1); | ||
if (rank === "A") return 11; | ||
if (!isNaN(rank) && Number(rank) >= 2 && Number(rank) <= 9) | ||
return Number(rank); | ||
if (faceCards.includes(rank)) return 10; | ||
throw new Error("Invalid card rank"); | ||
} | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
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 the number value of Number cards", () => { | ||
const numberCards = getCardValue("3♦"); | ||
expect(numberCards).toEqual(3); | ||
}); | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for Face cards", () => { | ||
const faceCards = getCardValue("Q♣"); | ||
expect(faceCards).toEqual(10); | ||
}); | ||
|
||
// Case 4: Handle Ace (A): | ||
test("should return 11 for Ace cards", () => { | ||
const aceCards = getCardValue("A♣"); | ||
expect(aceCards).toEqual(11); | ||
}); | ||
// Case 5: Handle Invalid Cards: | ||
test("should return Invalid card rank for Invalid cards", () => { | ||
expect(() => { | ||
getCardValue("Z♥"); | ||
}).toThrow("Invalid card rank"); | ||
}); |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
} | ||
const lastDigits = num % 10; | ||
const lastTwoDigits = num % 100; | ||
|
||
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) return num + "th"; | ||
if (lastDigits === 1) { | ||
return num + "st"; | ||
} else if (lastDigits === 2) { | ||
return num + "nd"; | ||
} else if (lastDigits === 3) { | ||
return num + "rd"; | ||
} else { | ||
return num + "th"; | ||
} | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
} | ||
|
||
function repeat(str, count) { | ||
if (count === 0) return ""; | ||
if (count < 0) { | ||
throw new Error("Not Allowed"); | ||
} else { | ||
return str.repeat(count); | ||
} | ||
} | ||
module.exports = repeat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to have the same condition twice here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right i don't need to have the same condition twice because it is kind of duplication since the first condition already returns if that condition is true.I will proceed to remove ''else if'', thank you