-
-
Notifications
You must be signed in to change notification settings - Fork 239
Birmingham | 25-ITP-Sep | Joy Opachavalit | Sprint 3 | coursework/sprint-3 #775
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
97d02c7
bf6c370
1a47995
3be3bfb
a7b7c2f
e110722
716f047
138843b
4879aaa
d34d343
4d61885
989855e
56625ec
47e385f
45dc764
00e6c6d
35b6637
eb1d90f
2f42a85
6db1bca
8f61c0f
0e834a6
f14ec50
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 |
|---|---|---|
|
|
@@ -8,6 +8,59 @@ test("should return 11 for Ace of Spades", () => { | |
| }); | ||
|
|
||
| // Case 2: Handle Number Cards (2-10): | ||
| test("should return numeric value for number cards (2-10)", () => { | ||
| const fiveofHearts = getCardValue("5♥"); | ||
| expect(fiveofHearts).toEqual(5); | ||
| }); | ||
|
Comment on lines
+11
to
+14
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. Could consider testing more sample values in each category (to make the test more comprehensive), especially the boundary cases such as "2♥" and "10♥". 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. Added more tests, especially the boundary cases such as "2♥" and "10♥." |
||
| // Case 3: Handle Face Cards (J, Q, K): | ||
| test("should return 10 for face cards (J, Q, K)", () => { | ||
| const jackOfDiamonds = getCardValue("J♦"); | ||
| const queenOfClubs = getCardValue("Q♣"); | ||
| const kingOfHearts = getCardValue("K♥"); | ||
| expect(jackOfDiamonds).toEqual(10); | ||
| expect(queenOfClubs).toEqual(10); | ||
| expect(kingOfHearts).toEqual(10); | ||
| }); | ||
|
|
||
| // Case 4: Handle Ace (A): | ||
| test("should return 11 for Ace (A)", () => { | ||
| const aceOfSpades = getCardValue("A♠"); | ||
| expect(aceOfSpades).toEqual(11); | ||
| }); | ||
|
|
||
| // Case 5: Handle Invalid Cards: | ||
| test("should return undefined for invalid cards", () => { | ||
| const invalidCard = getCardValue("1♠"); | ||
| expect(invalidCard).toEqual(undefined); | ||
| }); | ||
|
|
||
| test("should return correct value for all number cards 2-10", () => { | ||
| expect(getCardValue("2♥")).toEqual(2); | ||
| expect(getCardValue("3♣")).toEqual(3); | ||
| expect(getCardValue("4♦")).toEqual(4); | ||
| expect(getCardValue("5♠")).toEqual(5); | ||
| expect(getCardValue("6♥")).toEqual(6); | ||
| expect(getCardValue("7♣")).toEqual(7); | ||
| expect(getCardValue("8♦")).toEqual(8); | ||
| expect(getCardValue("9♠")).toEqual(9); | ||
| expect(getCardValue("10♥")).toEqual(10); | ||
| }); | ||
|
|
||
| test("should handle numeric-literal edge cases", () => { | ||
| expect(getCardValue("0x02♠")).toEqual(2); | ||
| expect(getCardValue("2.1♠")).toBeUndefined(); | ||
| expect(getCardValue("0002♠")).toEqual(2); | ||
| }); | ||
|
|
||
| test("should return 10 for all face cards", () => { | ||
| expect(getCardValue("J♠")).toEqual(10); | ||
| expect(getCardValue("Q♥")).toEqual(10); | ||
| expect(getCardValue("K♣")).toEqual(10); | ||
| }); | ||
|
|
||
| test("should return 11 for all Aces", () => { | ||
| expect(getCardValue("A♠")).toEqual(11); | ||
| expect(getCardValue("A♥")).toEqual(11); | ||
| expect(getCardValue("A♦")).toEqual(11); | ||
| expect(getCardValue("A♣")).toEqual(11); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
|
|
||
| // Loop through each character in the string | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| // If the current character matches the character we're looking for | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| // Handle special cases for teens (11th, 12th, 13th) | ||
| if (num % 100 >= 11 && num % 100 <= 13) { | ||
| return num + "th"; | ||
| } | ||
|
|
||
| // Handle based on last digit | ||
| const lastDigit = num % 10; | ||
|
|
||
| if (lastDigit === 1) { | ||
| return num + "st"; | ||
| } else if (lastDigit === 2) { | ||
| return num + "nd"; | ||
| } else if (lastDigit === 3) { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,45 @@ | ||
| const getOrdinalNumber = require("./get-ordinal-number"); | ||
| // In this week's prep, we started implementing getOrdinalNumber | ||
|
|
||
| // continue testing and implementing getOrdinalNumber for additional cases | ||
| // Write your tests using Jest - remember to run your tests often for continual feedback | ||
| const getOrdinalNumber = require("./get-ordinal-number"); | ||
|
|
||
| // Case 1: Identify the ordinal number for 1 | ||
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
| // To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases. | ||
| // Instead of writing tests for individual numbers, we group all possible input values into meaningful categories and select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain. | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| // Numbers ending in 1 (except those ending in 11): should append 'st' | ||
| test("append 'st' to numbers ending in 1, except those ending in 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st"); | ||
| expect(getOrdinalNumber(101)).toEqual("101st"); | ||
| }); | ||
|
|
||
| // Numbers ending in 2 (except those ending in 12): should append 'nd' | ||
| test("append 'nd' to numbers ending in 2, except those ending in 12", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| expect(getOrdinalNumber(22)).toEqual("22nd"); | ||
| expect(getOrdinalNumber(132)).toEqual("132nd"); | ||
| }); | ||
|
|
||
| // Numbers ending in 3 (except those ending in 13): should append 'rd' | ||
| test("append 'rd' to numbers ending in 3, except those ending in 13", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| expect(getOrdinalNumber(103)).toEqual("103rd"); | ||
| }); | ||
|
|
||
| // Numbers ending in 11, 12, 13: should append 'th' | ||
| test("append 'th' to numbers ending in 11, 12, 13", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| expect(getOrdinalNumber(111)).toEqual("111th"); | ||
| expect(getOrdinalNumber(112)).toEqual("112th"); | ||
| expect(getOrdinalNumber(113)).toEqual("113th"); | ||
| }); | ||
|
|
||
| // All other numbers: should append 'th' | ||
| test("append 'th' to all other numbers", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect(getOrdinalNumber(10)).toEqual("10th"); | ||
| expect(getOrdinalNumber(14)).toEqual("14th"); | ||
| expect(getOrdinalNumber(0)).toEqual("0th"); | ||
| }); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,20 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| // Handle edge cases | ||
| if (count < 0) { | ||
| throw new Error("Count cannot be negative"); | ||
| } | ||
|
|
||
| if (count === 0) { | ||
| return ""; | ||
| } | ||
|
|
||
| // Build the repeated string | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| 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.
In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. To see some examples, you can request AI to show you all forms of string values in JS, when converted to a number, equals to an integer 2.
Do you want these kinds of strings be recognized as valid ranks?
Hint; Validate the string value before converting its value.