-
-
Notifications
You must be signed in to change notification settings - Fork 195
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 15 commits
65fe894
532fd66
0cba6bb
8d6eb95
2479c4f
3fafedf
7a5fe08
68f5551
5dd3b88
62ef41d
1443cbf
1e2318b
edea881
dbf4e92
fad2100
1154f89
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,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,7 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (Math.abs(numerator) < Math.abs(denominator)) return true; // This version of code works correctly for proper and negative fractions. | ||
if (Math.abs(numerator) >= Math.abs(denominator)) return false; | ||
if (Math.abs(numerator) === Math.abs(denominator)) return 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. Can you use |
||
|
||
module.exports = isProperFraction; | ||
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 |
||
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,9 +1,40 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
test("should return 5 for 5 of Hearts", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
|
||
test("should return 10 for 10 of Diamonds", () => { | ||
const tenofDiamonds = getCardValue("10♦"); | ||
expect(tenofDiamonds).toEqual(10); | ||
}); | ||
Comment on lines
+8
to
+16
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
|
||
|
||
test("should return 10 for Jack of Clubs", () => { | ||
const jackofClubs = getCardValue("J♣"); | ||
expect(jackofClubs).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for Queen of Hearts", () => { | ||
const queenofHearts = getCardValue("Q♥"); | ||
expect(queenofHearts).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for King of Spades", () => { | ||
const kingofSpades = getCardValue("K♠"); | ||
expect(kingofSpades).toEqual(10); | ||
}); | ||
Comment on lines
+18
to
+31
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 combine these tests and place them under the category "should return 10 for face cards (J, Q, K)". |
||
|
||
try { | ||
getCardValue("Z♠"); | ||
} catch (error) { | ||
console.log("Caught error:", error.message); | ||
} | ||
Comment on lines
+33
to
+37
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. Jest offers a method called You can find out more about how to use |
||
|
||
// Case 2: Handle Number Cards (2-10): | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
|
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,11 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
if (num === 1) { | ||
return "1st"; | ||
} | ||
Comment on lines
+2
to
+4
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. This function is not fully implemented; it should work for any valid positive integers. Consider looking up the rules to clarify how ordinal numbers are formed. |
||
} | ||
console.log(getOrdinalNumber(1)); // The output should be "1st" | ||
|
||
module.exports = getOrdinalNumber; | ||
// 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; |
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. Why not update the tests in |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(word, times) { | ||
return word.repeat(times); | ||
} | ||
console.log(repeat("hello", 3)); // The output should be "hellohellohello" | ||
|
||
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.
Technically angles less than or equal to 0 are also considered "Invalid angle".