-
-
Notifications
You must be signed in to change notification settings - Fork 337
Glasgow | ITP-Jan-26 | Alasdair MacDonald | Sprint 3 | Coursework 3 implement and rewrite #1157
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
MacDonald91
wants to merge
7
commits into
CodeYourFuture:main
Choose a base branch
from
MacDonald91: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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0f5e98
Sprint 3 implement functions and tests
MacDonald91 06c3aa1
Fix: strict validation for card values (prevent invalid numeric formats)
MacDonald91 9837435
Merge branch 'main' into coursework/sprint-3-implement-and-rewrite
MacDonald91 b1be443
Updated tests
MacDonald91 da17f68
fix: tests.js
MacDonald91 3fcf3f9
Fix: erros fixed
MacDonald91 a17bab5
Fix: revert package.json to original CYF version
MacDonald91 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
50 changes: 20 additions & 30 deletions
50
Sprint-3/1-implement-and-rewrite-tests/implement/1-get-angle-type.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,37 +1,27 @@ | ||
| // Implement a function getAngleType | ||
| // | ||
| // When given an angle in degrees, it should return a string indicating the type of angle: | ||
| // - "Acute angle" for angles greater than 0° and less than 90° | ||
| // - "Right angle" for exactly 90° | ||
| // - "Obtuse angle" for angles greater than 90° and less than 180° | ||
| // - "Straight angle" for exactly 180° | ||
| // - "Reflex angle" for angles greater than 180° and less than 360° | ||
| // - "Invalid angle" for angles outside the valid range. | ||
| function getAngleType(angle) { | ||
| if (angle <= 0 || angle >= 360) { | ||
| return "Invalid angle"; | ||
| } | ||
|
|
||
| // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) | ||
| if (angle > 0 && angle < 90) { | ||
| return "Acute angle"; | ||
| } | ||
|
|
||
| // Acceptance criteria: | ||
| // After you have implemented the function, write tests to cover all the cases, and | ||
| // execute the code to ensure all tests pass. | ||
| if (angle === 90) { | ||
| return "Right angle"; | ||
| } | ||
|
|
||
| function getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| } | ||
| if (angle > 90 && angle < 180) { | ||
| return "Obtuse angle"; | ||
| } | ||
|
|
||
| // The line below allows us to load the getAngleType function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = getAngleType; | ||
| if (angle === 180) { | ||
| return "Straight angle"; | ||
| } | ||
|
|
||
| // This helper function is written to make our assertions easier to read. | ||
| // If the actual output matches the target output, the test will pass | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| if (angle > 180 && angle < 360) { | ||
| return "Reflex angle"; | ||
| } | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| module.exports = getAngleType; |
34 changes: 5 additions & 29 deletions
34
Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.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,33 +1,9 @@ | ||
| // Implement a function isProperFraction, | ||
| // when given two numbers, a numerator and a denominator, it should return true if | ||
| // the given numbers form a proper fraction, and false otherwise. | ||
|
|
||
| // Assumption: The parameters are valid numbers (not NaN or Infinity). | ||
|
|
||
| // Note: If you are unfamiliar with proper fractions, please look up its mathematical definition. | ||
|
|
||
| // Acceptance criteria: | ||
| // After you have implemented the function, write tests to cover all the cases, and | ||
| // execute the code to ensure all tests pass. | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function | ||
| } | ||
|
|
||
| // The line below allows us to load the isProperFraction function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = isProperFraction; | ||
| if (denominator === 0) { | ||
| return false; | ||
| } | ||
|
|
||
| // Here's our helper again | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| return Math.abs(numerator) < Math.abs(denominator); | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all cases. | ||
| // What combinations of numerators and denominators should you test? | ||
|
|
||
| // Example: 1/2 is a proper fraction | ||
| assertEquals(isProperFraction(1, 2), 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
45 changes: 29 additions & 16 deletions
45
Sprint-3/1-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,20 +1,33 @@ | ||
| // This statement loads the getAngleType function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const getAngleType = require("../implement/1-get-angle-type"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all cases/outcomes, | ||
| // including boundary and invalid cases. | ||
| describe("getAngleType", () => { | ||
| test("returns Acute angle", () => { | ||
| expect(getAngleType(1)).toBe("Acute angle"); | ||
| expect(getAngleType(45)).toBe("Acute angle"); | ||
| expect(getAngleType(89)).toBe("Acute angle"); | ||
| }); | ||
|
|
||
| // 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("returns Right angle", () => { | ||
| expect(getAngleType(90)).toBe("Right angle"); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| // Case 3: Obtuse angles | ||
| // Case 4: Straight angle | ||
| // Case 5: Reflex angles | ||
| // Case 6: Invalid angles | ||
| test("returns Obtuse angle", () => { | ||
| expect(getAngleType(100)).toBe("Obtuse angle"); | ||
| expect(getAngleType(179)).toBe("Obtuse angle"); | ||
| }); | ||
|
|
||
| test("returns Straight angle", () => { | ||
| expect(getAngleType(180)).toBe("Straight angle"); | ||
| }); | ||
|
|
||
| test("returns Reflex angle", () => { | ||
| expect(getAngleType(200)).toBe("Reflex angle"); | ||
| expect(getAngleType(359)).toBe("Reflex angle"); | ||
| }); | ||
|
|
||
| test("returns Invalid angle", () => { | ||
| expect(getAngleType(0)).toBe("Invalid angle"); | ||
| expect(getAngleType(360)).toBe("Invalid angle"); | ||
| expect(getAngleType(-10)).toBe("Invalid angle"); | ||
| }); | ||
| }); |
34 changes: 27 additions & 7 deletions
34
Sprint-3/1-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,10 +1,30 @@ | ||
| // This statement loads the isProperFraction function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const isProperFraction = require("../implement/2-is-proper-fraction"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all combinations of positives, negatives, zeros, and other categories. | ||
| describe("isProperFraction", () => { | ||
| test("returns true when numerator is smaller than denominator", () => { | ||
| expect(isProperFraction(1, 2)).toBe(true); | ||
| expect(isProperFraction(3, 4)).toBe(true); | ||
| }); | ||
|
|
||
| // Special case: numerator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
| test("returns false when numerator equals denominator", () => { | ||
| expect(isProperFraction(5, 5)).toBe(false); | ||
| }); | ||
|
|
||
| test("returns false when numerator is larger than denominator", () => { | ||
| expect(isProperFraction(7, 3)).toBe(false); | ||
| }); | ||
|
|
||
| test("returns true when numerator is zero", () => { | ||
| expect(isProperFraction(0, 5)).toBe(true); | ||
| }); | ||
|
|
||
| test("returns false when denominator is zero", () => { | ||
| expect(isProperFraction(1, 0)).toBe(false); | ||
| }); | ||
|
|
||
| test("works with negative numbers", () => { | ||
| expect(isProperFraction(-1, 2)).toBe(true); | ||
| expect(isProperFraction(1, -2)).toBe(true); | ||
| expect(isProperFraction(-3, -2)).toBe(false); | ||
| }); | ||
| }); |
52 changes: 38 additions & 14 deletions
52
Sprint-3/1-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,20 +1,44 @@ | ||
| // This statement loads the getCardValue function you wrote in the implement directory. | ||
| // We will use the same function, but write tests for it using Jest in this file. | ||
| const getCardValue = require("../implement/3-get-card-value"); | ||
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
| describe("getCardValue", () => { | ||
| // Ace | ||
| test("returns 11 for Ace", () => { | ||
| expect(getCardValue("A♠")).toBe(11); | ||
| }); | ||
|
|
||
| // Case 1: Ace (A) | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| }); | ||
| // Face cards | ||
| test("returns 10 for face cards", () => { | ||
| expect(getCardValue("J♥")).toBe(10); | ||
| expect(getCardValue("Q♦")).toBe(10); | ||
| expect(getCardValue("K♣")).toBe(10); | ||
| }); | ||
|
|
||
| // Suggestion: Group the remaining test data into these categories: | ||
| // Number Cards (2-10) | ||
| // Face Cards (J, Q, K) | ||
| // Invalid Cards | ||
| // Number cards | ||
| test("returns correct value for number cards", () => { | ||
| expect(getCardValue("2♠")).toBe(2); | ||
| expect(getCardValue("10♥")).toBe(10); | ||
| }); | ||
|
|
||
| // 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 | ||
| // Invalid format | ||
| test("throws error for invalid strings", () => { | ||
| expect(() => getCardValue("invalid")).toThrow(); | ||
| expect(() => getCardValue("A")).toThrow(); | ||
| }); | ||
|
|
||
| // Invalid numbers (REVIEWER CHECK 🔥) | ||
| test("throws error for invalid numeric formats", () => { | ||
| expect(() => getCardValue("0x02♠")).toThrow(); | ||
| expect(() => getCardValue("2.1♠")).toThrow(); | ||
| expect(() => getCardValue("0002♠")).toThrow(); | ||
| }); | ||
|
|
||
| // Invalid rank | ||
| test("throws error for invalid rank", () => { | ||
| expect(() => getCardValue("11♠")).toThrow(); | ||
| }); | ||
|
|
||
| // Invalid suit | ||
| test("throws error for invalid suit", () => { | ||
| expect(() => getCardValue("A?")).toThrow(); | ||
| }); | ||
| }); |
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
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.
Lines 32, 34, 85 are merge conflict markers.
Lines 33 is from one source and lines 35 to 84 are from another source. You need to