summaryrefslogtreecommitdiff
path: root/core/src/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala
blob: d645456d5056067cf0d111b7f73133941d35b904 (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
package com.rockymadden.stringmetric.similarity

import com.rockymadden.stringmetric.ScalaTest
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class JaroWinklerMetricSpec extends ScalaTest { "JaroWinklerMetric" should provide {
	"compare method" when passed {
		"empty arguments" should returns {
			"None" in {
				JaroWinklerMetric.compare("", "").isDefined should be (false)
				JaroWinklerMetric.compare("abc", "").isDefined should be (false)
				JaroWinklerMetric.compare("", "xyz").isDefined should be (false)
			}
		}
		"equal arguments" should returns {
			"1" in {
				JaroWinklerMetric.compare("a", "a").get should be (1)
				JaroWinklerMetric.compare("abc", "abc").get should be (1)
				JaroWinklerMetric.compare("123", "123").get should be (1)
			}
		}
		"unequal arguments" should returns {
			"0" in {
				JaroWinklerMetric.compare("abc", "xyz").get should be (0)
				JaroWinklerMetric.compare("123", "456").get should be (0)
			}
		}
		"valid arguments" should returns {
			"Double indicating distance" in {
				JaroWinklerMetric.compare("aa", "a").get should be (0.8500000000000001)
				JaroWinklerMetric.compare("a", "aa").get should be (0.8500000000000001)
				JaroWinklerMetric.compare("veryveryverylong", "v").get should be (0.71875)
				JaroWinklerMetric.compare("v", "veryveryverylong").get should be (0.71875)
				JaroWinklerMetric.compare("martha", "marhta").get should be (0.9611111111111111)
				JaroWinklerMetric.compare("dwayne", "duane").get should be (0.8400000000000001)
				JaroWinklerMetric.compare("dixon", "dicksonx").get should be (0.8133333333333332)
				JaroWinklerMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334)
				JaroWinklerMetric.compare("jones", "johnson").get should be (0.8323809523809523)
				JaroWinklerMetric.compare("henka", "henkan").get should be (0.9666666666666667)
				JaroWinklerMetric.compare("fvie", "ten").get should be (0)

				JaroWinklerMetric.compare("zac ephron", "zac efron").get should be >
					JaroWinklerMetric.compare("zac ephron", "kai ephron").get
				JaroWinklerMetric.compare("brittney spears", "britney spears").get should be >
					JaroWinklerMetric.compare("brittney spears", "brittney startzman").get
			}
		}
	}
}}