-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
WM4 | Fatima Safana | Module-Structuring-and-Testing-Data | WEEK6 #235
base: main
Are you sure you want to change the base?
Conversation
-test files -implemented function get-angle-type.js
-tested the isProperFraction
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.
I left some comments and suggestions in your code.
Sprint-3/implement/get-angle-type.js
Outdated
function getAngleType(angle) { | ||
if (angle === 90) { | ||
return "Right angle" | ||
} else if ( angle < 90) { |
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 does not give an exact specification of acute angle.
By definition, an acute angle cannot be less than or equal to 0.
Sprint-3/implement/get-card-value.js
Outdated
function getCardValue(card) { | ||
const singleDigitRank = Number(card.substring(0,1)); | ||
// const doubleDigitRank = Number(card.substring(0,2)); | ||
|
||
if (card.startsWith("10")){ | ||
return 10; | ||
} else if (singleDigitRank >= 2 && singleDigitRank <=9){ | ||
return singleDigitRank; | ||
} else if (card.startsWith("J") || card.startsWith("Q") || card.startsWith("K")){ | ||
return 10; | ||
} else if (card.startsWith("A")){ | ||
return 11 | ||
} else return "Invalid Cards"; | ||
|
||
} |
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.
What do you expect from the following function calls?
Does your function return the value you expected?
getCardValue("99Q♠");
getCardValue("100♠");
getCardValue("2K♠");
getCardValue("KK♠");
getCardValue("AA♠")
test('Given numerator and denominator, return the type of fraction', () => { | ||
expect(isProperFraction(2, 3)).toBe(true); | ||
expect(isProperFraction(5, 3)).toBe(false); | ||
expect(isProperFraction(2, 0)).toBe("error"); | ||
}); |
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.
Why not test also cases where numerator and/or denominator are negative values?
test('Given an angle in degrees, return the type of angle', () => { | ||
expect(getAngleType(90)).toBe("Right angle"); | ||
expect(getAngleType(45)).toBe("Acute angle"); | ||
expect(getAngleType(160)).toBe("Obtuse angle"); | ||
expect(getAngleType(180)).toBe("Straight angle"); | ||
expect(getAngleType(300)).toBe("Reflex angle"); | ||
}); |
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.
Could also test invalid cases.
const getAngleType = require('./get-angle-type.js'); | ||
const isProperFraction = require('./is-proper-fraction.js'); | ||
const isValidTriangle = require('./is-valid-triangle.js'); | ||
const getCardValue = require('./get-card-value.js'); | ||
|
||
|
||
|
||
test('Given an angle in degrees, return the type of angle', () => { |
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.
It is better to use separate .test.js
file for each unit test.
return true | ||
} else if ((num > 2)) { | ||
let squareRootNum = Math.sqrt(num) | ||
for (let i = 2 ; i <= squareRootNum; i++ ) { |
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.
Can further speed up the performance in the following manner:
- return false if
num
is an even number - check only odd divisors in the loop
if (password.length >= 5){ | ||
return true | ||
} else if (password.length < 5) |
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.
if (condition) {
}
else if (! condition) { // Opposite condition
}
can be simplified as
if (condition) {
}
else {
}
test('if password is a valid password.', () => { | ||
expect(isValidPassword("abcd")).toBe(false); | ||
expect(isValidPassword("Abc!")).toBe(false); | ||
expect(isValidPassword("ABCD1")).toBe(false); | ||
expect(isValidPassword("Dog!")).toBe(false); |
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.
These tests are not comprehensive, and they could not indicate exactly why the function fails. A better way to prepare the tests are in the following manner:
test('Check password without an uppercase letter', () => {
expect(isValidPassword("1a!123")).toBe(false);
expect(isValidPassword("za123!")).toBe(false);
});
test('Check passwords without a digit', () => {
expect(isValidPassword("!!aABC")).toBe(false);
expect(isValidPassword("Abaaa!")).toBe(false);
});
...
A comprehensive test can help you detect bugs in isValidPassword()
.
} return ""; | ||
} | ||
|
||
console.log(repeat("cat", 3)); |
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 isn't any Jest test specified in this file.
What do you expect from the following function calls?
repeat("", -1)
repeat("count cant be negative", 1)
Sprint-3/revise/investigate/find.js
Outdated
// d) What is the condition index < str.length used for? | ||
//the condition checks all indexes are checked. the check keeps iterating until it finds a matching value or index is less than str length |
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.
Your answer to question (d) seems like a description of what the while loop is doing, and not specifically why the loop condition is specified as index < str.length
.
Thank you for reviewing, I will implement the suggestions. |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.