DiffHelperTests.js 988 B

12345678910111213141516171819202122232425262728
  1. const { expect } = require('chai')
  2. const {
  3. stringSimilarity,
  4. } = require('../../../../app/src/Features/Helpers/DiffHelper')
  5. describe('DiffHelper', function () {
  6. describe('stringSimilarity', function () {
  7. it('should have a ratio of 1 for identical strings', function () {
  8. expect(stringSimilarity('abcdef', 'abcdef')).to.equal(1.0)
  9. })
  10. it('should have a ratio of 0 for completely different strings', function () {
  11. expect(stringSimilarity('abcdef', 'qmglzxv')).to.equal(0.0)
  12. })
  13. it('should have a ratio of between 0 and 1 for strings that are similar', function () {
  14. const ratio = stringSimilarity('abcdef', 'abcdef@zxvkp')
  15. expect(ratio).to.equal(0.66)
  16. })
  17. it('should reject non-string inputs', function () {
  18. expect(() => stringSimilarity(1, 'abc')).to.throw
  19. expect(() => stringSimilarity('abc', 2)).to.throw
  20. expect(() => stringSimilarity('abc', new Array(1000).fill('a').join('')))
  21. .to.throw
  22. })
  23. })
  24. })