-
-
Notifications
You must be signed in to change notification settings - Fork 196
London | May-2025 | Reza Jahanimir | Sprint-3 #576
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 6 commits
41faaac
fb392b3
52148a6
4d0497e
13220cd
396094b
ccf0768
686efb6
435f1dd
cb18deb
c13ebd3
37f8608
af01c38
2b3e360
8dd332e
e80b220
d32bc0c
ce330dd
c969da7
95c85ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. Can your function pass the tests you specified in this script? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
const isProperFraction = require("./2-is-proper-fraction"); | ||
|
||
|
||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(2, 3)).toEqual(true); | ||
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
test("should return false for an Improper fraction", () => { | ||
expect(isProperFraction(6, 3)).toEqual(false); | ||
}); | ||
|
||
test("should return false for a negative improper fraction", () => { | ||
expect(isProperFraction(-7, 4)).toEqual(false); | ||
}); | ||
|
||
// Case 3: Identify Negative Fractions: | ||
test("should return true for a negative proper fraction", () => { | ||
expect(isProperFraction(3, -5)).toEqual(true); | ||
expect(isProperFraction(-3, 5)).toEqual(true); | ||
}); | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
test("should return false for equal numerator and denominator", () => { | ||
expect(isEqualNumeratorAndDenominator(5, 5)).toEqual(false); | ||
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 also include all combinations of +ve and -ve cases.
|
||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
|
||
} | ||
const rank = card.slice(0, -1); | ||
if (rank === "A") return 11; | ||
(["K", "Q", "J", "10"].includes(rank)) return 10; | ||
(!isNaN(rank) && rank >= 2 && rank <= 9) return Number(rank); | ||
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. Does your function return the value you expected from each of the following function calls?
|
||
throw new Error("Invalid card rank"); | ||
|
||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
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: | ||
|
||
|
||
test("should return the correct value for number cards (2-10)", () => { | ||
expect(getCardValue("2♦")).toEqual(2); | ||
expect(getCardValue("5♣")).toEqual(5); | ||
expect(getCardValue("10♥")).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for face cards (J, Q, K)", () => { | ||
expect(getCardValue("J♠")).toEqual(10); | ||
expect(getCardValue("Q♦")).toEqual(10); | ||
expect(getCardValue("K♣")).toEqual(10); | ||
}); | ||
test("should return 11 for Ace", () => { | ||
expect(getCardValue("A♠")).toEqual(11); | ||
expect(getCardValue("A♣")).toEqual(11); | ||
expect(getCardValue("A♦")).toEqual(11); | ||
}); | ||
|
||
test("should throw an error for invalid cards", () => { | ||
expect(() => getCardValue("1♠")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("Z♦")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("15♥")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("X♣")).toThrow("Invalid card rank"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
//return 5 | ||
return stringOfCharacters.split(findCharacter).length - 1; | ||
} | ||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,32 @@ test("should count multiple occurrences of a character", () => { | |
// And a character char that does not exist within the case-sensitive str, | ||
// When the function is called with these inputs, | ||
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str. | ||
|
||
test("should return 0 when the character is not found", () => { | ||
const str = "hello"; | ||
const char = "z"; | ||
const count = countChar(str, char); | ||
expect(count).toEqual(0); | ||
}); | ||
|
||
test("should be case-sensitive", () => { | ||
const str = "Millena"; | ||
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. Consider including some |
||
const char = "m"; | ||
const count = countChar(str, char); | ||
expect(count).toEqual(0); | ||
}); | ||
|
||
|
||
test("should count spaces as characters", () => { | ||
const str = "Millena Mesfin"; | ||
const char = " "; | ||
const count = countChar(str, char); | ||
expect(count).toEqual(1); | ||
}); | ||
|
||
test("should return 0 for an empty string", () => { | ||
const str = ""; | ||
const char = "m"; | ||
const count = countChar(str, char); | ||
expect(count).toEqual(0); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
} | ||
if (num < 1 || !Number.isInteger(num)) throw new Error("Input must be a positive integer"); | ||
|
||
const specialCases = [11, 12, 13]; | ||
const suffixes = ["th", "st", "nd", "rd"]; | ||
const lastDigit = num % 10; | ||
const lastTwoDigits = num % 100; | ||
|
||
return num + (specialCases.includes(lastTwoDigits) ? "th" : suffixes[lastDigit] || "th"); | ||
} | ||
|
||
|
||
|
||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,46 @@ 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"); | ||
}); | ||
|
||
test("should return '12th' for 12", () => { | ||
expect(getOrdinalNumber(12)).toEqual("12th"); | ||
}); | ||
|
||
test("should return '13th' for 13", () => { | ||
expect(getOrdinalNumber(13)).toEqual("13th"); | ||
}); | ||
|
||
test("should return '21st' for 21", () => { | ||
expect(getOrdinalNumber(21)).toEqual("21st"); | ||
}); | ||
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. Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories. Then, select representative samples from each category to test. This approach improves coverage and makes your tests easier to maintain. For example, we can prepare a test for numbers 1, 21, 131, etc. as
|
||
|
||
test("should return '102nd' for 102", () => { | ||
expect(getOrdinalNumber(102)).toEqual("102nd"); | ||
}); | ||
|
||
test("should return '113th' for 113", () => { | ||
expect(getOrdinalNumber(113)).toEqual("113th"); | ||
}); | ||
|
||
test("should return '101st' for 101", () => { | ||
expect(getOrdinalNumber(101)).toEqual("101st"); | ||
}); | ||
|
||
test("should return '1000th' for 1000", () => { | ||
expect(getOrdinalNumber(1000)).toEqual("1000th"); | ||
}); |
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.
The spec isn't clear whether
angle
can be assigned a number not in the interval (0, 360).When
angle
is >= 360, what should the function return? (Also, by definition, angles <= 0 are not considered acute angles.)When we implement a function that can return a value, to ensure reliability, we should ensure it will always return a defined value instead of
undefined
(which represents "no return value").If the parameter,
angle
, is not within the recognised range, we can design the function to return a special value (e.g., "Invalid angle") or throw an error.