Cape Town | 26-ITP-Jan | Pretty Taruvinga | Sprint 1 | Data Groups#1104
Cape Town | 26-ITP-Jan | Pretty Taruvinga | Sprint 1 | Data Groups#1104Pretty548 wants to merge 19 commits intoCodeYourFuture:mainfrom
Conversation
…om>fix: correct calculateMedian implementation and handle non-array inputs
This comment has been minimized.
This comment has been minimized.
…om>Add reference check to ensure dedupe returns a copy of the array
| test("Given an array with no duplicates, when passed to the dedupe function, then it should return a copy of the original array", () => { | ||
| const input = ["a", "b", "c"]; | ||
| const result = dedupe(input); | ||
|
|
||
| expect(result).toEqual(input); | ||
| expect(result).not.toBe(input); | ||
| }); |
There was a problem hiding this comment.
There is a chance that, even though result has incorrect elements (for example, []),
the two tests could still pass. Can you figure out why, and then fix the tests accordingly?
There was a problem hiding this comment.
Thanks for pointing this out!
You're right — the current test isn't strict enough. It only checks that result is equal to input and that it's a different reference, but it doesn't explicitly verify the contents or length of the array. This means a faulty implementation could potentially pass the test under certain conditions.
To fix this, I strengthened the test by adding checks for the array length and ensuring the expected elements are present. This makes the test more robust and prevents false positives.
Let me know if you'd like me to add more edge case tests as well!
Learners, PR Template
Self checklist
Changelist