generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 240
Birmingham | 25-ITP-Sep | Ahmad Ehsas | Sprint 3 | Implement-and-rewrite-tests #735
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
ahmadehsas
wants to merge
42
commits into
CodeYourFuture:main
Choose a base branch
from
ahmadehsas: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 29 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
65fe894
Answered comment for count update in exercise -1
ahmadehsas 532fd66
Implement getAngleType with complete test coverage and improved test …
ahmadehsas 0cba6bb
Completed the rest the tests and cases
ahmadehsas 8d6eb95
Implement getCardValue function with test cases for number, face, ace…
ahmadehsas 2479c4f
Implement getAngleType function to classify angle types
ahmadehsas 3fafedf
Add test cases for angle types and update Sprint-1 readme
ahmadehsas 7a5fe08
Added function(isProperFraction)
ahmadehsas 68f5551
Identified Improper, Negative and equal fractions.
ahmadehsas 5dd3b88
Rewrote the Card value function and tests
ahmadehsas 62ef41d
completed the countChar function with a short clear description and t…
ahmadehsas 1443cbf
completed the No occurrences Scenario test
ahmadehsas 1e2318b
completed the function getOrdinalNumber.
ahmadehsas edea881
the test is passed for get-ordinal-number.js
ahmadehsas dbf4e92
Implemented the function and the test was passed
ahmadehsas fad2100
Edited incorrect test cases and fixed logic to ensure all tests pass …
ahmadehsas 1154f89
Add else condition to simplify my code.
ahmadehsas 047df5d
Add jest .toThrow method for checking if the function can throw the e…
ahmadehsas ba0f73e
implement the the function getOrdinalNumber that works for any vali p…
ahmadehsas 5aeb5c0
prepare tests for all valid integers.
ahmadehsas 550f44d
combine tests for number cards and Face cards.
ahmadehsas e76a59c
update the function to hundle invalid input.
ahmadehsas 3415822
update the test code to hundle expected cases.
ahmadehsas bf5f7f8
Match the error message in toThrow() matcher function.
ahmadehsas 4f1e86a
Delete Sprint-1/1-key-exercises/1-count.js
ahmadehsas e5699a5
Delete Sprint-1/readme.md
ahmadehsas 63d4861
Restored deleted files from Sprint-1 to fix accidental changes
ahmadehsas e749f57
update the tests for all valid integers.
ahmadehsas d34b464
Add test code to cover all valid integers.
ahmadehsas fb90283
Add input validation to ensure the function only accept valid card va…
ahmadehsas 8b3fd7a
Check if the Number(rank) works instead of parseint(rank, 10).
ahmadehsas b1e528f
deleted sprint-1 subforlder from sprint-3.
ahmadehsas e956cdc
Some folders have been renamed.
ahmadehsas c57fbd0
reverted files from sprint-1 to sprint-3.
ahmadehsas 7490201
Merge branch 'main' into coursework/sprint-3
ahmadehsas 154071d
Resolved merge conflicts with main updated Sprint-3 structure.
ahmadehsas 30dfbd8
Transferred all of my changes to the updated foldersand removed all o…
ahmadehsas a0cf3ae
Removed redundent code.
ahmadehsas 56ccaef
Removed redundant code and add condition for negative nemurator and d…
ahmadehsas 5c8aac3
recognized string values as valid ranks.
ahmadehsas 8accc29
The test is passed for negative denominator fraction.
ahmadehsas 5b0a96e
The implementation of all tests has been passed.
ahmadehsas 3b28213
Save updates to proper-fraction and card-value functions
ahmadehsas 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
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,15 @@ | ||
| function getAngleType(angle) { | ||
| if (angle === 90) return "Right angle"; | ||
| // replace with your completed function from key-implement | ||
| 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"; | ||
|
|
||
| return "Invalid 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; |
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,12 @@ | ||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) return true; | ||
| // add your completed function from key-implement here | ||
| if (denominator === 0) { | ||
| return false; | ||
| } else if (Math.abs(numerator) < Math.abs(denominator)) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| module.exports = isProperFraction; | ||
| // This version of code works correctly for proper and negative fractions. | ||
| 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,39 @@ | ||
| function getCardValue(card) { | ||
| // replace with your code from key-implement | ||
| return 11; | ||
| if (typeof card !== "string") { | ||
| throw new Error("Card must be a string"); | ||
| } | ||
|
|
||
| card = card.trim().toUpperCase(); | ||
|
|
||
| // Extract rank (everything except last char, assuming last is suit) | ||
| const rank = card.slice(0, -1); | ||
|
|
||
| // Define allowed ranks exactly — no fuzzy matching | ||
| const validRanks = [ | ||
| "2", | ||
| "3", | ||
| "4", | ||
| "5", | ||
| "6", | ||
| "7", | ||
| "8", | ||
| "9", | ||
| "10", | ||
| "J", | ||
| "Q", | ||
| "K", | ||
| "A", | ||
| ]; | ||
|
|
||
| if (!validRanks.includes(rank)) { | ||
| throw new Error("Invalid card rank"); | ||
| } | ||
|
|
||
| if (rank === "A") return 11; | ||
| if (["K", "Q", "J"].includes(rank)) return 10; | ||
|
|
||
| // If rank is numeric (2-10), safely convert to number | ||
| return parseInt(rank, 10); | ||
| } | ||
| 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
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,15 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; // start a count with 0 | ||
| for (let char of stringOfCharacters) { | ||
| // repeat for each character in the string | ||
| if (char === findCharacter) { | ||
| // check if the character matches the one we are looking for. | ||
| count++; // if it does increase the count by 1. | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
| console.log(countChar("aAaAaAaAa", "a")); // example usage should return 5. | ||
|
|
||
| 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
20 changes: 17 additions & 3 deletions
20
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,19 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| function getOrdinalNumber(n) { | ||
| let ord = "th"; | ||
|
|
||
| if (n % 10 == 1 && n % 100 != 11) { | ||
| ord = "st"; | ||
| } else if (n % 10 == 2 && n % 100 != 12) { | ||
| ord = "nd"; | ||
| } else if (n % 10 == 3 && n % 100 != 13) { | ||
| ord = "rd"; | ||
| } | ||
|
|
||
| return n + ord; | ||
| } | ||
| console.log(getOrdinalNumber(1)); // The output should be "1st" | ||
|
|
||
| // in this function, we got the ordinal number for 1. | ||
| // we used a simple if statement to check if the number is 1 and return "1st". | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| module.exports = getOrdinalNumber; |
Oops, something went wrong.
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.
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 think using Number(rank) is simpler than accounting for base 10)?
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.
Yeah, 'Number(rank) 'is simpler because you don't need to specify the base. However, "parseint(rank, 10)" is useful if the string contains non-numeric characters. for example: "10px". And, the Number would return NAN.