-
-
Notifications
You must be signed in to change notification settings - Fork 196
WESTMIDLANDS | ITP-MAY-25 | AHMAD EHSAS | MODULE STRUCTURING AND TESTING DATA SPRINT-3 #656
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 25 commits
65fe894
532fd66
0cba6bb
8d6eb95
2479c4f
3fafedf
7a5fe08
68f5551
5dd3b88
62ef41d
1443cbf
1e2318b
edea881
dbf4e92
fad2100
1154f89
047df5d
ba0f73e
5aeb5c0
550f44d
e76a59c
3415822
bf5f7f8
4f1e86a
e5699a5
63d4861
e749f57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
if (angle < 90) return "Acute angle"; | ||
if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle > 180 && angle < 360) return "Reflex angle"; | ||
|
||
return "Invalid angle"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// Don't get bogged down in this detail | ||
// Jest uses CommonJS module syntax by default as it's quite old | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// we have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (denominator === 0) { | ||
return false; | ||
} else if (Math.abs(numerator) < Math.abs(denominator)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = isProperFraction; | ||
// This version of code works correctly for proper and negative fractions. | ||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); // get the value part: A, 2–10, J, Q, K | ||
|
||
if (rank === "A") return 11; | ||
if (["K", "Q", "J"].includes(rank)) return 10; | ||
|
||
const number = parseInt(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?
Consider looking up how 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. Yes, the function returns the card value based on the card's 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. 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.
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. As 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 objective of the function is to determine the value of the rank of a card. If you were to design a card game, would you allow the card to be displayed as |
||
if (!isNaN(number) && number >= 2 && number <= 10) return number; | ||
|
||
throw new Error("Invalid card"); | ||
} | ||
module.exports = getCardValue; | ||
|
||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let count = 0; // start a count with 0 | ||
for (let char of stringOfCharacters) { | ||
// repeat for each character in the string | ||
if (char === findCharacter) { | ||
// check if the character matches the one we are looking for. | ||
count++; // if it does increase the count by 1. | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
console.log(countChar("aAaAaAaAa", "a")); // example usage should return 5. | ||
|
||
module.exports = countChar; | ||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
function getOrdinalNumber(n) { | ||
let ord = "th"; | ||
|
||
if (n % 10 == 1 && n % 100 != 11) { | ||
ord = "st"; | ||
} else if (n % 10 == 2 && n % 100 != 12) { | ||
ord = "nd"; | ||
} else if (n % 10 == 3 && n % 100 != 13) { | ||
ord = "rd"; | ||
} | ||
|
||
return n + ord; | ||
} | ||
console.log(getOrdinalNumber(1)); // The output should be "1st" | ||
|
||
// in this function, we got the ordinal number for 1. | ||
// we used a simple if statement to check if the number is 1 and return "1st". | ||
|
||
module.exports = getOrdinalNumber; | ||
module.exports = getOrdinalNumber; |
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 tests in this Jest script are incomplete. When you have fully implemented the function in Group all possible input values into meaningful categories, and then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain. For example, we can prepare a test for numbers 2, 22, 132, etc. as
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 you update the tests in this script so that they cover all valid integers? |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
// When the number is 1, | ||
// Then the function should return "1st" | ||
|
||
test("should return '1st' for 1", () => { | ||
expect(getOrdinalNumber(1)).toEqual("1st"); | ||
}); | ||
//test("should return '1st' for 1", () => { | ||
//expect(getOrdinalNumber(1)).toEqual("1st"); | ||
//}); | ||
|
||
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(121)).toEqual("121st"); | ||
}); | ||
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 you update the tests in this script so that they cover all valid integers? |
Uh oh!
There was an error while loading. Please reload this page.