summaryrefslogtreecommitdiff
path: root/core/source/test/scala/com/rockymadden/stringmetric/StringMetricSpec.scala
blob: 2fdd9253d45a9d85dc66ddb9bcc5f40d57475f91 (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
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 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 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 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 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)
		}
	}
}