forked from trekhleb/javascript-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhammingDistance.test.js
More file actions
21 lines (18 loc) · 797 Bytes
/
hammingDistance.test.js
File metadata and controls
21 lines (18 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import hammingDistance from '../hammingDistance';
describe('hammingDistance', () => {
it('should throw an error when trying to compare the strings of different lengths', () => {
const compareStringsOfDifferentLength = () => {
hammingDistance('a', 'aa');
};
expect(compareStringsOfDifferentLength).toThrowError();
});
it('should calculate difference between two strings', () => {
expect(hammingDistance('a', 'a')).toBe(0);
expect(hammingDistance('a', 'b')).toBe(1);
expect(hammingDistance('abc', 'add')).toBe(2);
expect(hammingDistance('karolin', 'kathrin')).toBe(3);
expect(hammingDistance('karolin', 'kerstin')).toBe(3);
expect(hammingDistance('1011101', '1001001')).toBe(2);
expect(hammingDistance('2173896', '2233796')).toBe(3);
});
});