-
-
Notifications
You must be signed in to change notification settings - Fork 397
London | 26-ITP-May | Sayeed Hussain | Sprint 3 | implement-and-rewrite #1590
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
sayeedhussain01
wants to merge
28
commits into
CodeYourFuture:main
Choose a base branch
from
sayeedhussain01:Sprint-3/implement
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
28 commits
Select commit
Hold shift + click to select a range
aeba164
Explained what line 3 is doing
sayeedhussain01 bf0aa49
Fix syntax error
sayeedhussain01 f09ff4b
fix syntax error and define erro
sayeedhussain01 28dec16
fix syntax error and used valid parameter name
sayeedhussain01 fbc18f9
fixed multiply function to return result
sayeedhussain01 82ad98f
fixed sum function to return correct value
sayeedhussain01 9e3b8c1
fix getLastDigit to return last digit of any input number
sayeedhussain01 df45294
made a bmi calcultor function
sayeedhussain01 9513e24
wrote a function for upper snakecase
sayeedhussain01 09bd32f
added function
sayeedhussain01 64a649f
Answered following question in time format
sayeedhussain01 19b4504
converted 24 clock to 12 and test group of input and adge cases
sayeedhussain01 1f54745
fix original files
sayeedhussain01 4cd4749
Implement angle
sayeedhussain01 f86d67d
Implemented angle type
sayeedhussain01 c52dab3
Implemented angle type
sayeedhussain01 e207d39
Formed proper fraction
sayeedhussain01 833f478
implemented card value
sayeedhussain01 5935475
angle type test done
sayeedhussain01 d6b8042
get angle test done
sayeedhussain01 0b6ad14
get angle test done
sayeedhussain01 563050e
get angle test done
sayeedhussain01 bd91f3b
proper fraction test implementation done
sayeedhussain01 9cf30f5
card value test implementation done
sayeedhussain01 d3ca5ad
try to fix
sayeedhussain01 d58e208
fix error
sayeedhussain01 9efb8a7
fix revert files
sayeedhussain01 0b2dbe2
fix revert sprint-1 task
sayeedhussain01 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
96 changes: 59 additions & 37 deletions
96
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,59 @@ | ||
| // 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. | ||
|
|
||
| // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) | ||
|
|
||
| // 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 getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| } | ||
|
|
||
| // 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; | ||
|
|
||
| // 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}` | ||
| ); | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| // 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. | ||
|
|
||
| // Assumption: The parameter is a valid number. (You do not need to handle non-numeric inputs.) | ||
|
|
||
| // 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 getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| if (angle < 90) { | ||
| return "Acute angle"; | ||
| } | ||
| if (angle === 90) { | ||
| return "Right angle"; | ||
| } | ||
| if (angle > 90 && angle < 180) { | ||
| return "Obtuse angle"; | ||
| } | ||
| if (angle === 180) { | ||
| return "Straight angle"; | ||
| } | ||
| if (angle > 180 && angle < 360) { | ||
| return "Reflex angle"; | ||
| } else { | ||
| return "Invalid"; | ||
| } | ||
| } | ||
|
|
||
| // 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; | ||
|
|
||
| // 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}` | ||
| ); | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
| assertEquals(getAngleType(45), "Acute angle"); | ||
| assertEquals(getAngleType(145), "Obtuse angle"); | ||
| assertEquals(getAngleType(180), "Straight angle"); | ||
| assertEquals(getAngleType(190), "Reflex angle"); | ||
| assertEquals(getAngleType(390), "Invalid"); |
71 changes: 38 additions & 33 deletions
71
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,38 @@ | ||
| // 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; | ||
|
|
||
| // Here's our helper again | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| } | ||
|
|
||
| // 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); | ||
| // 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 | ||
| let fraction = Math.abs(numerator) < Math.abs(denominator); | ||
| return fraction; | ||
| } | ||
|
|
||
| // 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; | ||
|
|
||
| // Here's our helper again | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| } | ||
|
|
||
| // 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); | ||
| assertEquals(isProperFraction(5, 2), false); | ||
| assertEquals(isProperFraction(7, 9), true); | ||
| assertEquals(isProperFraction(3, -5), true); | ||
163 changes: 109 additions & 54 deletions
163
Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.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,54 +1,109 @@ | ||
| // This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck | ||
|
|
||
| // Implement a function getCardValue, when given a string representing a playing card, | ||
| // should return the numerical value of the card. | ||
|
|
||
| // A valid card string will contain a rank followed by the suit. | ||
| // The rank can be one of the following strings: | ||
| // "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" | ||
| // The suit can be one of the following emojis: | ||
| // "♠", "♥", "♦", "♣" | ||
| // For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". | ||
|
|
||
| // When the card is an ace ("A"), the function should return 11. | ||
| // When the card is a face card ("J", "Q", "K"), the function should return 10. | ||
| // When the card is a number card ("2" to "10"), the function should return its numeric value. | ||
|
|
||
| // When the card string is invalid (not following the above format), the function should | ||
| // throw an error. | ||
|
|
||
| // 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 getCardValue(card) { | ||
| // TODO: Implement this function | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = getCardValue; | ||
|
|
||
| // Helper functions to make our assertions easier to read. | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
||
| // This line will not be reached if an error is thrown as expected | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
|
|
||
| // What other invalid card cases can you think of? | ||
| // This problem involves playing cards: https://en.wikipedia.org/wiki/Standard_52-card_deck | ||
|
|
||
| // Implement a function getCardValue, when given a string representing a playing card, | ||
| // should return the numerical value of the card. | ||
|
|
||
| // A valid card string will contain a rank followed by the suit. | ||
| // The rank can be one of the following strings: | ||
| // "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" | ||
| // The suit can be one of the following emojis: | ||
| // "♠", "♥", "♦", "♣" | ||
| // For example: "A♠", "2♥", "10♥", "J♣", "Q♦", "K♦". | ||
|
|
||
| // When the card is an ace ("A"), the function should return 11. | ||
| // When the card is a face card ("J", "Q", "K"), the function should return 10. | ||
| // When the card is a number card ("2" to "10"), the function should return its numeric value. | ||
|
|
||
| // When the card string is invalid (not following the above format), the function should | ||
| // throw an error. | ||
|
|
||
| // 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 getCardValue(card) { | ||
| // TODO: Implement this function | ||
|
|
||
| const ranks = [ | ||
| "A", | ||
| "2", | ||
| "3", | ||
| "4", | ||
| "5", | ||
| "6", | ||
| "7", | ||
| "8", | ||
| "9", | ||
| "10", | ||
| "J", | ||
| "Q", | ||
| "K", | ||
| ]; | ||
| const suits = ["♠", "♥", "♦", "♣"]; | ||
|
|
||
| const rank1 = card.slice(0, -1); | ||
| const suit1 = card.slice(-1); | ||
| const IsEqualCard = suits.includes(suit1) && ranks.includes(rank1); | ||
| if (!IsEqualCard) { | ||
| throw new Error("invalid card "); | ||
| } | ||
| if (rank1 === "A") { | ||
| return 11; | ||
| } | ||
| if (rank1 === "J" || rank1 === "Q" || rank1 === "K") { | ||
| return 10; | ||
| } | ||
| const numberRanks = Number(rank1); | ||
| if (numberRanks >= 2 && numberRanks <= 10) { | ||
| return numberRanks; | ||
| } | ||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
| // This will be useful in the "rewrite tests with jest" step. | ||
| module.exports = getCardValue; | ||
|
|
||
| // Helper functions to make our assertions easier to read. | ||
| function assertEquals(actualOutput, targetOutput) { | ||
| console.assert( | ||
| actualOutput === targetOutput, | ||
| `Expected ${actualOutput} to equal ${targetOutput}` | ||
| ); | ||
| } | ||
|
|
||
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
| // Examples: | ||
| assertEquals(getCardValue("9♠"), 9); | ||
| assertEquals(getCardValue("10♦"), 10); | ||
| assertEquals(getCardValue("7♠"), 7); | ||
| assertEquals(getCardValue("8♥"), 8); | ||
| assertEquals(getCardValue("A♥"), 11); | ||
| assertEquals(getCardValue("J♥"), 10); | ||
| assertEquals(getCardValue("Q♥"), 10); | ||
| assertEquals(getCardValue("K♥"), 10); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
||
| // This line will not be reached if an error is thrown as expected | ||
| console.error("Error was not thrown for invalid card 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
|
|
||
| try { | ||
| getCardValue("1♠"); | ||
| console.error("Error was not thrown 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid 🎉"); | ||
| } | ||
|
|
||
| try { | ||
| getCardValue("error"); | ||
| console.error("Error was not thrown 😢"); | ||
| } catch (e) { | ||
| console.log("Error thrown for invalid 🎉"); | ||
| } | ||
|
|
||
| // What other invalid card cases can you think of? |
66 changes: 46 additions & 20 deletions
66
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,46 @@ | ||
| // 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. | ||
|
|
||
| // 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"); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| // Case 3: Obtuse angles | ||
| // Case 4: Straight angle | ||
| // Case 5: Reflex angles | ||
| // Case 6: Invalid angles | ||
| // 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. | ||
|
|
||
| // Case 1: Acute angles | ||
| test(`should return "Acute angle" when ( angle > 0 and 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"); | ||
| }); | ||
|
|
||
| // Case 2: Right angle | ||
| test(`should return "Right angle" when angle exactly equals 90`, () => { | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
| }); | ||
|
|
||
| // Case 3: Obtuse angles | ||
| describe(`should return "obtuse angle" when obtuse > 90 and obtuse < 180`, () => { | ||
| expect(getAngleType(95)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(99)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(105)).toEqual("Obtuse angle"); | ||
| }); | ||
| // Case 4: Straight angle | ||
|
|
||
| test(`should return "straight angle" when straight is equals 180`, () => { | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
| // Case 5: Reflex angles | ||
| test(`should return "reflex angle" if angle is more than 180 and less than 360`, () => { | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(191)).toEqual("Reflex angle"); | ||
| expect(getAngleType(211)).toEqual("Reflex angle"); | ||
| }); | ||
|
|
||
| // tes(`should return "reflex angle" when straight is `); | ||
| // Case 6: Invalid angles | ||
| test(`should return "invalid angle" if any of them don't match`, () => { | ||
| expect(getAngleType(385)).toEqual("Invalid"); | ||
| expect(getAngleType(380)).toEqual("Invalid"); | ||
| expect(getAngleType(430)).toEqual("Invalid"); | ||
| expect(getAngleType(390)).toEqual("Invalid"); | ||
| }); |
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.
This works, good use of Abs, but can the return statement be simplified?