summaryrefslogtreecommitdiff
path: root/cli/source
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2012-10-15 21:53:21 -0600
committerRocky Madden <git@rockymadden.com>2012-10-15 21:53:21 -0600
commit0db51ce1fe68371efb9010810ce93d93f48c50d0 (patch)
tree9ceb35a45800672d168de3438cb0bbdfc94a7c03 /cli/source
parentfca3092370731e8cae29a4e52ebc33488e9ec3a1 (diff)
downloadstringmetric-0db51ce1fe68371efb9010810ce93d93f48c50d0.tar.gz
stringmetric-0db51ce1fe68371efb9010810ce93d93f48c50d0.tar.bz2
stringmetric-0db51ce1fe68371efb9010810ce93d93f48c50d0.zip
Created HammingMetric, spec, and command.
Diffstat (limited to 'cli/source')
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala56
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala6
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala6
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala6
-rwxr-xr-xcli/source/test/scala/org/hashtree/stringmetric/cli/command/hammingMetricSpec.scala39
-rwxr-xr-xcli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexMetricSpec.scala2
6 files changed, 111 insertions, 4 deletions
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala
new file mode 100755
index 0000000..9e8dcfc
--- /dev/null
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/hammingMetric.scala
@@ -0,0 +1,56 @@
+package org.hashtree.stringmetric.cli.command
+
+import org.hashtree.stringmetric.{ CaseStringCleaner, HammingMetric, StringCleanerDelegate }
+import org.hashtree.stringmetric.cli._
+import org.hashtree.stringmetric.cli.command._
+
+/**
+ * The hammingMetric [[org.hashtree.stringmetric.cli.command.Command]]. Compares the number of characters that two equal
+ * length strings are different from one another.
+ */
+object hammingMetric extends Command {
+ override def main(args: Array[String]): Unit = {
+ val options = OptionMapUtility.toOptionMap(args)
+
+ try {
+ // Help.
+ if (options.contains('h) || options.contains('help)) {
+ help()
+ exit(options)
+ // Execute.
+ } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) {
+ execute(options)
+ exit(options)
+ // Invalid syntax.
+ } else {
+ throw new IllegalArgumentException("Expected valid syntax. See --help.")
+ }
+ } catch {
+ case e => error(e)(options)
+ }
+ }
+
+ override def help(): Unit = {
+ val ls = sys.props("line.separator")
+ val tab = " "
+
+ println(
+ "Compares the number of characters that two equal length strings are different from one another." + ls + ls +
+ "Syntax:" + ls +
+ tab + "hammingMetric [Options] string1 string2..." + ls + ls +
+ "Options:" + ls +
+ tab + "-h, --help" + ls +
+ tab + tab + "Outputs description, syntax, and options."
+ )
+ }
+
+ override def execute(options: OptionMap): Unit = {
+ val strings = options('dashless).split(" ")
+
+ println(
+ HammingMetric.compare(strings(0),
+ strings(1))(new StringCleanerDelegate with CaseStringCleaner
+ ).getOrElse("not comparable").toString
+ )
+ }
+} \ No newline at end of file
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala
index 874f3aa..51a4958 100755
--- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroMetric.scala
@@ -47,6 +47,10 @@ object jaroMetric extends Command {
override def execute(options: OptionMap): Unit = {
val strings = options('dashless).split(" ")
- println(JaroMetric.compare(strings(0), strings(1))(new StringCleanerDelegate with CaseStringCleaner).getOrElse("0.0").toString)
+ println(
+ JaroMetric.compare(strings(0),
+ strings(1))(new StringCleanerDelegate with CaseStringCleaner
+ ).getOrElse("not comparable").toString
+ )
}
} \ No newline at end of file
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala
index ea1b8a6..af633ae 100755
--- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/jaroWinklerMetric.scala
@@ -47,6 +47,10 @@ object jaroWinklerMetric extends Command {
override def execute(options: OptionMap): Unit = {
val strings = options('dashless).split(" ")
- println(JaroWinklerMetric.compare(strings(0), strings(1))(new StringCleanerDelegate with CaseStringCleaner).getOrElse("0.0").toString)
+ println(
+ JaroWinklerMetric.compare(strings(0),
+ strings(1))(new StringCleanerDelegate with CaseStringCleaner
+ ).getOrElse("not comparable").toString
+ )
}
} \ No newline at end of file
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala
index 5a44395..f0b204e 100755
--- a/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/command/soundexMetric.scala
@@ -47,6 +47,10 @@ object soundexMetric extends Command {
override def execute(options: OptionMap): Unit = {
val strings = options('dashless).split(" ")
- println(SoundexMetric.compare(strings(0), strings(1))(new StringCleanerDelegate).getOrElse("false").toString)
+ println(
+ SoundexMetric.compare(strings(0),
+ strings(1))(new StringCleanerDelegate
+ ).getOrElse("not comparable").toString
+ )
}
} \ No newline at end of file
diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/hammingMetricSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/hammingMetricSpec.scala
new file mode 100755
index 0000000..f140505
--- /dev/null
+++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/hammingMetricSpec.scala
@@ -0,0 +1,39 @@
+package org.hashtree.stringmetric.cli.command
+
+import org.hashtree.stringmetric.ScalaTest
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+@RunWith(classOf[JUnitRunner])
+final class hammingMetricSpec extends ScalaTest {
+ "hammingMetric" should provide {
+ "main method" when passed {
+ "valid dashless arguments" should executes {
+ "print if they are a match" in {
+ val out = new java.io.ByteArrayOutputStream()
+
+ Console.withOut(out)(
+ hammingMetric.main(Array("--unitTest", "--debug", "aBc", "abc"))
+ )
+
+ out.toString should equal ("0\n")
+ out.reset()
+
+ Console.withOut(out)(
+ hammingMetric.main(Array("--unitTest", "--debug", "aBc", "xyz"))
+ )
+
+ out.toString should equal ("3\n")
+ out.reset()
+ }
+ }
+ "no dashless arguments" should throws {
+ "IllegalArgumentException" in {
+ evaluating {
+ hammingMetric.main(Array("--unitTest", "--debug"))
+ } should produce [IllegalArgumentException]
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexMetricSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexMetricSpec.scala
index 80a0a50..4fba289 100755
--- a/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexMetricSpec.scala
+++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/command/soundexMetricSpec.scala
@@ -30,7 +30,7 @@ final class soundexMetricSpec extends ScalaTest {
soundexMetric.main(Array("--unitTest", "--debug", "1", "1"))
)
- out.toString should equal ("false\n")
+ out.toString should equal ("not comparable\n")
out.reset()
}
}