generated from CodeYourFuture/Module-Template
-
-
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
Open
SalehOmar-Y
wants to merge
23
commits into
CodeYourFuture:main
Choose a base branch
from
SalehOmar-Y:coursework/sprint-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3856c49
new file: prep/Variables
SalehOmar-Y 6e565c2
new file
SalehOmar-Y ca705a4
Implement angle type identification in getAngleType function
5c55f19
Add assertions for negative fractions and equal numerator/denominator…
c62f6d2
Refactor getCardValue function to correctly return card values and up…
00efebb
Refactor isProperFraction function for clarity and accuracy; enhance …
5bb2de5
completed 2-mandatory-rewrite
8e56555
Implement countChar function to accurately count character occurrence…
9e470f2
repeat.test.js completed
4882807
Update 1-get-angle-type.js
SalehOmar-Y a8e8735
Update get-ordinal-number.test.js
SalehOmar-Y c041ee4
Update repeat.test.js
SalehOmar-Y dc54439
Update 3-get-card-value.test.js
SalehOmar-Y f6db2fa
Update 3-get-card-value.test.js
SalehOmar-Y af76630
Update count.test.js
SalehOmar-Y f349caa
Update count.test.js
SalehOmar-Y 2f6b738
Update 3-get-card-value.js
SalehOmar-Y ab2284b
Update 1-get-angle-type.test.js
SalehOmar-Y 826d8c1
Update repeat.test.js
SalehOmar-Y 4f3c922
Update get-ordinal-number.test.js
SalehOmar-Y d39457e
Update count.test.js
SalehOmar-Y aba4df6
Update 3-get-card-value.test.js
SalehOmar-Y 4ce219b
Refactor code structure for improved readability and maintainability
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule Project-CLI-Treasure-Hunt
added at
7cc7f5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 rank = card.slice(0, -1); | ||
|
||
if (rank === "A") return 11; | ||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
if (/^[2-9]$/.test(rank)) return Number (rank); | ||
|
||
throw new Error("Invalid card rank."); | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,43 @@ | ||
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 correct numeric value for number cards", () => { | ||
expect(getCardValue("5♥")).toEqual(5); | ||
expect(getCardValue("3♣")).toEqual(3); | ||
expect(getCardValue("4♦")).toEqual(4); | ||
|
||
|
||
}); | ||
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."); | ||
}); | ||
|
||
|
||
test("should throw an error for hex literal rank", () => { | ||
expect(() => getCardValue("0x02♠")).toThrow("Invalid card rank."); | ||
}); | ||
test("should throw an error for float rank", () => { | ||
expect(() => getCardValue("2.1♠")).toThrow("Invalid card rank."); | ||
}); | ||
test("should throw an error for underscore rank", () => { | ||
expect(() => getCardValue("00_02♠")).toThrow("Invalid card rank."); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.