-
-
Notifications
You must be signed in to change notification settings - Fork 195
London|May 2025|Alexandru Pocovnicu|Coursework/sprint 3 #639
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?
London|May 2025|Alexandru Pocovnicu|Coursework/sprint 3 #639
Conversation
test("should identify reflex angle(230°)",()=>{ | ||
expect(getAngleType(230)).toEqual("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.
To ensure thorough testing, we need broad scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases.
Instead of writing tests for individual angles, consider grouping all possible input values into meaningful categories. Then, select representative samples from each category to test. This approach improves coverage and makes our tests easier to maintain. For example,
test("should identify reflex angle (180 < angle < 360)", () => {
expect(getAngleType(300)).toEqual("Reflex angle");
expect(getAngleType(359.999)).toEqual("Reflex angle");
expect(getAngleType(180.001)).toEqual("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.
thank you...is it possible to test a negative in this case, if i add 'else' it affects the other tests
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.
angle <= 0 should be considered as an invalid angle.
@@ -1,5 +1,9 @@ | |||
function isProperFraction(numerator, denominator) { | |||
if (numerator < denominator) return true; | |||
if (isNaN(numerator) || isNaN(denominator)) return NaN; |
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 return false
. Technically if any of the parameter is NaN
, then it cannot represent a proper fraction.
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.
Sorry but I do not understand, I don't seem to have this line if (numerator < denominator) return true; in my code
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 mean, instead of returning
NaN
, you could returnfalse
. -
Red-highlighted lines are removed lines, and green-highlighted lines are new additions to the file.
if (rank === "A") return 11; | ||
if(rank>=2 && rank<10)return Number(rank); |
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.
In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers. For examples, "0x02", "2.1", or "00_02".
Does your function return the value you expected from each of the following function calls?
getCardValue("0x02♠");
getCardValue("2.1♠");
getCardValue("00_02♠");
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.
getCardValue("00_02♠"); it doesn't for this one, from my understanding the result of that should be 2♠ , I wrote a test for 2♠, but i still cant figure it out, sorry
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.
In your case "00_02" should not satisfy the condition at line 5. The other two do.
A few more cases:
getCardValue("3e0♠");
getCardValue("000002♠");
You would need a stricter check to ensure rank
is one of the 9 possible number ranks before you convert it to a number.
test("should return '2nd' for 2", () => { | ||
expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
}); |
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.
Instead of writing tests for individual numbers, consider grouping all possible input values into meaningful categories. For example, we can prepare a test for numbers 2, 22, 132, etc. as
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect( getOrdinalNumber(2) ).toEqual("2nd");
expect( getOrdinalNumber(22) ).toEqual("22nd");
expect( getOrdinalNumber(132) ).toEqual("132nd");
});
Can you update the tests in this script so that they can cover all possible valid numbers?
if (isNaN(num)) { | ||
return NaN; | ||
} |
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 function is expected to return a string, so even if the parameter is not an integer, it is better to return a string instead of
NaN
. -
Could also consider using
Number.isInteger()
to check if a value is an integer.
if(count<0){ | ||
return "negative number" | ||
} |
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.
How would the caller distinguish the result of the following two function calls?
repeat("negative number", 1)
repeat("", -1)
Both function calls return the same value.
test("should repeat the string count times", () => { | ||
const str = "hello"; | ||
const count = -1; | ||
const repeatedStr = repeat(str, count); | ||
expect(repeatedStr).toEqual("negative number"); | ||
}); |
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 you modified repeat()
to throw an error when count
is negative, and you wanted to test if the function can throw an error as expected, you can use .toThrow()
. You can find out more about how to use .toThrow()
here: https://jestjs.io/docs/expect#tothrowerror (Note: Pay close attention to the syntax of the example)
const password = "123bB45%"; | ||
// Act | ||
const result = isValidPassword(password); | ||
// Assert | ||
expect(result).toEqual(true); | ||
} | ||
); No newline at end of file | ||
); | ||
test("password has at least one uppercase letter (A-Z)", () => { | ||
const password = "abcB123%"; | ||
const result = isValidPassword(password); | ||
expect(result).toEqual(true); | ||
}); | ||
test("password has at least one lowercase letter (a-z)", () => { | ||
const password = "abcB123%"; | ||
const result = isValidPassword(password); | ||
expect(result).toEqual(true); | ||
}); | ||
test("password has at least one number (0-9)", () => { | ||
const password = "abcB123%"; | ||
const result = isValidPassword(password); | ||
expect(result).toEqual(true); | ||
}); | ||
test('password has at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")', () => { | ||
const password = "abcB123%"; | ||
const result = isValidPassword(password); | ||
expect(result).toEqual(true); | ||
}); |
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.
All these tests should also check if the function can return false
when the password satisfies all other conditions except the one described in the test.
For example,
test("password has at least 5 characters", () => {
// This password contains each of the required characters but is too short
expect( isValidPassword("Aa1$") ).toEqual(false);
}
Hi, I don't know what's happening, all the files in sprint 3 from my computer are empty, as if i haven't done any work in them , is there a way I could copy the ones on github, should i clone the whole PR and then push that , will i have to create a new PR? |
never mind the previous message , sorted....i was in the wrong branch |
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.