mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
chore: merge "Dice" (#703)
* feat: add dice coefficient * chore: link to wikipedia article * chore: convert to esm * refactor: add tests * chore: formatting
This commit is contained in:
21
String/test/DiceCoefficient.test.js
Normal file
21
String/test/DiceCoefficient.test.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { diceCoefficient } from '../DiceCoefficient'
|
||||
|
||||
describe('diceCoefficient', () => {
|
||||
it('should calculate edit distance between two strings', () => {
|
||||
// equal strings return 1 (max possible value)
|
||||
expect(diceCoefficient('abc', 'abc')).toBe(1)
|
||||
expect(diceCoefficient('', '')).toBe(1)
|
||||
|
||||
// string length needs to be atleast 2 (unless equal)
|
||||
expect(diceCoefficient('a', '')).toBe(0)
|
||||
expect(diceCoefficient('', 'a')).toBe(0)
|
||||
|
||||
expect(diceCoefficient('skate', 'ate')).toBe(0.66)
|
||||
|
||||
expect(diceCoefficient('money', 'honey')).toBe(0.75)
|
||||
|
||||
expect(diceCoefficient('love', 'hate')).toBe(0)
|
||||
|
||||
expect(diceCoefficient('skilled', 'killed')).toBe(0.9)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user