-
-
Notifications
You must be signed in to change notification settings - Fork 195
Glasgow | ITP May -25 | Pandi Simatupang | Module-Structuring-and-Testing-Data | coursework/sprint-3 #651
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?
Glasgow | ITP May -25 | Pandi Simatupang | Module-Structuring-and-Testing-Data | coursework/sprint-3 #651
Changes from all commits
0d3ab26
8ca1698
9486542
e895328
a0c7003
0769e0b
b3f7e1c
dde0d24
b4f0f0c
2c54885
8587494
8781fe7
d981134
a2f5474
2698473
a4bcc75
b17787c
75516af
4e98474
c4f73a6
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 | ||
|
||
else if (angle === 180) return "Straight angle"; | ||
// read to the end, complete line 36, then pass your test here | ||
else if (angle < 90) return "Acute angle"; | ||
else if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
else return "Reflex angle"; | ||
} | ||
Comment on lines
+4
to
9
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. Same as above. 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. already done.. |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 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,24 +1,23 @@ | ||
const getAngleType = require("./1-get-angle-type"); | ||
|
||
test("should identify right angle (90°)", () => { | ||
test("testing for multiple different angles", () => { | ||
// REPLACE the comments with the tests | ||
// make your test descriptions as clear and readable as possible | ||
|
||
// Case 2: Identify Acute Angles: | ||
// When the angle is less than 90 degrees, | ||
// Then the function should return "Acute angle" | ||
expect(getAngleType(90)).toEqual("Right angle"); | ||
// Case 3: Identify Obtuse Angles: | ||
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
expect(getAngleType(120)).toEqual("Obtuse angle"); | ||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
expect(getAngleType(180)).toEqual("Straight angle"); | ||
// Case 5: Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" | ||
expect(getAngleType(300)).toEqual("Reflex angle"); | ||
}); | ||
|
||
// REPLACE the comments with the tests | ||
// make your test descriptions as clear and readable as possible | ||
|
||
// Case 2: Identify Acute Angles: | ||
// When the angle is less than 90 degrees, | ||
// Then the function should return "Acute angle" | ||
|
||
// Case 3: Identify Obtuse Angles: | ||
// When the angle is greater than 90 degrees and less than 180 degrees, | ||
// Then the function should return "Obtuse angle" | ||
|
||
// Case 4: Identify Straight Angles: | ||
// When the angle is exactly 180 degrees, | ||
// Then the function should return "Straight angle" | ||
|
||
// Case 5: Identify Reflex Angles: | ||
// When the angle is greater than 180 degrees and less than 360 degrees, | ||
// Then the function should return "Reflex angle" |
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. That is really good, it is my preferred style of writing such a function, as subjective is it may be. It is easy to read and understand at a glance at what is happening, and each line represents a condition. So if you are reading the code trying to work out what will happen if a specific value is passed into the function, it is really easy to read each condition and determine the outcome, all in a matter of seconds and without having to run the code. Good job here, I like this! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
//if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
|
||
if (numerator === 0 || denominator === 0) return false; | ||
if (numerator === denominator) return false; | ||
if (Math.abs(numerator) < Math.abs(denominator)) return true; | ||
if (Math.abs(numerator) > Math.abs(denominator)) return false; | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
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; | ||
// replace with your code from key-implement | ||
//return 11; | ||
let rank = card.slice(0, -1); //start from 0 until just before one last character | ||
if (rank === "A") return 11; | ||
else if ((rank === "10") | (rank === "J") | (rank === "Q") | (rank === "K")) | ||
return 10; | ||
else if (rank > 1 && rank < 10) return Number(rank); | ||
//need to convert to number, because === compare type and exact number | ||
else return null; | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
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); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return 5 for Ace of Spades", () => { | ||
const fiveSpades = getCardValue("5♠"); | ||
expect(fiveSpades).toEqual(5); | ||
}); | ||
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for K of Spades", () => { | ||
const KSpades = getCardValue("K♠"); | ||
expect(KSpades).toEqual(10); | ||
}); | ||
|
||
// Case 4: Handle Ace (A): | ||
test("should return 11 for A of Spades", () => { | ||
const ASpades = getCardValue("A♠"); | ||
expect(ASpades).toEqual(11); | ||
}); | ||
// Case 5: Handle Invalid Cards: | ||
test("should return null for 17 of Spades", () => { | ||
const invalidCard = getCardValue("17♠"); | ||
expect(invalidCard).toEqual(null); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let numberOfFindChar = 0; | ||
let lengthOfString = stringOfCharacters.length; | ||
for (let i = 0; i < lengthOfString; i++) { | ||
if (findCharacter === stringOfCharacters[i]) numberOfFindChar++; | ||
} | ||
return numberOfFindChar; | ||
} | ||
|
||
module.exports = countChar; | ||
//console.log(countChar("aaaaaaaaaaaaaaaaaaaaabaaaa", "b")); | ||
|
||
module.exports = countChar; |
Uh oh!
There was an error while loading. Please reload this page.
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.
Nice, that is a good solution, it is easier to read already. If you check this part of the Switch documentation, do you think this could be useful for your code? Can it be useful perhaps on other files from this PR?