-
-
Notifications
You must be signed in to change notification settings - Fork 389
London | 26-ITP-May | Liridona Shehu | Sprint 3 | Implement and rewrite #1474
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
base: main
Are you sure you want to change the base?
Changes from all commits
7fd7710
88d76b4
b6def45
d06f9a3
c15a48e
66ddc97
b82f302
491605b
b8a684c
095f72d
0a4c587
4aa639f
892bb92
4bc146e
4ccf833
4b20e69
6f270d2
0799ea5
956f635
5cec9c4
1096cc2
6caf04c
fdd00ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,22 @@ | |
|
|
||
| function getAngleType(angle) { | ||
| // TODO: Implement this function | ||
| if( angle > 0 && angle < 90){ | ||
| return "Acute angle"; | ||
| } | ||
| else if (angle === 90){ | ||
| return "Right angle"; | ||
| } | ||
| else if ( angle > 90 && angle < 180){ | ||
| return "Obtuse angle"; | ||
| } | ||
| else if(angle === 180){ | ||
| return "Straight angle"; | ||
| } | ||
| else if( angle > 180 && angle < 360){ | ||
| return "Reflex angle"; | ||
| } | ||
| else return "Invalid angle"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: You don't need the else here as the code will only run if no other condition was true |
||
| } | ||
|
|
||
| // The line below allows us to load the getAngleType function into tests in other files. | ||
|
|
@@ -33,5 +49,32 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
|
|
||
| const acute = getAngleType(45); | ||
| assertEquals(acute, "Acute angle"); | ||
|
|
||
|
|
||
| const right = getAngleType(90); | ||
| assertEquals(right, "Right angle"); | ||
|
|
||
|
|
||
| const obtuse = getAngleType(120); | ||
| assertEquals(obtuse, "Obtuse angle"); | ||
|
|
||
|
|
||
| const straight = getAngleType(180); | ||
| assertEquals(straight, "Straight angle"); | ||
|
|
||
|
|
||
| const reflex = getAngleType(200); | ||
| assertEquals(reflex, "Reflex angle"); | ||
|
|
||
|
|
||
| const invalid0 = getAngleType(0); | ||
| assertEquals(invalid0, "Invalid angle"); | ||
|
|
||
| const invalid360 = getAngleType(360); | ||
| assertEquals(invalid360, "Invalid angle"); | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,31 @@ | |
|
|
||
| function getCardValue(card) { | ||
| // TODO: Implement this function | ||
|
|
||
| let rank = card.slice(0, -1); | ||
| let suit = card.slice(-1); | ||
|
|
||
| const validRanks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]; | ||
| const validSuits = ["♠", "♥", "♦", "♣"]; | ||
|
|
||
| let isValidRank = validRanks.includes(rank); | ||
| let isValidSuit = validSuits.includes(suit); | ||
|
|
||
|
|
||
|
|
||
| // Invalid Card | ||
| if( !isValidRank || !isValidSuit ){ | ||
| throw new Error("Invalid Card") | ||
|
Comment on lines
+30
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats a nice way of checking if the input is valid. By expliciting stating all allowed values that code is easy to understand |
||
| } | ||
|
|
||
| if(rank == "A"){ | ||
| return 11; | ||
| } | ||
| else if(rank == "J" || rank == "Q" || rank == "K"){ | ||
| return 10; | ||
| } | ||
| else return Number(rank); | ||
|
|
||
| } | ||
|
|
||
| // The line below allows us to load the getCardValue function into tests in other files. | ||
|
|
@@ -39,8 +64,31 @@ function assertEquals(actualOutput, targetOutput) { | |
|
|
||
| // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards. | ||
| // Examples: | ||
|
|
||
| assertEquals(getCardValue("8♠"), 8); | ||
|
|
||
| assertEquals(getCardValue("7♠"), 7); | ||
|
|
||
| assertEquals(getCardValue("6♠"), 6); | ||
|
|
||
| assertEquals(getCardValue("5♠"), 5); | ||
|
|
||
| assertEquals(getCardValue("4♠"), 4); | ||
|
|
||
| assertEquals(getCardValue("3♠"), 3); | ||
|
|
||
| assertEquals(getCardValue("2♠"), 2); | ||
|
|
||
| assertEquals(getCardValue("9♠"), 9); | ||
|
|
||
| assertEquals(getCardValue("J♠"), 10); | ||
|
|
||
| assertEquals(getCardValue("Q♠"), 10); | ||
|
|
||
| assertEquals(getCardValue("K♠"), 10); | ||
|
|
||
| assertEquals(getCardValue("A♠"), 11); | ||
|
|
||
| // Handling invalid cards | ||
| try { | ||
| getCardValue("invalid"); | ||
|
|
@@ -51,4 +99,23 @@ try { | |
| console.log("Error thrown for invalid card 🎉"); | ||
| } | ||
|
|
||
|
|
||
| // What other invalid card cases can you think of? | ||
| try { | ||
| getCardValue("24♠"); | ||
|
|
||
| // 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("44"); | ||
|
|
||
| // 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 🎉"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,43 @@ test(`should return "Acute angle" when (0 < angle < 90)`, () => { | |
| expect(getAngleType(89)).toEqual("Acute angle"); | ||
| }); | ||
|
|
||
|
|
||
| // Case 2: Right angle | ||
| test(`should return "Right angle" when ( angle = 90)`, () => { | ||
| // Test various right angles, including boundary cases | ||
| expect(getAngleType(90)).toEqual("Right angle"); | ||
|
|
||
| }); | ||
|
|
||
|
|
||
| // Case 3: Obtuse angles | ||
| test(`should return "Obtuse angle" when (90 < angle < 180)`, () => { | ||
| // Test various obtuse angles, including boundary cases | ||
| expect(getAngleType(91)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
| expect(getAngleType(179)).toEqual("Obtuse angle"); | ||
| }); | ||
|
|
||
|
|
||
| // Case 4: Straight angle | ||
| test(`should return "Straight angle" when ( angle = 180)`, () => { | ||
| // Test various straight angles, including boundary cases | ||
| expect(getAngleType(180)).toEqual("Straight angle"); | ||
| }); | ||
|
|
||
|
|
||
| // Case 5: Reflex angles | ||
| test(`should return "Reflex angle" when (180 < angle < 360)`, () => { | ||
| // Test various reflex angles, including boundary cases | ||
| expect(getAngleType(181)).toEqual("Reflex angle"); | ||
| expect(getAngleType(220)).toEqual("Reflex angle"); | ||
| expect(getAngleType(359)).toEqual("Reflex angle"); | ||
| }); | ||
|
|
||
|
|
||
| // Case 6: Invalid angles | ||
| test(`should return "Invalid angle" when (180 < angle < 360)`, () => { | ||
| // Test various invalid angles, including boundary cases | ||
| expect(getAngleType(0)).toEqual("Invalid angle"); | ||
| expect(getAngleType(360)).toEqual("Invalid angle"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could add 2 test cases that are not boundary cases |
||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,43 @@ 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. | ||
|
|
||
| // Special case: numerator is zero | ||
| // Special case: denominator is zero | ||
| test(`should return false when denominator is zero`, () => { | ||
| expect(isProperFraction(1, 0)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: numerator is zero | ||
| test(`should return false when numerator is zero`, () => { | ||
| expect(isProperFraction(0, 1)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: numerator is equal to denominators is a proper fraction | ||
| test(`should return false when numerator is equal to denominator`, () => { | ||
| expect(isProperFraction(2, 2)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: numerator is negative is a proper fraction | ||
| test(`should return false when numerator is negative value`, () => { | ||
| expect(isProperFraction(-1, 2)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: denominator is negative is a proper fraction | ||
|
Comment on lines
+25
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments say is a prober fracteion but the function should return false. This is confusing |
||
| test(`should return false denominator is negative value `, () => { | ||
| expect(isProperFraction(1, -2)).toEqual(false); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: numerator and denominator are both negative values is a proper fraction// | ||
| test(`should return true when numerator ans denominator are both negative values `, () => { | ||
| expect(isProperFraction(-5, -6)).toEqual(true); | ||
| }); | ||
|
|
||
|
|
||
| // Special case: negative numerator with smaller value then negative dominator is a proper fraction | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments say is a prober fracteion but the function should return false. This is confusing |
||
| test(`should return false when negative numerator is smaller than negative denominator `, () => { | ||
| expect(isProperFraction(-6, -5)).toEqual(false); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,58 @@ const getCardValue = require("../implement/3-get-card-value"); | |
|
|
||
| // TODO: Write tests in Jest syntax to cover all possible outcomes. | ||
|
|
||
| // Case 1: Ace (A) | ||
| // Case 1: Ace (A) ♣ ♦ ♥ C | ||
| test(`Should return 11 when given an ace card`, () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| expect(getCardValue("A♥")).toEqual(11); | ||
| expect(getCardValue("A♦")).toEqual(11); | ||
| expect(getCardValue("A♣")).toEqual(11); | ||
| }); | ||
|
|
||
|
|
||
|
|
||
| // 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 | ||
|
|
||
|
|
||
| // Number cards | ||
| test(`Should return the number when given a number card`, () => { | ||
| expect(getCardValue("2♠")).toEqual(2); | ||
| expect(getCardValue("7♥")).toEqual(7); | ||
| expect(getCardValue("9♦")).toEqual(9); | ||
| expect(getCardValue("6♣")).toEqual(6); | ||
| }); | ||
|
|
||
|
|
||
| // Face Cards (J, Q, K) | ||
| test(`Should return 10 when given a face card`, () => { | ||
| expect(getCardValue("J♠")).toEqual(10); | ||
| expect(getCardValue("Q♥")).toEqual(10); | ||
| expect(getCardValue("K♦")).toEqual(10); | ||
| }); | ||
|
|
||
|
|
||
| // test(`Should throw an error when given an invalid card`, () => { | ||
| // expect(() => getCardValue("1♠")).toThrow(); | ||
| // expect(() => getCardValue("Z♦")).toThrow(); | ||
| // expect(() => getCardValue("11♥")).toThrow(); | ||
| // expect(() => getCardValue("")).toThrow(); | ||
| // }); | ||
|
|
||
|
Comment on lines
+45
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this code commented out? |
||
| // Invalid Cards | ||
| test(`Should throw an error when given an invalid card`, () => { | ||
| expect(() => getCardValue("1♣")).toThrow("Invalid Card"); | ||
| expect(() => getCardValue("Z♦")).toThrow("Invalid Card"); | ||
| expect(() => getCardValue("12♦")).toThrow("Invalid Card"); | ||
| expect(() => getCardValue("♦3")).toThrow("Invalid Card"); | ||
| expect(() => getCardValue("")).toThrow("Invalid Card"); | ||
| expect(() => getCardValue("invalid")).toThrow("Invalid Card"); | ||
| expect(() => getCardValue("----")).toThrow("Invalid Card"); | ||
| }); | ||
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.
I see some white spaces in the conditions that are not needed. How can you ensure consistent formatting in your code?