aboutsummaryrefslogtreecommitdiff
path: root/levenshtein_test.go
blob: 60f029336d80ab770b9491f671e3761f7f682197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2014 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package blueprint

import (
	"reflect"
	"testing"
)

func mods(mods []string) []*moduleGroup {
	ret := []*moduleGroup{}

	for _, v := range mods {
		m := moduleGroup{name: v}
		ret = append(ret, &m)
	}

	return ret
}

func assertEqual(t *testing.T, a, b []string) {
	if len(a) == 0 && len(b) == 0 {
		return
	}

	if !reflect.DeepEqual(a, b) {
		t.Errorf("Expected the following to be equal:\n\t%q\n\t%q", a, b)
	}
}

func TestLevenshteinWontGuessUnlike(t *testing.T) {
	assertEqual(t, namesLike("a", "test", mods([]string{"test"})), []string{})
}
func TestLevenshteinInsert(t *testing.T) {
	assertEqual(t, namesLike("a", "test", mods([]string{"ab", "ac", "not_this"})), []string{"ab", "ac"})
}
func TestLevenshteinDelete(t *testing.T) {
	assertEqual(t, namesLike("ab", "test", mods([]string{"a", "b", "not_this"})), []string{"a", "b"})
}
func TestLevenshteinReplace(t *testing.T) {
	assertEqual(t, namesLike("aa", "test", mods([]string{"ab", "ac", "not_this"})), []string{"ab", "ac"})
}