Files
Nim/tests/stdlib/teditdistance.nim
ringabout 3d2f0e2c7c make more standard libraries work with nimPreviewSlimSystem (#20343)
* make more standard libraries work with `nimPreviewSlimSystem`

* typo

* part two

* Delete specutils.nim

* fixes more tests

* more fixes

* fixes tests

* fixes three more tests

* add formatfloat import

* fix

* last
2022-09-27 20:06:23 +02:00

41 lines
1.5 KiB
Nim
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import std/editdistance
import std/assertions
doAssert editDistance("", "") == 0
doAssert editDistance("kitten", "sitting") == 3 # from Wikipedia
doAssert editDistance("flaw", "lawn") == 2 # from Wikipedia
doAssert editDistance("привет", "превет") == 1
doAssert editDistance("Åge", "Age") == 1
# editDistance, one string is longer in bytes, but shorter in rune length
# first string: 4 bytes, second: 6 bytes, but only 3 runes
doAssert editDistance("aaaa", "×××") == 4
block veryLongStringEditDistanceTest:
const cap = 256
var
s1 = newStringOfCap(cap)
s2 = newStringOfCap(cap)
while len(s1) < cap:
s1.add 'a'
while len(s2) < cap:
s2.add 'b'
doAssert editDistance(s1, s2) == cap
block combiningCodePointsEditDistanceTest:
const s = "A\xCC\x8Age"
doAssert editDistance(s, "Age") == 1
doAssert editDistanceAscii("", "") == 0
doAssert editDistanceAscii("kitten", "sitting") == 3 # from Wikipedia
doAssert editDistanceAscii("flaw", "lawn") == 2 # from Wikipedia
doAssert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0)
doAssert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1)
doAssert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5)
doAssert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3)
doAssert(editDistance("prefix__hallo_suffix", "prefix") == 14)
doAssert(editDistance("prefix__hallo_suffix", "suffix") == 14)
doAssert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2)
doAssert(editDistance("main", "malign") == 2)