Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Fatimasfn
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@Fatimasfn Fatimasfn added the Needs Review Participant to add when requesting review label Dec 21, 2024
@cjyuan cjyuan added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Dec 22, 2024
Copy link

@cjyuan cjyuan left a 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.

function getAngleType(angle) {
if (angle === 90) {
return "Right angle"
} else if ( angle < 90) {
Copy link

@cjyuan cjyuan Dec 22, 2024

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.

Comment on lines 35 to 49
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";

}
Copy link

@cjyuan cjyuan Dec 22, 2024

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♠")

Comment on lines 16 to 20
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");
});
Copy link

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?

Comment on lines +8 to +14
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");
});
Copy link

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.

Comment on lines +1 to +8
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', () => {
Copy link

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++ ) {
Copy link

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

Comment on lines +19 to +21
if (password.length >= 5){
return true
} else if (password.length < 5)
Copy link

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 {
}

Comment on lines +100 to +104
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);
Copy link

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));
Copy link

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)

// 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
Copy link

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.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Dec 22, 2024
@Fatimasfn
Copy link
Author

I left some comments and suggestions in your code.

Thank you for reviewing, I will implement the suggestions.

@Fatimasfn Fatimasfn added Complete Participant to add when work is complete and review comments have been addressed and removed Reviewed Volunteer to add when completing a review labels Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Participant to add when work is complete and review comments have been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants