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
24
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
24 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 dd4d5dc
test: reject invalid card ranks
fatimarouchi 6f64b83
test: cover angle boundaries
fatimarouchi 1c0da29
Add negative angle coverage
fatimarouchi cb8fa8a
Group card value cases
fatimarouchi 5a89c66
Cover angle classification boundaries
fatimarouchi acbe93e
Fix proper fraction logic and tests
fatimarouchi 2eae682
Cover proper fraction sign and boundary cases
fatimarouchi 83a6341
Handle proper fraction edge cases
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
40 changes: 37 additions & 3 deletions
40
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,52 @@ | ||
| 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(0.1)).toEqual("Acute angle"); | ||
| expect(getAngleType(1)).toEqual("Acute angle"); | ||
| expect(getAngleType(0.5)).toEqual("Acute angle"); | ||
| expect(getAngleType(45)).toEqual("Acute angle"); | ||
| expect(getAngleType(89.9)).toEqual("Acute angle"); | ||
| expect(getAngleType(89.5)).toEqual("Acute angle"); | ||
| expect(getAngleType(89)).toEqual("Acute angle"); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| test('should return "Right angle" when angle is 90', () => { | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
| // Case 3: Obtuse angles | ||
| test('should return "Obtuse angle" when (90 < angle < 180)', () => { | ||
| expect(getAngleType(90.1)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(90.5)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179.9)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179.5)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| }); | ||
| // Case 4: Straight angle | ||
| test('should return "Straight angle" when angle is 180', () => { | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Reflex angles | ||
| test('should return "Reflex angle" when (180 < angle < 360)', () => { | ||
| expect(getAngleType(180.1)).toEqual("Reflex angle"); | ||
| expect(getAngleType(180.5)).toEqual("Reflex angle"); | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(270)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359.9)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359.5)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| }); | ||
| // Case 6: Invalid angles | ||
|
|
||
| test('should return "Invalid angle" for invalid angles', () => { | ||
|
fatimarouchi marked this conversation as resolved.
Resolved
|
||
| expect(getAngleType(-1)).toEqual("Invalid angle"); | ||
| expect(getAngleType(-0.5)).toEqual("Invalid angle"); | ||
| expect(getAngleType(-10)).toEqual("Invalid angle"); | ||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| expect(getAngleType(360)).toEqual("Invalid angle"); | ||
| expect(getAngleType(400)).toEqual("Invalid angle"); | ||
| }); | ||
49 changes: 45 additions & 4 deletions
49
implement-and-rewrite-tests/rewrite-tests-with-jest/2-is-proper-fraction.test.js
|
fatimarouchi marked this conversation as resolved.
Resolved
|
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,49 @@ | ||
| 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`, () => { | ||
| test("should return false when the denominator is zero", () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| expect(isProperFraction(0, 0)).toEqual(false); | ||
| }); | ||
|
|
||
| test("should return true for a proper fraction", () => { | ||
| expect(isProperFraction(1, 2)).toEqual(true); | ||
| }); | ||
|
|
||
| test("should return false when the numerator and denominator have equal magnitudes", () => { | ||
| expect(isProperFraction(5, 5)).toEqual(false); | ||
| expect(isProperFraction(-5, 5)).toEqual(false); | ||
| expect(isProperFraction(5, -5)).toEqual(false); | ||
| expect(isProperFraction(-5, -5)).toEqual(false); | ||
| }); | ||
|
|
||
| test("should return false when the numerator's magnitude exceeds the denominator's", () => { | ||
| expect(isProperFraction(7, 3)).toEqual(false); | ||
| expect(isProperFraction(-7, 3)).toEqual(false); | ||
| expect(isProperFraction(7, -3)).toEqual(false); | ||
| expect(isProperFraction(-7, -3)).toEqual(false); | ||
| }); | ||
|
|
||
| test("should return true when numerator is zero", () => { | ||
| expect(isProperFraction(0, 5)).toEqual(true); | ||
| expect(isProperFraction(0, -5)).toEqual(true); | ||
| }); | ||
|
|
||
| test("should return true when both numerator and denominator are negative and form a proper fraction", () => { | ||
| expect(isProperFraction(-1, -2)).toEqual(true); | ||
| }); | ||
|
|
||
| test("should return true for negative numerator and positive denominator", () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(true); | ||
| }); | ||
|
|
||
| test("should return true for positive numerator and negative denominator when the numerator is smaller", () => { | ||
| expect(isProperFraction(1, -2)).toEqual(true); | ||
| }); | ||
|
|
||
| test("should return false for negative numerator and positive denominator when the numerator is larger", () => { | ||
| expect(isProperFraction(-3, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| test("should return false for positive numerator and negative denominator when the numerator is larger", () => { | ||
| expect(isProperFraction(3, -2)).toEqual(false); | ||
| }); |
54 changes: 43 additions & 11 deletions
54
implement-and-rewrite-tests/rewrite-tests-with-jest/3-get-card-value.test.js
|
fatimarouchi marked this conversation as resolved.
Resolved
|
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,50 @@ | ||
| import { getCardValue } from "../implement/3-get-card-value.js"; | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
| test("Returns the value of number cards from 2 to 10", () => { | ||
| const suits = ["♠", "♥", "♦", "♣"]; | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| for (let rank = 2; rank <= 10; rank += 1) { | ||
| for (const suit of suits) { | ||
| expect(getCardValue(`${rank}${suit}`)).toEqual(rank); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
| test("Returns 10 for face cards", () => { | ||
| 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 | ||
| for (const rank of ["J", "Q", "K"]) { | ||
| for (const suit of suits) { | ||
| expect(getCardValue(`${rank}${suit}`)).toEqual(10); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test("Returns 11 for aces", () => { | ||
| for (const suit of ["♠", "♥", "♦", "♣"]) { | ||
| expect(getCardValue(`A${suit}`)).toEqual(11); | ||
| } | ||
| }); | ||
|
|
||
| test("Throws an error for invalid card formats", () => { | ||
| const invalidCards = [ | ||
| "A", | ||
| "invalid", | ||
| "1♠", | ||
| "11♠", | ||
| "02♠", | ||
| "0x02♦", | ||
| "2.1♦", | ||
| "0002♦", | ||
| "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.
The tests in this script are comprehensive. Well done!
Note: The tests in the Jest test script could also be categorised in similar fashion.