-
-
Notifications
You must be signed in to change notification settings - Fork 195
London|MAY_2025|FATMA_DEGIRMENCI|STRUCTRING_AND_TESTING_DATA| SPRINT 3 #640
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?
Conversation
if (angle === 90) { | ||
return "Right angle"; | ||
} else if (angle < 90) { | ||
return "Acute angle"; | ||
} else if (angle > 90 && angle < 180) { | ||
return "Obtuse angle"; | ||
} else if (angle === 180) { | ||
return "Straight angle"; | ||
} else if (angle > 180 && angle < 360) { | ||
return "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.
The spec isn't clear whether angle
can be assigned a number not in the interval (0, 360).
When angle
is >= 360, what should the function return? (Also, by definition, angles <= 0 are not considered acute angles.)
When we implement a function that can return a value, to ensure reliability, we should ensure it will always return a defined value instead of undefined
(which represents "no return value").
If the parameter, angle
, is not within the recognised range, we can design the function to return a special value (e.g., "Invalid angle") or throw an error.
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (denominator === 0) { | ||
return undefined; |
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.
-
Returning
undefined
in JS has the same meaning as "no return value". -
We could also return
false
when the parameters cannot form a proper fraction. Technically, 1/0 or 0/1 are not proper fractions.
if (Number(rank) <= 10 && Number(rank) >= 2) { | ||
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♠");
test("should return 4 for 4 of Hearts", () => { | ||
expect(getCardValue("4♠")).toEqual(4); | ||
}); |
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.
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 getCardValue()
is, "should return the value of number cards (2-10)", and we can prepare the test as
test("should return the value of number cards (2-10)", () => {
expect(getCardValue("2♣︎")).toEqual(2);
expect(getCardValue("5♠")).toEqual(5);
expect(getCardValue("10♥")).toEqual(5);
// Note: We could also use a loop to check all values from 2 to 10.
});
test("should return 10 for Queen of Spades", () => { | ||
expect(getCardValue("Q♠")).toEqual(10); | ||
}); |
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.
We could generalise this test to "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K.
if (n > 3 && n < 21) return n + "th"; | ||
switch (n % 10) { | ||
case 1: | ||
return n + "st"; | ||
case 2: | ||
return n + "nd"; | ||
case 3: | ||
return n + "rd"; | ||
default: | ||
return n + "th"; | ||
} |
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.
getOrdinalNumber(511)
should return "511th".
Consider looking up the rules to clarify how ordinal numbers are formed.
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.
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 numbers, 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, 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 valid integers?
function isValidPassword(password) { | ||
const previousPasswords = ["abcD1*", "Fatma123.", "App23$"]; |
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.
-
Avoid using invalid passwords as one of previous passwords.
-
Could also consider accepting
previousPasswords
array through the 2nd parameter so that the callers have the flexibility to specify previous passwords.
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 tests in this script 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);
}
…g with 11, 12, and 13 correctly
Self checklist