MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Test_EditDistance

Function Test_EditDistance

dynamic/editdistance_test.go:8–35  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func Test_EditDistance(t *testing.T) {
9
10 var testCases = []struct {
11 first string
12 second string
13 expected int
14 }{
15 {"", "", 0},
16 {"horse", "ros", 3},
17 {"intention", "execution", 5},
18 {"abcdxabcde", "abcdeabcdx", 2},
19 {"sunday", "saturday", 3},
20 {"food", "money", 4},
21 {"voldemort", "dumbledore", 7},
22 }
23
24 for i := range testCases {
25
26 t.Run(fmt.Sprintf("Word 1: %s, Word 2: %s", testCases[i].first, testCases[i].second), func(t *testing.T) {
27
28 computed := EditDistanceDP(testCases[i].first, testCases[i].second)
29
30 if computed != testCases[i].expected {
31 t.Errorf("Word 1: %s, Word 2: %s, Expected: %d, Computed: %d", testCases[i].first, testCases[i].second, testCases[i].expected, computed)
32 }
33 })
34 }
35}

Callers

nothing calls this directly

Calls 1

EditDistanceDPFunction · 0.85

Tested by

no test coverage detected