@dxzmpk/js-algorithms-data-structures
Version:
Algorithms and data-structures implemented on JavaScript
22 lines (18 loc) • 797 B
JavaScript
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);
});
});