Repository navigation
Manchester | 26-ITP-Sept | Fatima Rouchi | Sprint 2 | Implement and rewrite tests #1728
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
fatimarouchi
wants to merge
16
commits into
CodeYourFuture:main
Choose a base branch
from
fatimarouchi:coursework/sprint-3-implement-and-rewrite
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
16 commits
Select commit
Hold shift + click to select a range
e275bbf
add more tests
fatimarouchi 18c03c0
implement functions
fatimarouchi a19670a
fix error
fatimarouchi f5bf95b
implement function
fatimarouchi 6c865ba
run tests
fatimarouchi 37f4f78
Revert latest test run
fatimarouchi 12f4893
add test
fatimarouchi f47f802
add more test
fatimarouchi d58fb5e
Add Jest tests for angle types
fatimarouchi c9cc257
Add proper fraction tests
fatimarouchi eaa3920
Add Jest tests for card values
fatimarouchi 6e7d6e6
Add boundary cases to angle type tests
fatimarouchi f4eca9e
Restrict card values to valid ranks
fatimarouchi d034af5
Test all valid card ranks and reject invalid formats
fatimarouchi 7e69ad3
Cover all card ranks and invalid formats in Jest tests
fatimarouchi 2c547d9
Correct proper fraction expectation for negative values
fatimarouchi 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
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
42 changes: 30 additions & 12 deletions
42
implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.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,18 +1,36 @@ | ||
| import { getCardValue } from "../implement/3-get-card-value.js"; | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
| test("Returns the correct value for every valid rank and suit", () => { | ||
| const expectedValues = { | ||
| A: 11, | ||
| 2: 2, | ||
| 3: 3, | ||
| 4: 4, | ||
| 5: 5, | ||
| 6: 6, | ||
| 7: 7, | ||
| 8: 8, | ||
| 9: 9, | ||
| 10: 10, | ||
| J: 10, | ||
| Q: 10, | ||
| K: 10, | ||
| }; | ||
| const suits = ["♠", "♥", "♦", "♣"]; | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| for (const [rank, value] of Object.entries(expectedValues)) { | ||
| for (const suit of suits) { | ||
| expect(getCardValue(`${rank}${suit}`)).toEqual(value); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
|
|
||
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
| // https://jestjs.io/docs/expect#tothrowerror | ||
| test("Throws an error for invalid card formats", () => { | ||
| const invalidCards = ["A", "invalid", "1♠", "11♠", "02♠", "2.5♠", " 2♠", "A?", ""]; | ||
|
|
||
| for (const card of invalidCards) { | ||
| expect(() => getCardValue(card)).toThrow( | ||
| `Expected a number followed by a suit, but got "${card}"` | ||
| ); | ||
| } | ||
| }); |
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.
An exact range of invalid angles could probably make the test description more informative.