summaryrefslogtreecommitdiff
path: root/core/source/test/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricSpec.scala
blob: e1ff9cf2fc8b012470f13e8083574bc3da60187d (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
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 {
	"RatcliffObershelpMetric" should provide {
		"compare method" when passed {
			"empty arguments" should returns {
				"None" in {
					RatcliffObershelpMetric.compare("", "").isDefined should be (false)
					RatcliffObershelpMetric.compare("abc", "").isDefined should be (false)
					RatcliffObershelpMetric.compare("", "xyz").isDefined should be (false)
				}
			}
			"equal arguments" should returns {
				"0" in {
					RatcliffObershelpMetric.compare("abc", "abc").get should be (1)
					RatcliffObershelpMetric.compare("123", "123").get should be (1)
				}
			}
			"unequal arguments" should returns {
				"Double indicating distance" in {
					RatcliffObershelpMetric.compare("abc", "xyz").get should be (0)
					RatcliffObershelpMetric.compare("123", "456").get should be (0)
				}
			}
			"valid arguments" should returns {
				"Double indicating distance" in {
					RatcliffObershelpMetric.compare("aleksander", "alexandre").get should be (0.7368421052631579)
					RatcliffObershelpMetric.compare("alexandre", "aleksander").get should be (0.7368421052631579)
					RatcliffObershelpMetric.compare("pennsylvania", "pencilvaneya").get should be (0.6666666666666666)
					RatcliffObershelpMetric.compare("pencilvaneya", "pennsylvania").get should be (0.6666666666666666)
					RatcliffObershelpMetric.compare("abcefglmn", "abefglmo").get should be (0.8235294117647058)
					RatcliffObershelpMetric.compare("abefglmo", "abcefglmn").get should be (0.8235294117647058)
				}
			}
		}
	}
}