summaryrefslogtreecommitdiff
path: root/core/source/test/scala
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2013-03-12 17:53:59 -0600
committerRocky Madden <git@rockymadden.com>2013-03-12 17:53:59 -0600
commitb848cf2945b0be8d9fad0e81d98deda78e7443dd (patch)
treebe4b6e8592c5166f4e9e162241b1e112f626e39d /core/source/test/scala
parentcd4919a5093b916e5f568734f8ec2e799aa1037a (diff)
downloadstringmetric-b848cf2945b0be8d9fad0e81d98deda78e7443dd.tar.gz
stringmetric-b848cf2945b0be8d9fad0e81d98deda78e7443dd.tar.bz2
stringmetric-b848cf2945b0be8d9fad0e81d98deda78e7443dd.zip
Created overlap metric, spec, benchmark, and CLI.
Diffstat (limited to 'core/source/test/scala')
-rwxr-xr-xcore/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala77
1 files changed, 77 insertions, 0 deletions
diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala
new file mode 100755
index 0000000..32c9650
--- /dev/null
+++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/OverlapMetricSpec.scala
@@ -0,0 +1,77 @@
+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 OverlapMetricSpec extends ScalaTest {
+ import OverlapMetricSpec.Metric
+
+ "OverlapMetric" should provide {
+ "compare method" when passed {
+ "empty arguments" should returns {
+ "None" in {
+ Metric.compare("", "")(1).isDefined should be (false)
+ Metric.compare("abc", "")(1).isDefined should be (false)
+ Metric.compare("", "xyz")(1).isDefined should be (false)
+ }
+ }
+ "equal arguments" should returns {
+ "1" in {
+ Metric.compare("abc", "abc")(1).get should be (1)
+ Metric.compare("abc", "abc")(2).get should be (1)
+ Metric.compare("abc", "abc")(3).get should be (1)
+ }
+ }
+ "unequal arguments" should returns {
+ "0" in {
+ Metric.compare("abc", "xyz")(1).get should be (0)
+ Metric.compare("abc", "xyz")(2).get should be (0)
+ Metric.compare("abc", "xyz")(3).get should be (0)
+ }
+ }
+ "invalid arguments" should returns {
+ "None" in {
+ Metric.compare("n", "naght")(2).isDefined should be (false)
+ Metric.compare("night", "n")(2).isDefined should be (false)
+ Metric.compare("ni", "naght")(3).isDefined should be (false)
+ Metric.compare("night", "na")(3).isDefined should be (false)
+ }
+ }
+ "valid arguments" should returns {
+ "Double indicating distance" in {
+ Metric.compare("bob", "bobman") (1).get should be (1)
+ Metric.compare("bob", "manbobman") (1).get should be (1)
+ Metric.compare("night", "nacht")(1).get should be (0.6)
+ Metric.compare("night", "naght")(1).get should be (0.8)
+ Metric.compare("context", "contact")(1).get should be (0.7142857142857143)
+
+ Metric.compare("night", "nacht")(2).get should be (0.25)
+ Metric.compare("night", "naght")(2).get should be (0.5)
+ Metric.compare("context", "contact")(2).get should be (0.5)
+ Metric.compare("contextcontext", "contact")(2).get should be (0.5)
+ Metric.compare("context", "contactcontact")(2).get should be (0.5)
+ Metric.compare("ht", "nacht")(2).get should be (1)
+ Metric.compare("xp", "nacht")(2).get should be (0)
+ Metric.compare("ht", "hththt")(2).get should be (1)
+
+ Metric.compare("night", "nacht")(3).get should be (0)
+ Metric.compare("night", "naght")(3).get should be (0.3333333333333333)
+ Metric.compare("context", "contact")(3).get should be (0.4)
+ }
+ }
+ }
+ }
+ "OverlapMetric companion object" should provide {
+ "pass-through compare method" should returns {
+ "same value as class" in {
+ OverlapMetric.compare("context", "contact")(3).get should be (0.4)
+ }
+ }
+ }
+}
+
+object OverlapMetricSpec {
+ private final val Metric = OverlapMetric()
+}