-
-
Notifications
You must be signed in to change notification settings - Fork 195
London | May-2025 | Fatima_Zohra_Belkedari | Module Structuring and Testing Data | Sprint. 3 #629
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 all commits
696bb42
4cc5106
22cab74
ed21e9d
4d9bc3b
8f7c8a6
27e36c5
a97c923
cc9d7dc
bfee299
8f9221a
d6a385f
0c51d93
9c6607c
da6f74f
b15ce67
401a0d1
d25287f
ea3514b
22db2cc
77294d9
6c4aa13
b0c9c31
3000184
96eb260
19e006e
037bc34
535e4ba
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
const isProperFraction = require("./2-is-proper-fraction"); | ||
|
||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(2, 3)).toEqual(true); | ||
|
||
test("should return false for improper fraction (5/2)", () => { | ||
expect(isProperFraction(5, 2)).toEqual(false); | ||
}); | ||
|
||
|
||
test("should return true for negative proper fraction (-4/7)", () => { | ||
expect(isProperFraction(-4, 7)).toEqual(true); | ||
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
|
||
// Case 3: Identify Negative Fractions: | ||
test("should return false for equal numerator and denominator (3/3)", () => { | ||
expect(isProperFraction(3, 3)).toEqual(false); | ||
}); | ||
|
||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
test("should return true for both negative proper fraction (-8/-10)", () => { | ||
expect(isProperFraction(-8, -10)).toEqual(true); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); | ||
|
||
if (rank === "A") return 11; | ||
if (["J", "Q", "K"].includes(rank)) return 10; | ||
|
||
if (/^(10|[2-9])$/.test(rank)) { | ||
return Number(rank); | ||
} | ||
throw new Error("Invalid card rank"); | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return number for number cards (2-10)",() => { | ||
expect(getCardValue("2♠")).toEqual (2); | ||
expect(getCardValue("10♣")).toEqual(10); | ||
}); | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for face cards J, Q, K", () => { | ||
["J", "Q", "K"].forEach(rank => { | ||
expect(getCardValue (`${rank}♦`)).toEqual(10); | ||
}); | ||
}); | ||
|
||
|
||
|
||
// Case 4: Handle Ace (A): | ||
test("should return 11 for Ace", () => { | ||
expect(getCardValue("A♦")).toEqual(11); | ||
}); | ||
|
||
// Case 5: Handle Invalid Cards: | ||
test("should throw error for invalid card rank", () => { | ||
expect(() => getCardValue("L")).toThrow(new Error("Invalid card rank")); | ||
}); | ||
|
||
// Case 6: should throw error for invalid numeric format: | ||
test("should throw error for invalid numeric format", () => { | ||
expect(() => getCardValue("0x02♠")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("2.1♠")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("2♠♠")).toThrow("Invalid card rank"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let count = 0; | ||
for (let i = 0; i < stringOfCharacters.length; i++) { | ||
if (stringOfCharacters[i] === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
const strNum= num.toString(); | ||
if(strNum.slice(-2)==="11") { | ||
return strNum + "th"; | ||
} | ||
if(strNum.slice(-2)==="12") { | ||
return strNum + "th"; | ||
} | ||
if(strNum.slice(-2)==="13") { | ||
return strNum + "th"; | ||
} | ||
if(strNum.slice(-1)==="1") { | ||
return strNum + "st"; | ||
} | ||
if(strNum.slice(-1)==="2") { | ||
return strNum + "nd"; | ||
} | ||
if(strNum.slice(-1)==="3") { | ||
return strNum + "rd"; | ||
} | ||
|
||
Comment on lines
+2
to
+21
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.
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. If we use the number%10 we will get the last digit. In this case : 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. What does your function return when 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. number will return the remainder 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. 10 % 10 = 0 |
||
} | ||
|
||
module.exports = getOrdinalNumber; | ||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,26 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
// When the number is 1, | ||
// Then the function should return "1st" | ||
|
||
test("should return '1st' for 1", () => { | ||
test("append 'st' to numbers ending in 1" , () => { | ||
expect(getOrdinalNumber(1)).toEqual("1st"); | ||
expect(getOrdinalNumber(21)).toEqual("21st"); | ||
expect(getOrdinalNumber(121)).toEqual("121st"); | ||
}); | ||
|
||
test("append 'nd' to numbers ending in 2, except those ending in 12", () => { | ||
expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
expect(getOrdinalNumber(132)).toEqual("132nd"); | ||
}); | ||
|
||
test("append 'rd' to numbers ending in 3 , except those ending in 13", () => { | ||
expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
expect(getOrdinalNumber(13)).toEqual("13th"); | ||
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. "except those ending in 13". Numbers ending in 12, and 13 could be placed together with numbers ending in 11 in the same category. |
||
expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
}); | ||
|
||
test("should return '11th' for 11 , 12, 13", () => { | ||
expect(getOrdinalNumber(11)).toEqual("11th"); | ||
expect(getOrdinalNumber(12)).toEqual("12th"); | ||
expect(getOrdinalNumber(13)).toEqual("13th"); | ||
}); | ||
Comment on lines
+28
to
+33
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. Can you include this test to the script and then check if your function can pass this test:
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. I applied this code and when I run the code it failed. But other codes they run properly . |
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){ | ||
throw new Error("throw an error as negative counts are not valid"); | ||
} | ||
return str.repeat(count); | ||
} | ||
|
||
module.exports = repeat; | ||
|
||
module.exports = repeat; |
Uh oh!
There was an error while loading. Please reload this page.