summaryrefslogtreecommitdiff
path: root/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala
blob: ca99bff4305b336471eab363a27f5f7f2830ea16 (plain) (blame)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.rockymadden.stringmetric

import com.rockymadden.stringmetric.phonetic._
import com.rockymadden.stringmetric.similarity._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class StringMetricSpec extends ScalaTest {
	"StringMetric standalone object" should provide {
		"compare method, type, and companion object pass-throughs" in {
			val diceSorensen: StringMetric.DiceSorensen = StringMetric.DiceSorensen()

			diceSorensen.compare("testone", "testtwo")(1).get should
				equal (StringMetric.compareWithDiceSorensen("testone", "testtwo")(1).get)
			diceSorensen.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (StringMetric.compareWithDiceSorensen("testone".toCharArray, "testtwo".toCharArray)(1).get)
			diceSorensen.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (DiceSorensenMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get)

			val hamming: StringMetric.Hamming = StringMetric.Hamming()

			hamming.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithHamming("testone", "testtwo").get)
			hamming.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithHamming("testone".toCharArray, "testtwo".toCharArray).get)
			hamming.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (HammingMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val jaccard: StringMetric.Jaccard = StringMetric.Jaccard()

			jaccard.compare("testone", "testtwo")(1).get should
				equal (StringMetric.compareWithJaccard("testone", "testtwo")(1).get)
			jaccard.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (StringMetric.compareWithJaccard("testone".toCharArray, "testtwo".toCharArray)(1).get)
			jaccard.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (JaccardMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get)

			val jaro: StringMetric.Jaro = StringMetric.Jaro()

			jaro.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithJaro("testone", "testtwo").get)
			jaro.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithJaro("testone".toCharArray, "testtwo".toCharArray).get)
			jaro.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (JaroMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val jaroWinkler: StringMetric.JaroWinkler = StringMetric.JaroWinkler()

			jaroWinkler.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithJaroWinkler("testone", "testtwo").get)
			jaroWinkler.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithJaroWinkler("testone".toCharArray, "testtwo".toCharArray).get)
			jaroWinkler.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (JaroWinklerMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val levenshtein: StringMetric.Levenshtein = StringMetric.Levenshtein()

			levenshtein.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithLevenshtein("testone", "testtwo").get)
			levenshtein.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithLevenshtein("testone".toCharArray, "testtwo".toCharArray).get)
			levenshtein.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (LevenshteinMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val metaphone: StringMetric.Metaphone = StringMetric.Metaphone()

			metaphone.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithMetaphone("testone", "testtwo").get)
			metaphone.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithMetaphone("testone".toCharArray, "testtwo".toCharArray).get)
			metaphone.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (MetaphoneMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val nGram: StringMetric.NGram = StringMetric.NGram()

			nGram.compare("testone", "testtwo")(1).get should
				equal (StringMetric.compareWithNGram("testone", "testtwo")(1).get)
			nGram.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (StringMetric.compareWithNGram("testone".toCharArray, "testtwo".toCharArray)(1).get)
			nGram.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (NGramMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get)

			val nysiis: StringMetric.Nysiis = StringMetric.Nysiis()

			nysiis.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithNysiis("testone", "testtwo").get)
			nysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithNysiis("testone".toCharArray, "testtwo".toCharArray).get)
			nysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (NysiisMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val overlap: StringMetric.Overlap = StringMetric.Overlap()

			overlap.compare("testone", "testtwo")(1).get should
				equal (StringMetric.compareWithOverlap("testone", "testtwo")(1).get)
			overlap.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (StringMetric.compareWithOverlap("testone".toCharArray, "testtwo".toCharArray)(1).get)
			overlap.compare("testone".toCharArray, "testtwo".toCharArray)(1).get should
				equal (OverlapMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1).get)

			val refinedNysiis: StringMetric.RefinedNysiis = StringMetric.RefinedNysiis()

			refinedNysiis.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithRefinedNysiis("testone", "testtwo").get)
			refinedNysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithRefinedNysiis("testone".toCharArray, "testtwo".toCharArray).get)
			refinedNysiis.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (RefinedNysiisMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val refinedSoundex: StringMetric.RefinedSoundex = StringMetric.RefinedSoundex()

			refinedSoundex.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithRefinedSoundex("testone", "testtwo").get)
			refinedSoundex.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithRefinedSoundex("testone".toCharArray, "testtwo".toCharArray).get)
			refinedSoundex.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (RefinedSoundexMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val soundex: StringMetric.Soundex = StringMetric.Soundex()

			soundex.compare("testone", "testtwo").get should
				equal (StringMetric.compareWithSoundex("testone", "testtwo").get)
			soundex.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (StringMetric.compareWithSoundex("testone".toCharArray, "testtwo".toCharArray).get)
			soundex.compare("testone".toCharArray, "testtwo".toCharArray).get should
				equal (SoundexMetric.compare("testone".toCharArray, "testtwo".toCharArray).get)

			val weightedLevenshtein: StringMetric.WeightedLevenshtein = StringMetric.WeightedLevenshtein()

			weightedLevenshtein.compare("testone", "testtwo")(1, 2, 3).get should
				equal (StringMetric.compareWithWeightedLevenshtein("testone", "testtwo")(1, 2, 3).get)
			weightedLevenshtein.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get should
				equal (StringMetric.compareWithWeightedLevenshtein("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get)
			weightedLevenshtein.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get should
				equal (WeightedLevenshteinMetric.compare("testone".toCharArray, "testtwo".toCharArray)(1, 2, 3).get)
		}
	}
}