Added HammingDistance.js and HammingDistance.test.js in String directory

This commit is contained in:
AbhinavXT
2021-07-11 16:30:23 +05:30
parent a55248a3b7
commit 7af96ae1cc
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { hammingDistance } from '../HammingDistance'
test('should throw an error when trying to compare the strings of different length', () => {
const compareStringsOfDifferentLength = () => {
hammingDistance('abc', 'abcd')
}
expect(compareStringsOfDifferentLength).toThrowError()
})
test('should calculate difference between two strings', () => {
expect(hammingDistance('a', 'a')).toBe(0)
})
test('should calculate difference between two strings', () => {
expect(hammingDistance('abc', 'add')).toBe(2)
})
test('should calculate difference between two strings', () => {
expect(hammingDistance('1011101', '1001001')).toBe(2)
})