dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

levenshtein_test.go (1343B)


      1 package levenshtein
      2 
      3 import (
      4 	"testing"
      5 )
      6 
      7 func TestSanity(t *testing.T) {
      8 	tests := []struct {
      9 		a, b string
     10 		want int
     11 	}{
     12 		{"", "hello", 5},
     13 		{"hello", "", 5},
     14 		{"hello", "hello", 0},
     15 		{"ab", "aa", 1},
     16 		{"ab", "ba", 2},
     17 		{"ab", "aaa", 2},
     18 		{"bbb", "a", 3},
     19 		{"kitten", "sitting", 3},
     20 		{"distance", "difference", 5},
     21 		{"levenshtein", "frankenstein", 6},
     22 		{"resume and cafe", "resumes and cafes", 2},
     23 		{"a very long string that is meant to exceed", "another very long string that is meant to exceed", 6},
     24 	}
     25 	for i, d := range tests {
     26 		n := ComputeDistance(d.a, d.b)
     27 		if n != d.want {
     28 			t.Errorf("Test[%d]: ComputeDistance(%q,%q) returned %v, want %v",
     29 				i, d.a, d.b, n, d.want)
     30 		}
     31 	}
     32 }
     33 
     34 func TestUnicode(t *testing.T) {
     35 	tests := []struct {
     36 		a, b string
     37 		want int
     38 	}{
     39 		// Testing acutes and umlauts
     40 		{"resumé and café", "resumés and cafés", 2},
     41 		{"resume and cafe", "resumé and café", 2},
     42 		{"Hafþór Júlíus Björnsson", "Hafþor Julius Bjornsson", 4},
     43 		// Only 2 characters are less in the 2nd string
     44 		{"།་གམ་འས་པ་་མ།", "།་གམའས་པ་་མ", 2},
     45 	}
     46 	for i, d := range tests {
     47 		n := ComputeDistance(d.a, d.b)
     48 		if n != d.want {
     49 			t.Errorf("Test[%d]: ComputeDistance(%q,%q) returned %v, want %v",
     50 				i, d.a, d.b, n, d.want)
     51 		}
     52 	}
     53 }