-
-
Notifications
You must be signed in to change notification settings - Fork 196
West Midland | ITP-May-2025 | Saleh Yousef | Module-Structuring-and-Testing-Data | sprint 3 #601
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 21 commits
3856c49
6e565c2
ca705a4
5c55f19
c62f6d2
00efebb
5bb2de5
8e56555
9e470f2
4882807
a8e8735
c041ee4
dc54439
f6db2fa
af76630
f349caa
2f6b738
ab2284b
826d8c1
4f3c922
d39457e
aba4df6
4ce219b
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,18 +1,16 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
if (angle <= 0 || angle >= 360) return "Invalid angle"; | ||
if (angle === 90) return "Right angle"; | ||
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 have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
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 zero."); | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
// here's our helper again | ||
function assertEquals(actualOutput, targetOutput) { | ||
console.assert( | ||
actualOutput === targetOutput, | ||
`Expected ${actualOutput} to equal ${targetOutput}` | ||
); | ||
} | ||
|
||
// Proper Fraction check: | ||
const properFraction = isProperFraction(2, 3); | ||
assertEquals(properFraction, true); | ||
|
||
// Improper Fraction check: | ||
const improperFraction = isProperFraction(5, 2); | ||
assertEquals(improperFraction, false); | ||
|
||
// Negative Fraction check: | ||
const negativeFraction = isProperFraction(-4, 7); | ||
assertEquals(negativeFraction, true); | ||
|
||
// Equal Numerator and Denominator check: | ||
const equalFraction = isProperFraction(3, 3); | ||
assertEquals(equalFraction, false); | ||
|
||
// Negative Denominator check: | ||
const negativeDenominator = isProperFraction(0, -3); | ||
assertEquals(negativeDenominator, true); | ||
|
||
|
||
|
||
|
||
module.exports = isProperFraction; |
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; | ||
const rank = card.slice(0, -1); | ||
|
||
if (rank === "A") return 11; | ||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
const num = Number(rank); | ||
if (num >= 2 && num <= 9) return num; | ||
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. In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "00_02". Does your function return the value you expected from each of the following function calls?
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. fixed, the earlier function had loose logic. |
||
|
||
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,32 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
expect(getCardValue("A♠")).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return 5 for Five of Hearts", () => { | ||
expect(getCardValue("5♥")).toEqual(5); | ||
expect(getCardValue("3♣")).toEqual(3); | ||
expect(getCardValue("4♦")).toEqual(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. The test description does not quite match the values being tested. 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’ve fixed the description so it matches the actual test values now. Thank you |
||
test('returns 10 for Ten of Diamonds', () => { | ||
expect(getCardValue('10♦')).toEqual(10); | ||
}); | ||
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
// Case 4: Handle Ace (A): | ||
// Case 5: Handle Invalid Cards: | ||
test.each(["K♣", "Q♦", "J♥"])( | ||
'returns 10 for %s', | ||
(card) => { | ||
expect(getCardValue(card)).toEqual(10); | ||
}); | ||
|
||
// Case 4: Handle Invalid Cards: | ||
test("should throw an error for invalid card rank", () => { | ||
expect(() => getCardValue("Z♣")).toThrow("Invalid card rank."); | ||
}); | ||
test("should throw an error for invalid card rank", () => { | ||
expect(() => getCardValue("11♠")).toThrow("Invalid card rank."); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let count = 0; | ||
for (let char of stringOfCharacters) { | ||
if (char === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
module.exports = countChar; | ||
module.exports = countChar;node |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
const lastTwo = num % 100; | ||
if (lastTwo >= 11 && lastTwo <= 13) { | ||
return num + "th"; | ||
} | ||
const last = num % 10; | ||
if (last === 1) return num + "st"; | ||
if (last === 2) return num + "nd"; | ||
if (last === 3) return num + "rd"; | ||
return num + "th"; | ||
} | ||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if (count < 0) throw new Error("Count must be non-negative"); | ||
return str.repeat(count); | ||
} | ||
|
||
module.exports = repeat; |
Uh oh!
There was an error while loading. Please reload this page.