-
-
Notifications
You must be signed in to change notification settings - Fork 240
London | 25-ITP-May | Houssam Lahlah | Sprint 2 | Acoursework/sprint 3 #699
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
Changes from all commits
2dd0a78
1bc5c74
b16d048
625c114
f5522e7
2f17199
5e31d7c
5cf1cfd
2d1e8dd
4723bb9
85a7125
a6dd884
cb53f9a
5a07227
a417fa0
461d0b6
057740b
48444ef
633a7af
6d8d7bb
50eaeb4
e2c7e37
276c348
28dfefd
c3ed0d1
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 |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| // Explanation: | ||
| // It checks if the absolute value of the numerator | ||
| // is less than the absolute value of the denominator. | ||
|
|
||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) return true; | ||
| // add your completed function from key-implement here | ||
| if (denominator === 0) { | ||
| throw new Error("Denominator cannot be zero"); | ||
| } | ||
|
|
||
| return Math.abs(numerator) < Math.abs(denominator); | ||
| } | ||
|
|
||
| module.exports = isProperFraction; | ||
| module.exports = isProperFraction; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| function getCardValue(card) { | ||
| // replace with your code from key-implement | ||
| return 11; | ||
| const rank = card.slice(0, -1); // All characters except the last one (suit) | ||
|
|
||
| if (!rank) throw new Error("Invalid card rank"); | ||
|
|
||
| if (rank === "A") return 11; | ||
| if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
|
|
||
| const number = Number(rank); | ||
| if (number >= 2 && number <= 9) return number; | ||
|
|
||
| throw new Error("Invalid card rank"); | ||
| } | ||
| module.exports = getCardValue; | ||
|
|
||
| module.exports = getCardValue; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,33 @@ | ||
| const getCardValue = require("./3-get-card-value"); | ||
|
|
||
| test("should return 11 for Ace of Spades", () => { | ||
| const aceofSpades = getCardValue("A♠"); | ||
| expect(aceofSpades).toEqual(11); | ||
| }); | ||
|
|
||
| // Case 2: Handle Number Cards (2-10): | ||
| // Case 3: Handle Face Cards (J, Q, K): | ||
| // Case 4: Handle Ace (A): | ||
| // Case 5: Handle Invalid Cards: | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| }); | ||
|
|
||
| // Case 2: Handle Number Cards (2-10) | ||
| test("should return 5 for Five of Hearts", () => { | ||
| expect(getCardValue("5♥")).toEqual(5); | ||
| }); | ||
|
|
||
| test("should return 10 for Ten of Diamonds", () => { | ||
| expect(getCardValue("10♦")).toEqual(10); | ||
| }); | ||
|
Comment on lines
+8
to
+14
Contributor
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. When preparing tests, we should ensure the tests cover all possible cases. If we specify a test for individual card, we will need about 53 tests to cover all possible cases. Instead, we could consider classifying all possible values into different categories, and then within each category we test some samples. For example, one possible category for |
||
|
|
||
| // Case 3: Handle Face Cards (J, Q, K) | ||
| test("should return 10 for Jack of Clubs", () => { | ||
| expect(getCardValue("J♣")).toEqual(10); | ||
| }); | ||
|
|
||
| test("should return 10 for Queen of Spades", () => { | ||
| expect(getCardValue("Q♠")).toEqual(10); | ||
| }); | ||
|
|
||
| test("should return 10 for King of Hearts", () => { | ||
| expect(getCardValue("K♥")).toEqual(10); | ||
| }); | ||
|
Comment on lines
+17
to
+27
Contributor
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. We could generalise this test to "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K). |
||
|
|
||
| // Case 5: Handle Invalid Cards | ||
| test("should throw an error for invalid card rank", () => { | ||
| expect(() => getCardValue("Z♣")).toThrow("Invalid card rank"); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
| for (let char of stringOfCharacters) { | ||
| if (char === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const suffixes = ["th", "st", "nd", "rd"]; | ||
| const value = num % 100; | ||
| if (value >= 11 && value <= 13) { | ||
| return num + "th"; | ||
| } | ||
| const lastDigit = num % 10; | ||
| const suffix = suffixes[lastDigit] || "th"; | ||
| return num + suffix; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,20 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
| test("should return '4th' for 4", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| }); | ||
|
|
||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
|
Comment on lines
+14
to
+29
Contributor
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. These tests are not comprehensive; they do not quite cover all possible cases. To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases. For example, we can prepare a test for numbers 2, 22, 132, etc. as |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Count must be non-negative"); | ||
| } | ||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
| module.exports = repeat; |
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.
Does your function return the value you expected from each of the following function calls?