Repository navigation
North West | 26-ITP-Sep | Brian Yorachi | Sprint 2 | implement and rewrite tests #1705
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
BrianY315
wants to merge
7
commits into
CodeYourFuture:main
Choose a base branch
from
BrianY315: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
7 commits
Select commit
Hold shift + click to select a range
8a715f4
Implement sprint 3 functions
BrianY315 cbcc2b3
Complete node and Jest sprint tests
BrianY315 22d4a37
Add decimal angle boundary tests
BrianY315 b6b7084
Mirror angle boundary coverage in Jest
BrianY315 23d3274
Cover every standard card combination
BrianY315 3449903
Mirror exhaustive card coverage in Jest
BrianY315 52fef2a
Add more negative-value test cases for isProperFraction
BrianY315 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
42 changes: 28 additions & 14 deletions
42
implement-and-rewrite-tests/rewrite-tests-with-jest/1-get-angle-type.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,32 @@ | ||
| import { getAngleType } from "../implement/1-get-angle-type.js"; | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all cases/outcomes, | ||
| // including boundary and invalid cases. | ||
|
|
||
| // Case 1: Acute angles | ||
| test(`should return "Acute angle" when (0 < angle < 90)`, () => { | ||
| // Test various acute angles, including boundary cases | ||
| expect(getAngleType(1)).toEqual("Acute angle"); | ||
| expect(getAngleType(45)).toEqual("Acute angle"); | ||
| expect(getAngleType(89)).toEqual("Acute angle"); | ||
| test.each([ | ||
| [1, "Acute angle"], | ||
| [45, "Acute angle"], | ||
| [89, "Acute angle"], | ||
| [90, "Right angle"], | ||
| [91, "Obtuse angle"], | ||
| [135, "Obtuse angle"], | ||
| [179, "Obtuse angle"], | ||
| [180, "Straight angle"], | ||
| [181, "Reflex angle"], | ||
| [270, "Reflex angle"], | ||
| [359, "Reflex angle"], | ||
| [0, "Invalid angle"], | ||
| [360, "Invalid angle"], | ||
| [-1, "Invalid angle"], | ||
| [361, "Invalid angle"], | ||
| ])("classifies an angle of %i degrees", (angle, expectedType) => { | ||
| expect(getAngleType(angle)).toEqual(expectedType); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| // Case 3: Obtuse angles | ||
| // Case 4: Straight angle | ||
| // Case 5: Reflex angles | ||
| // Case 6: Invalid angles | ||
| test.each([ | ||
| [0.1, "Acute angle"], | ||
| [89.9, "Acute angle"], | ||
| [90.1, "Obtuse angle"], | ||
| [179.9, "Obtuse angle"], | ||
| [180.1, "Reflex angle"], | ||
| [359.9, "Reflex angle"], | ||
| ])("classifies a boundary-adjacent angle of %i degrees", (angle, expectedType) => { | ||
| expect(getAngleType(angle)).toEqual(expectedType); | ||
| }); |
22 changes: 17 additions & 5 deletions
22
implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.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,8 +1,20 @@ | ||
| import { isProperFraction } from "../implement/2-is-proper-fraction.js"; | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. | ||
|
|
||
| // Special case: numerator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| test.each([ | ||
| [1, 2, true], | ||
| [9, 10, true], | ||
| [2, 1, false], | ||
| [3, 3, false], | ||
| [10, 2, false], | ||
| [0, 5, true], | ||
| [-1, 2, true], | ||
| [1, -2, true], | ||
| [-3, -2, false], | ||
| [-1, -2, true], | ||
| [-3, 2, false], | ||
| [3, -2, false], | ||
| [0, 0, false], | ||
| [1, 0, false], | ||
| ])("checks %i/%i", (numerator, denominator, expected) => { | ||
| expect(isProperFraction(numerator, denominator)).toEqual(expected); | ||
| }); | ||
51 changes: 39 additions & 12 deletions
51
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,45 @@ | ||
| import { getCardValue } from "../implement/3-get-card-value.js"; | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| test.each([ | ||
| ["2♠", 2], | ||
| ["9♠", 9], | ||
| ["10♥", 10], | ||
| ["A♠", 11], | ||
| ["J♣", 10], | ||
| ["Q♦", 10], | ||
| ["K♥", 10], | ||
| ])("returns the value of %s", (card, expectedValue) => { | ||
| expect(getCardValue(card)).toEqual(expectedValue); | ||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
| const ranks = [ | ||
| ["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 = ["♠", "♥", "♦", "♣"]; | ||
|
|
||
| // 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.each( | ||
| ranks.flatMap(([rank, expectedValue]) => | ||
| suits.map((suit) => [`${rank}${suit}`, expectedValue]), | ||
| ), | ||
| )("returns the expected value for %s", (card, expectedValue) => { | ||
| expect(getCardValue(card)).toEqual(expectedValue); | ||
| }); | ||
|
|
||
| test.each(["invalid", "1♠", "11♠", "A", "A X", "A🃏"])( | ||
| "rejects invalid card %s", | ||
| (card) => { | ||
| expect(() => getCardValue(card)).toThrow(); | ||
| }, | ||
| ); |
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.
These test cases are quite comprehensive because they almost cover all possible combinations of numerator and denominator.
Could you think of one more test case to make them more complete?
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.
Thanks for the review! I've added three more test cases covering the sign combinations that were missing: [-1, -2, true] (both negative, proper), [-3, 2, false] (negative numerator, improper) and [3, -2, false] (negative denominator, improper). I added the same cases to the node-test file so the two suites stay consistent. All tests pass. Please take another look when you have time
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.
Well done.