mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-10 14:22:53 +08:00
Added HammingDistance.js and HammingDistance.test.js in String directory
This commit is contained in:
21
String/test/HammingDistance.test.js
Normal file
21
String/test/HammingDistance.test.js
Normal 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)
|
||||
})
|
Reference in New Issue
Block a user