summaryrefslogtreecommitdiff
path: root/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala
blob: 638536f72ba82e963534a511b9652d9868b4d270 (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
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 RatcliffObershelpMetricSpec extends ScalaTest {
	import RatcliffObershelpMetricSpec.Metric

	"RatcliffObershelpMetric" should provide {
		"compare method" when passed {
			"empty arguments" should returns {
				"None" in {
					Metric.compare("", "").isDefined should be (false)
					Metric.compare("abc", "").isDefined should be (false)
					Metric.compare("", "xyz").isDefined should be (false)
				}
			}
			"equal arguments" should returns {
				"0" in {
					Metric.compare("abc", "abc").get should be (1)
					Metric.compare("123", "123").get should be (1)
				}
			}
			"unequal arguments" should returns {
				"Double indicating distance" in {
					Metric.compare("abc", "xyz").get should be (0)
					Metric.compare("123", "456").get should be (0)
				}
			}
			"valid arguments" should returns {
				"Double indicating distance" in {
					Metric.compare("aleksander", "alexandre").get should be (0.7368421052631579)
					Metric.compare("alexandre", "aleksander").get should be (0.7368421052631579)
					Metric.compare("pennsylvania", "pencilvaneya").get should be (0.6666666666666666)
					Metric.compare("pencilvaneya", "pennsylvania").get should be (0.6666666666666666)
					Metric.compare("abcefglmn", "abefglmo").get should be (0.8235294117647058)
					Metric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058)
				}
			}
		}
	}
	"RatcliffObershelpMetric companion object" should provide {
		"pass-through compare method" should returns {
			"same value as class" in {
				RatcliffObershelpMetric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058)
			}
		}
	}
}

object RatcliffObershelpMetricSpec {
	private final val Metric = RatcliffObershelpMetric()
}