-
-
Notifications
You must be signed in to change notification settings - Fork 283
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 3 | Coursework #878
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
32eef26
0709cbe
def5669
487694e
5fb6f95
876b8a1
801d5d8
7e6166b
dbf085f
a09a992
5f2aa2c
22f8e4a
f3f8b47
f08ec15
234e8b6
6a021e3
7455253
5e1196f
cc80d7e
ca08ca9
7dc44ec
5e720c8
252bfb9
3b7e322
809e11b
0b2a485
377b7db
096d45c
1200ba7
014b90e
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,15 +8,10 @@ | |
| // write one test at a time, and make it pass, build your solution up methodically | ||
|
|
||
| function isProperFraction(numerator, denominator) { | ||
| if (numerator < denominator) { | ||
| return true; | ||
| } | ||
| if (denominator === 0) return false; // avoid division by zero | ||
| return Math.abs(numerator) < Math.abs(denominator); | ||
| } | ||
|
Comment on lines
10
to
13
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. According to the definition of proper fraction in mathematics:
Can you look up the definition of proper fraction and update your function accordingly? |
||
|
|
||
| // 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( | ||
|
|
@@ -47,13 +42,17 @@ assertEquals(improperFraction, false); | |
| // Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true. | ||
| const negativeFraction = isProperFraction(-4, 7); | ||
| // ====> complete with your assertion | ||
| assertEquals(properFraction, true); | ||
|
|
||
| // Equal Numerator and Denominator check: | ||
| // Input: numerator = 3, denominator = 3 | ||
| // target output: false | ||
| // Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false. | ||
| const equalFraction = isProperFraction(3, 3); | ||
| // ====> complete with your assertion | ||
| assertEquals(equalFraction, false); | ||
|
|
||
| // Stretch: | ||
| // What other scenarios could you test for? | ||
|
|
||
| module.exports = isProperFraction; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,21 @@ test("should return true for a proper fraction", () => { | |
| }); | ||
|
|
||
| // Case 2: Identify Improper Fractions: | ||
| test("should return false for an improper fraction", () => { | ||
| expect(isProperFraction(5, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 3: Identify Negative Fractions: | ||
| test("should return true for a negative proper fraction", () => { | ||
| expect(isproperFraction(-4, 7)).toEqual(true); | ||
| }); | ||
|
Comment on lines
+15
to
+17
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. Could consider introduce a test for negative improper fraction to make the test more complete.
Author
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. have implemented the test for negative improper fractions. |
||
|
|
||
| // Case 4: Identify Equal Numerator and Denominator: | ||
| test ("should return false when numerator equals denominator", () => { | ||
| expect(isProperFraction(3, 3)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 5: Identify Negative Improper Fractions: | ||
| test("should return false for a negative improper fraction", () => { | ||
| expect(isProperFraction(-4, 4)).toEqual(false); | ||
| expect(isProperFraction(10, -3)).toEqual(false); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| // start a count of 0 | ||
| let count = 0; | ||
|
|
||
| // check each of the characters in the string one by one. | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| // checks if the current characters matches the one were looking for in the string. | ||
| if (stringOfCharacters[i] === findCharacter) | ||
| // if it does, we increment the count by 1. | ||
| count = count + 1; | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
| console.log(countChar("aaaaa", "a")); // 5 | ||
| console.log(countChar("hello", "l")); // 2 | ||
|
|
||
| module.exports = countChar; | ||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,26 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastTwoDigits = num % 100; // gets the last two digits of the number because some like 11, 12, 13 are special cases. | ||
| const lastDigit= num % 10; // gets the last digit to decide if its going to be "St, Nd, Rd" | ||
|
|
||
| // handles special cases like "11,12,13" to always end in the "Th" | ||
| if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13){ | ||
| return num + "th"; | ||
| } | ||
| // will return "St" if the number ends in 1. | ||
| if (lastDigit === 1){ | ||
| return num + "st"; | ||
| } | ||
| // will return "Nd" if the number ends in 2. | ||
| if (lastDigit === 2){ | ||
| return num + "nd"; | ||
| } | ||
| // will return "Rd" if the number ends in 3. | ||
| if (lastDigit === 3){ | ||
| return num + "rd"; | ||
| } | ||
|
|
||
| // will return all numbers that end in 4, 5, 6, 7, 8, 9 with "Th". | ||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,37 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
|
|
||
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect(getOrdinalNumber(21)).toEqual("21st") | ||
| expect(getOrdinalNumber(141)).toEqual("141st") | ||
| }); | ||
| // Case 2: Identify the ordinal number for 2 | ||
| // When the number is 2, | ||
| // The function should then return "2nd". | ||
|
|
||
| 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"); | ||
| }); | ||
|
|
||
| // Case 3: Identify the ordinal number for 3 | ||
| // When the number is 3, | ||
| // The Function should the return "3rd" | ||
|
|
||
| test("Should return `3rd` for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect(getOrdinalNumber(23)).toEqual("23rd"); | ||
| expect(getOrdinalNumber(133)).toEqual("133rd"); | ||
| }); | ||
|
Comment on lines
16
to
34
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. To ensure thorough testing, we need broad scenarios that cover all possible cases. For example, we can prepare a test for numbers 2, 22, 132, etc. as Can you update the tests in this script to make them more comprehensive? That is, create few test categories that can cover all possible cases?
Author
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. have updated them to have more tests to cover more possible cases |
||
| // Case 4: identify the special ordinal numbers for 11, 12, 13 | ||
| // When the number is 11, 12, 13, | ||
| // The function should return "11th, 12th, 13th" | ||
|
|
||
| test("should return `11th, 12th, 13th` for special ordinal numbers ending on these", () => { | ||
| 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"); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| // check if "count" is a negative number if so will throw new error | ||
| if (count < 0) { | ||
| throw new error("Count must be a positive number"); | ||
|
|
||
| //check if the is equal to zero | ||
| if (count === 0){ | ||
| return ""; // returns empty string if count is equal to zero | ||
| } | ||
| //check if the count is equals 1. | ||
| if (count === 1) { | ||
| //returns just the string as its not needed to be repeated | ||
| return str; | ||
| } | ||
| return str.repeat(count); // if the count is above two it repeat "count" number of times. | ||
| } | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
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.
There is no "division by zero" needs to be prevented though.
Will the function still work equally well without this if statement?
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.
yes it would still work because it would return false implicitly with out the if-statement, as im currently explicitly looking for the error having the if-statement in.