Skip to content

Commit

Permalink
test(uniq): write additional test codes for uniq function
Browse files Browse the repository at this point in the history
  • Loading branch information
ho991217 committed Jun 13, 2024
1 parent ec4e2b2 commit e78a790
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/array/uniq.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,35 @@ describe('uniq', () => {
it('uniq function creates unique elements from the array passed as an argument.', () => {
expect(uniq([11, 2, 3, 44, 11, 2, 3])).toEqual([11, 2, 3, 44]);
});
it('uniq function works with strings.', () => {
expect(uniq(['a', 'b', 'b', 'c', 'a'])).toEqual(['a', 'b', 'c']);
});
it('uniq function works with boolean values.', () => {
expect(uniq([true, false, true, false, false])).toEqual([true, false]);
});
it('uniq function works with nullish values.', () => {
expect(uniq([null, undefined, null, undefined])).toEqual([null, undefined]);
});
it('uniq function works with empty arrays.', () => {
expect(uniq([])).toEqual([]);
});
it('uniq function works with multiple types.', () => {
expect(uniq([1, 'a', 2, 'b', 1, 'a'])).toEqual([1, 'a', 2, 'b']);
});
it('uniq function keeps its original order.', () => {
expect(uniq([1, 2, 2, 3, 4, 4, 5])).toEqual([1, 2, 3, 4, 5]);
});
it('uniq function should create a new array.', () => {
const array = [1, 2, 3];
const result = uniq(array);

expect(result).toEqual([1, 2, 3]);
expect(result).not.toBe(array);
});
it('uniq function should not mutate the original array.', () => {
const array = [1, 2, 3, 2, 1, 3];
uniq(array);

expect(array).toEqual([1, 2, 3, 2, 1, 3]);
});
});

0 comments on commit e78a790

Please sign in to comment.