-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnagramGrouper.test.ts
25 lines (21 loc) · 973 Bytes
/
AnagramGrouper.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { AnagramGrouper } from './AnagramGrouper';
describe('AnagramGrouper', () => {
test('groups anagrams correctly', () => {
const input = ["eat", "tea", "tan", "ate", "nat", "bat"];
const expectedOutput = [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]];
const output = AnagramGrouper.groupAnagrams(input);
expect(new Set(output.map(group => new Set(group)))).toEqual(new Set(expectedOutput.map(group => new Set(group))));
});
test('handles empty input', () => {
const input: string[] = [];
const expectedOutput: string[][] = [];
const output = AnagramGrouper.groupAnagrams(input);
expect(output).toEqual(expectedOutput);
});
test('handles null or undefined input', () => {
const input = undefined;
const expectedOutput: string[][] = [];
const output = AnagramGrouper.groupAnagrams(input as any);
expect(output).toEqual(expectedOutput);
});
});