summaryrefslogtreecommitdiff
path: root/core/source/test/scala/org/hashtree/stringmetric/similarity/LevenshteinMetricSpec.scala
blob: 53ac7e677335badeb16aa9ffd81388e442c14979 (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
package org.hashtree.stringmetric.similarity

import org.hashtree.stringmetric.ScalaTest
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class LevenshteinMetricSpec extends ScalaTest {
	"LevenshteinMetric" should provide {
		"compare method" when passed {
			"empty arguments" should returns {
				"None" in {
					LevenshteinMetric.compare("", "").isDefined should be (false)
				}
			}
			"equal arguments" should returns {
				"0" in {
					LevenshteinMetric.compare("abc", "abc").get should be (0)
				}
			}
			"unequal arguments" should returns {
				"Int indicating distance" in {
					LevenshteinMetric.compare("abc", "").get should be (3)
					LevenshteinMetric.compare("", "xyz").get should be (3)
					LevenshteinMetric.compare("abc", "xyz").get should be (3)
				}
			}
			"valid arguments" should returns {
				"Int indicating distance" in {
					LevenshteinMetric.compare("abc", "a").get should be (2)
					LevenshteinMetric.compare("a", "abc").get should be (2)
					LevenshteinMetric.compare("abc", "c").get should be (2)
					LevenshteinMetric.compare("c", "abc").get should be (2)
					LevenshteinMetric.compare("kitten", "sitting").get should be (3)
					LevenshteinMetric.compare("drake", "cake").get should be (2)
				}
			}
		}
	}
}