diff options
author | Rocky Madden <git@rockymadden.com> | 2012-12-16 10:37:11 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-12-16 10:37:11 -0700 |
commit | 93722dfe64a93d2259ce9fa7d04da2eab8b64e1c (patch) | |
tree | cbabbac479b731103d879616b930ba3a096f0cb6 /core/source/test/scala/com/rockymadden | |
parent | 0c19b374c1c19a705d613b37451e92e6b27d7fe4 (diff) | |
download | stringmetric-93722dfe64a93d2259ce9fa7d04da2eab8b64e1c.tar.gz stringmetric-93722dfe64a93d2259ce9fa7d04da2eab8b64e1c.tar.bz2 stringmetric-93722dfe64a93d2259ce9fa7d04da2eab8b64e1c.zip |
Changed group from org.hashtree.stringmetric to com.rockymadden.stringmetric.
Diffstat (limited to 'core/source/test/scala/com/rockymadden')
33 files changed, 2080 insertions, 0 deletions
diff --git a/core/source/test/scala/com/rockymadden/stringmetric/ScalaTest.scala b/core/source/test/scala/com/rockymadden/stringmetric/ScalaTest.scala new file mode 100755 index 0000000..6e4faba --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/ScalaTest.scala @@ -0,0 +1,18 @@ +package com.rockymadden.stringmetric + +import org.scalatest.{ BeforeAndAfter, WordSpec } +import org.scalatest.matchers.ShouldMatchers + +trait ScalaTest extends WordSpec with ShouldMatchers with BeforeAndAfter { + def allows = afterWord("allow") + + def executes = afterWord("execute") + + def passed = afterWord("passed") + + def provide = afterWord("provide") + + def returns = afterWord("return") + + def throws = afterWord("throw") +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilterSpec.scala new file mode 100755 index 0000000..73b7799 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlOnlyStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiControlOnlyStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiControlOnlyStringFilter + + "AsciiControlOnlyStringFilter" should provide { + "overloaded filter method" when passed { + "String with mixed characters" should returns { + "String with non-controls removed" in { + Filter.filter("!@#$% ^&*()abc") should equal (" ") + Filter.filter(" ^&*()abc") should equal (" ") + Filter.filter("%^&*()abc ") should equal (" ") + } + } + "character array with mixed characters" should returns { + "character array with non-controls removed" in { + Filter.filter("!@#$% ^&*()abc".toCharArray) should equal (" ".toCharArray) + Filter.filter(" ^&*()abc".toCharArray) should equal (" ".toCharArray) + Filter.filter("%^&*()abc ".toCharArray) should equal (" ".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilterSpec.scala new file mode 100755 index 0000000..55b0428 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiControlStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiControlStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiControlStringFilter + + "AsciiControlStringFilter" should provide { + "overloaded filter method" when passed { + "String with controls" should returns { + "String with controls removed" in { + Filter.filter(" HelloWorld") should equal ("HelloWorld") + Filter.filter("HelloWorld ") should equal ("HelloWorld") + Filter.filter("Hello World") should equal ("HelloWorld") + } + } + "character array with controls" should returns { + "character array with controls removed" in { + Filter.filter(" HelloWorld".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter("HelloWorld ".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter("Hello World".toCharArray) should equal ("HelloWorld".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilterSpec.scala new file mode 100755 index 0000000..34915fb --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterCaseStringFilterSpec.scala @@ -0,0 +1,37 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiLetterCaseStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiLetterCaseStringFilter + + "AsciiLetterCaseStringFilter" should provide { + "overloaded filter method" when passed { + "String with mixed case" should returns { + "String with the same case" in { + Filter.filter("HelloWorld") should (equal ("helloworld") or equal ("HELLOWORLD")) + Filter.filter("Hello World") should (equal ("hello world") or equal ("HELLO WORLD")) + Filter.filter("H e l l o W o r l d") should + (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) + Filter.filter("H e l l o W o r l d") should + (equal ("h e l l o w o r l d") or equal ("H E L L O W O R L D")) + } + } + "character array with mixed case" should returns { + "character array with the same case" in { + Filter.filter("HelloWorld".toCharArray) should + (equal ("helloworld".toCharArray) or equal ("HELLOWORLD".toCharArray)) + Filter.filter("Hello World".toCharArray) should + (equal ("hello world".toCharArray) or equal ("HELLO WORLD".toCharArray)) + Filter.filter("H e l l o W o r l d".toCharArray) should + (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) + Filter.filter("H e l l o W o r l d".toCharArray) should + (equal ("h e l l o w o r l d".toCharArray) or equal ("H E L L O W O R L D".toCharArray)) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilterSpec.scala new file mode 100755 index 0000000..e5130a2 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberOnlyStringFilterSpec.scala @@ -0,0 +1,31 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiLetterNumberOnlyStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiLetterNumberOnlyStringFilter + + "AsciiLetterNumberOnlyStringFilter" should provide { + "overloaded filter method" when passed { + "String with mixed characters" should returns { + "String with non-letters and non-numbers removed" in { + Filter.filter("!@#$%^&*()abc") should equal ("abc") + Filter.filter("!@#$%^&*()abc123") should equal ("abc123") + Filter.filter("abc123!@#$%^&*()") should equal ("abc123") + Filter.filter("!@#$%abc123^&*()") should equal ("abc123") + } + } + "character array with mixed characters" should returns { + "character array with non-letters and non-numbers removed" in { + Filter.filter("!@#$%^&*()abc".toCharArray) should equal ("abc".toCharArray) + Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("abc123".toCharArray) + Filter.filter("abc123!@#$%^&*()".toCharArray) should equal ("abc123".toCharArray) + Filter.filter("!@#$%abc123^&*()".toCharArray) should equal ("abc123".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilterSpec.scala new file mode 100755 index 0000000..66c4dc4 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterNumberStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiLetterNumberStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiLetterNumberStringFilter + + "AsciiLetterNumberStringFilter" should provide { + "overloaded filter method" when passed { + "String with letters and numbers" should returns { + "String with letters and numbers removed" in { + Filter.filter(" Hello123World!") should equal (" !") + Filter.filter("Hello123 !World") should equal (" !") + Filter.filter("!Hello123World ") should equal ("! ") + } + } + "character array with letters and numbers" should returns { + "character array with letters and numbers removed" in { + Filter.filter(" Hello123World!".toCharArray) should equal (" !".toCharArray) + Filter.filter("Hello123 !World".toCharArray) should equal (" !".toCharArray) + Filter.filter("!Hello123World ".toCharArray) should equal ("! ".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilterSpec.scala new file mode 100755 index 0000000..46fe931 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterOnlyStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiLetterOnlyStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiLetterOnlyStringFilter + + "AsciiLetterOnlyStringFilter" should provide { + "overloaded filter method" when passed { + "String with mixed characters" should returns { + "String with non-letters removed" in { + Filter.filter("!@#$%^&*()abc") should equal ("abc") + Filter.filter("!@#$%^&*()abc123") should equal ("abc") + Filter.filter("abc!@#$%^&*()123") should equal ("abc") + } + } + "character array with mixed characters" should returns { + "character array with non-letters removed" in { + Filter.filter("!@#$%^&*()abc".toCharArray) should equal ("abc".toCharArray) + Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("abc".toCharArray) + Filter.filter("abc!@#$%^&*()123".toCharArray) should equal ("abc".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilterSpec.scala new file mode 100755 index 0000000..d522d72 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiLetterStringFilterSpec.scala @@ -0,0 +1,25 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiLetterStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiLetterStringFilter + + "AsciiLetterStringFilter" should provide { + "overloaded filter method" when passed { + "String with letters" should returns { + "String with letters removed" in { + Filter.filter(" Hello123World!") should equal (" 123!") + } + } + "character array with letters" should returns { + "character array with letters removed" in { + Filter.filter(" Hello123World!".toCharArray) should equal (" 123!".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilterSpec.scala new file mode 100755 index 0000000..994c17d --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberOnlyStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiNumberOnlyStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiNumberOnlyStringFilter + + "AsciiNumberOnlyStringFilter" should provide { + "overloaded filter method" when passed { + "String with mixed characters" should returns { + "String with non-numbers removed" in { + Filter.filter("!@#$%^&*()abc123") should equal ("123") + Filter.filter("123!@#$%^&*()abc") should equal ("123") + Filter.filter("!@#$%^123&*()abc") should equal ("123") + } + } + "character array with mixed characters" should returns { + "character array with non-numbers removed" in { + Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("123".toCharArray) + Filter.filter("123!@#$%^&*()abc".toCharArray) should equal ("123".toCharArray) + Filter.filter("!@#$%^123&*()abc".toCharArray) should equal ("123".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilterSpec.scala new file mode 100755 index 0000000..4495d8b --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiNumberStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiNumberStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiNumberStringFilter + + "AsciiNumberStringFilter" should provide { + "overloaded filter method" when passed { + "String with numbers" should returns { + "String with numbers removed" in { + Filter.filter(" Hello123World!") should equal (" HelloWorld!") + Filter.filter("123 HelloWorld!") should equal (" HelloWorld!") + Filter.filter(" HelloWorld!123") should equal (" HelloWorld!") + } + } + "character array with numbers" should returns { + "character array with numbers removed" in { + Filter.filter(" Hello123World!".toCharArray) should equal (" HelloWorld!".toCharArray) + Filter.filter("123 HelloWorld!".toCharArray) should equal (" HelloWorld!".toCharArray) + Filter.filter(" HelloWorld!123".toCharArray) should equal (" HelloWorld!".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilterSpec.scala new file mode 100755 index 0000000..7d532a3 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSpaceStringFilterSpec.scala @@ -0,0 +1,33 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiSpaceStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiSpaceStringFilter + + "AsciiSpaceStringFilter" should provide { + "overloaded filter method" when passed { + "String with spaces" should returns { + "String with spaces removed" in { + Filter.filter("HelloWorld") should equal ("HelloWorld") + Filter.filter(" HelloWorld ") should equal ("HelloWorld") + Filter.filter("Hello World") should equal ("HelloWorld") + Filter.filter("H e l l o W o r l d") should equal ("HelloWorld") + Filter.filter("H e l l o W o r l d") should equal ("HelloWorld") + } + } + "character array with spaces" should returns { + "character array with spaces removed" in { + Filter.filter("HelloWorld".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter(" HelloWorld ".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter("Hello World".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter("H e l l o W o r l d".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter("H e l l o W o r l d".toCharArray) should equal ("HelloWorld".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilterSpec.scala new file mode 100755 index 0000000..53f47b1 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolOnlyStringFilterSpec.scala @@ -0,0 +1,29 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiSymbolOnlyStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiSymbolOnlyStringFilter + + "AsciiSymbolOnlyStringFilter" should provide { + "overloaded filter method" when passed { + "String with mixed characters" should returns { + "String with non-symbols removed" in { + Filter.filter("!@#$%^&*()abc123") should equal ("!@#$%^&*()") + Filter.filter("abc123!@#$%^&*()") should equal ("!@#$%^&*()") + Filter.filter("!@#$%abc123^&*()") should equal ("!@#$%^&*()") + } + } + "character array with mixed characters" should returns { + "character array with non-symbols removed" in { + Filter.filter("!@#$%^&*()abc123".toCharArray) should equal ("!@#$%^&*()".toCharArray) + Filter.filter("abc123!@#$%^&*()".toCharArray) should equal ("!@#$%^&*()".toCharArray) + Filter.filter("!@#$%abc123^&*()".toCharArray) should equal ("!@#$%^&*()".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilterSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilterSpec.scala new file mode 100755 index 0000000..51ca748 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/AsciiSymbolStringFilterSpec.scala @@ -0,0 +1,27 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AsciiSymbolStringFilterSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate with AsciiSymbolStringFilter + + "AsciiSymbolStringFilter" should provide { + "overloaded filter method" when passed { + "String with symbols" should returns { + "String with symbols removed" in { + Filter.filter("[HelloWorld]") should equal ("HelloWorld") + Filter.filter("Hello!World") should equal ("HelloWorld") + } + } + "character array with symbols" should returns { + "character array with symbols removed" in { + Filter.filter("[HelloWorld]".toCharArray) should equal ("HelloWorld".toCharArray) + Filter.filter("Hello!World".toCharArray) should equal ("HelloWorld".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala new file mode 100755 index 0000000..bce7cd8 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/filter/StringFilterDelegateSpec.scala @@ -0,0 +1,27 @@ +package com.rockymadden.stringmetric.filter + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class StringFilterDelegateSpec extends ScalaTest { + private[this] val Filter = new StringFilterDelegate + + "StringFilterDelegate" should provide { + "overloaded filter method" when passed { + "String" should returns { + "the same String" in { + Filter.filter("Hello World") should equal ("Hello World") + Filter.filter(" Hello! World]") should equal (" Hello! World]") + } + } + "character array" should returns { + "the same character array" in { + Filter.filter("Hello World".toCharArray) should equal ("Hello World".toCharArray) + Filter.filter(" Hello! World]".toCharArray) should equal (" Hello! World]".toCharArray) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/AlphabetSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/AlphabetSpec.scala new file mode 100755 index 0000000..dc0e63b --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/AlphabetSpec.scala @@ -0,0 +1,125 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class AlphabetSpec extends ScalaTest { + "Alphabet" should provide { + "an overloaded is method which accepts a Char" when passed { + "non-alphabet argument" should returns { + "false" in { + Alphabet.is('0') should be (false) + } + } + "alphabet argument" should returns { + "true" in { + Alphabet.is('a') should be (true) + Alphabet.is('A') should be (true) + } + } + } + "an overloaded is method which accepts an Array[Char]" when passed { + "empty argument" should returns { + "false" in { + Alphabet.is(Array.empty[Char]) should be (false) + } + } + "non-alphabet argument" should returns { + "false" in { + Alphabet.is("hi!".toCharArray) should be (false) + Alphabet.is("helloworld!".toCharArray) should be (false) + } + } + "alphabet argument" should returns { + "true" in { + Alphabet.is("hi".toCharArray) should be (true) + Alphabet.is("helloworld".toCharArray) should be (true) + Alphabet.is("HI".toCharArray) should be (true) + Alphabet.is("HELLOWORLD".toCharArray) should be (true) + } + } + } + "an overloaded is method which accepts a String" when passed { + "empty argument" should returns { + "false" in { + Alphabet.is("") should be (false) + } + } + "non-alphabet argument" should returns { + "false" in { + Alphabet.is("helloworld!") should be (false) + } + } + "alphabet argument" should returns { + "true" in { + Alphabet.is("helloworld") should be (true) + Alphabet.is("HELLOWORLD") should be (true) + } + } + } + "isSometimesVowel method" when passed { + "non-vowel argument" should returns { + "false" in { + Alphabet.isSometimesVowel('z') should be (false) + } + } + "vowel argument" should returns { + "true" in { + Alphabet.isSometimesVowel('a') should be (true) + Alphabet.isSometimesVowel('A') should be (true) + Alphabet.isSometimesVowel('y') should be (true) + Alphabet.isSometimesVowel('Y') should be (true) + } + } + } + "isVowel method" when passed { + "non-vowel argument" should returns { + "false" in { + Alphabet.isVowel('y') should be (false) + } + } + "vowel argument" should returns { + "true" in { + Alphabet.isVowel('a') should be (true) + Alphabet.isVowel('A') should be (true) + } + } + } + "an overloaded startsWith method which accepts an Array[Char]" when passed { + "empty argument" should returns { + "false" in { + Alphabet.startsWith(Array.empty[Char]) should be (false) + } + } + "non-alphabet argument" should returns { + "false" in { + Alphabet.startsWith("1abc".toCharArray) should be (false) + } + } + "alphabet argument" should returns { + "true" in { + Alphabet.startsWith("abc".toCharArray) should be (true) + } + } + } + "an overloaded startsWith method which accepts a String" when passed { + "empty argument" should returns { + "false" in { + Alphabet.startsWith("") should be (false) + } + } + "non-alphabet argument" should returns { + "false" in { + Alphabet.startsWith("1abc") should be (false) + } + } + "alphabet argument" should returns { + "true" in { + Alphabet.startsWith("abc") should be (true) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala new file mode 100755 index 0000000..b6af492 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneAlgorithmSpec.scala @@ -0,0 +1,213 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class MetaphoneAlgorithmSpec extends ScalaTest { + "MetaphoneAlgorithm" should provide { + "compute method" when passed { + "empty argument" should returns { + "None" in { + MetaphoneAlgorithm.compute("").isDefined should be (false) + } + } + "non-phonetic argument" should returns { + "None" in { + MetaphoneAlgorithm.compute("123").isDefined should be (false) + } + } + "phonetic argument" should returns { + "Some" in { + // z + MetaphoneAlgorithm.compute("z").get should equal ("s") + MetaphoneAlgorithm.compute("zz").get should equal ("s") + + // y + MetaphoneAlgorithm.compute("y").isDefined should be (false) + MetaphoneAlgorithm.compute("zy").get should equal ("s") + MetaphoneAlgorithm.compute("zyz").get should equal ("ss") + MetaphoneAlgorithm.compute("zya").get should equal ("sy") + + // x + MetaphoneAlgorithm.compute("x").get should equal ("s") + MetaphoneAlgorithm.compute("zx").get should equal ("sks") + MetaphoneAlgorithm.compute("zxz").get should equal ("skss") + + // w + MetaphoneAlgorithm.compute("w").isDefined should be (false) + MetaphoneAlgorithm.compute("zw").get should equal ("s") + MetaphoneAlgorithm.compute("zwz").get should equal ("ss") + MetaphoneAlgorithm.compute("zwa").get should equal ("sw") + + // v + MetaphoneAlgorithm.compute("v").get should equal ("f") + MetaphoneAlgorithm.compute("zv").get should equal ("sf") + MetaphoneAlgorithm.compute("zvz").get should equal ("sfs") + + // u + MetaphoneAlgorithm.compute("u").get should equal ("u") + MetaphoneAlgorithm.compute("zu").get should equal ("s") + + // t + MetaphoneAlgorithm.compute("t").get should equal ("t") + MetaphoneAlgorithm.compute("ztiaz").get should equal ("sxs") + MetaphoneAlgorithm.compute("ztioz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zthz").get should equal ("s0s") + MetaphoneAlgorithm.compute("ztchz").get should equal ("sxs") + MetaphoneAlgorithm.compute("ztz").get should equal ("sts") + + // s + MetaphoneAlgorithm.compute("s").get should equal ("s") + MetaphoneAlgorithm.compute("zshz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zsioz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zsiaz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zs").get should equal ("ss") + MetaphoneAlgorithm.compute("zsz").get should equal ("sss") + + // r + MetaphoneAlgorithm.compute("r").get should equal ("r") + MetaphoneAlgorithm.compute("zr").get should equal ("sr") + MetaphoneAlgorithm.compute("zrz").get should equal ("srs") + + // q + MetaphoneAlgorithm.compute("q").get should equal ("k") + MetaphoneAlgorithm.compute("zq").get should equal ("sk") + MetaphoneAlgorithm.compute("zqz").get should equal ("sks") + + // p + MetaphoneAlgorithm.compute("p").get should equal ("p") + MetaphoneAlgorithm.compute("zp").get should equal ("sp") + MetaphoneAlgorithm.compute("zph").get should equal ("sf") + MetaphoneAlgorithm.compute("zpz").get should equal ("sps") + + // o + MetaphoneAlgorithm.compute("o").get should equal ("o") + MetaphoneAlgorithm.compute("zo").get should equal ("s") + + // n + MetaphoneAlgorithm.compute("n").get should equal ("n") + MetaphoneAlgorithm.compute("zn").get should equal ("sn") + MetaphoneAlgorithm.compute("znz").get should equal ("sns") + + // m + MetaphoneAlgorithm.compute("m").get should equal ("m") + MetaphoneAlgorithm.compute("zm").get should equal ("sm") + MetaphoneAlgorithm.compute("zmz").get should equal ("sms") + + // l + MetaphoneAlgorithm.compute("l").get should equal ("l") + MetaphoneAlgorithm.compute("zl").get should equal ("sl") + MetaphoneAlgorithm.compute("zlz").get should equal ("sls") + + // k + MetaphoneAlgorithm.compute("k").get should equal ("k") + MetaphoneAlgorithm.compute("zk").get should equal ("sk") + MetaphoneAlgorithm.compute("zck").get should equal ("sk") + + // j + MetaphoneAlgorithm.compute("j").get should equal ("j") + MetaphoneAlgorithm.compute("zj").get should equal ("sj") + MetaphoneAlgorithm.compute("zjz").get should equal ("sjs") + + // i + MetaphoneAlgorithm.compute("i").get should equal ("i") + MetaphoneAlgorithm.compute("zi").get should equal ("s") + + // h + MetaphoneAlgorithm.compute("h").get should equal ("h") // php wrongly says nothing + MetaphoneAlgorithm.compute("zh").get should equal ("sh") // php wrongly says s + MetaphoneAlgorithm.compute("zah").get should equal ("s") + MetaphoneAlgorithm.compute("zchh").get should equal ("sx") + MetaphoneAlgorithm.compute("ha").get should equal ("h") + + // g + MetaphoneAlgorithm.compute("g").get should equal ("k") + MetaphoneAlgorithm.compute("zg").get should equal ("sk") + MetaphoneAlgorithm.compute("zgh").get should equal ("skh") // php wrongly says sf + MetaphoneAlgorithm.compute("zghz").get should equal ("shs") // php wrongly says sfs + MetaphoneAlgorithm.compute("zgha").get should equal ("sh") // php wrongly says sf others wrongly say skh + MetaphoneAlgorithm.compute("zgn").get should equal ("sn") + MetaphoneAlgorithm.compute("zgns").get should equal ("skns") + MetaphoneAlgorithm.compute("zgned").get should equal ("snt") // others wrongly says sknt + MetaphoneAlgorithm.compute("zgneds").get should equal ("sknts") // php wrongly says snts + MetaphoneAlgorithm.compute("zgi").get should equal ("sj") + MetaphoneAlgorithm.compute("zgiz").get should equal ("sjs") + MetaphoneAlgorithm.compute("zge").get should equal ("sj") + MetaphoneAlgorithm.compute("zgez").get should equal ("sjs") + MetaphoneAlgorithm.compute("zgy").get should equal ("sj") + MetaphoneAlgorithm.compute("zgyz").get should equal ("sjs") + MetaphoneAlgorithm.compute("zgz").get should equal ("sks") + + // f + MetaphoneAlgorithm.compute("f").get should equal ("f") + MetaphoneAlgorithm.compute("zf").get should equal ("sf") + MetaphoneAlgorithm.compute("zfz").get should equal ("sfs") + + // e + MetaphoneAlgorithm.compute("e").get should equal ("e") + MetaphoneAlgorithm.compute("ze").get should equal ("s") + + // d + MetaphoneAlgorithm.compute("d").get should equal ("t") + MetaphoneAlgorithm.compute("fudge").get should equal ("fjj") // php wrongly says fj + MetaphoneAlgorithm.compute("dodgy").get should equal ("tjj") // php wrongly says tj others wrongly say tjjy + MetaphoneAlgorithm.compute("dodgi").get should equal ("tjj") // php wrongly says tj + MetaphoneAlgorithm.compute("zd").get should equal ("st") + MetaphoneAlgorithm.compute("zdz").get should equal ("sts") + + // c + MetaphoneAlgorithm.compute("c").get should equal ("k") + MetaphoneAlgorithm.compute("zcia").get should equal ("sx") + MetaphoneAlgorithm.compute("zciaz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zch").get should equal ("sx") + MetaphoneAlgorithm.compute("zchz").get should equal ("sxs") + MetaphoneAlgorithm.compute("zci").get should equal ("ss") + MetaphoneAlgorithm.compute("zciz").get should equal ("sss") + MetaphoneAlgorithm.compute("zce").get should equal ("ss") + MetaphoneAlgorithm.compute("zcez").get should equal ("sss") + MetaphoneAlgorithm.compute("zcy").get should equal ("ss") + MetaphoneAlgorithm.compute("zcyz").get should equal ("sss") + MetaphoneAlgorithm.compute("zsci").get should equal ("ss") + MetaphoneAlgorithm.compute("zsciz").get should equal ("sss") + MetaphoneAlgorithm.compute("zsce").get should equal ("ss") + MetaphoneAlgorithm.compute("zscez").get should equal ("sss") + MetaphoneAlgorithm.compute("zscy").get should equal ("ss") + MetaphoneAlgorithm.compute("zscyz").get should equal ("sss") + MetaphoneAlgorithm.compute("zsch").get should equal ("sskh") // php wrongly says ssx + MetaphoneAlgorithm.compute("zc").get should equal ("sk") + MetaphoneAlgorithm.compute("zcz").get should equal ("sks") + + // b + MetaphoneAlgorithm.compute("b").get should equal ("b") + MetaphoneAlgorithm.compute("zb").get should equal ("sb") + MetaphoneAlgorithm.compute("zbz").get should equal ("sbs") + MetaphoneAlgorithm.compute("zmb").get should equal ("sm") + + // a + MetaphoneAlgorithm.compute("a").get should equal ("a") + MetaphoneAlgorithm.compute("za").get should equal ("s") + + // Miscellaneous. + MetaphoneAlgorithm.compute("dumb").get should equal ("tm") + MetaphoneAlgorithm.compute("smith").get should equal ("sm0") + MetaphoneAlgorithm.compute("school").get should equal ("skhl") // php wrongly says sxl + MetaphoneAlgorithm.compute("merci").get should equal ("mrs") + MetaphoneAlgorithm.compute("cool").get should equal ("kl") + MetaphoneAlgorithm.compute("aebersold").get should equal ("ebrslt") + MetaphoneAlgorithm.compute("gnagy").get should equal ("nj") + MetaphoneAlgorithm.compute("knuth").get should equal ("n0") + MetaphoneAlgorithm.compute("pniewski").get should equal ("nsk") + MetaphoneAlgorithm.compute("wright").get should equal ("rht") // php wrongly says rft + MetaphoneAlgorithm.compute("phone").get should equal ("fn") + MetaphoneAlgorithm.compute("aggregate").get should equal ("akrkt") + MetaphoneAlgorithm.compute("accuracy").get should equal ("akkrs") + MetaphoneAlgorithm.compute("encyclopedia").get should equal ("ensklpt") + MetaphoneAlgorithm.compute("honorificabilitudinitatibus").get should equal ("hnrfkblttnttbs") + MetaphoneAlgorithm.compute("antidisestablishmentarianism").get should equal ("anttsstblxmntrnsm") + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala new file mode 100755 index 0000000..93de46e --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/MetaphoneMetricSpec.scala @@ -0,0 +1,41 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class MetaphoneMetricSpec extends ScalaTest { + "MetaphoneMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + MetaphoneMetric.compare("", "").isDefined should be (false) + MetaphoneMetric.compare("abc", "").isDefined should be (false) + MetaphoneMetric.compare("", "xyz").isDefined should be (false) + } + } + "non-phonetic arguments" should returns { + "None" in { + MetaphoneMetric.compare("123", "123").isDefined should be (false) + MetaphoneMetric.compare("123", "").isDefined should be (false) + MetaphoneMetric.compare("", "123").isDefined should be (false) + } + } + "phonetically similar arguments" should returns { + "Boolean indicating true" in { + MetaphoneMetric.compare("dumb", "dum").get should be (true) + MetaphoneMetric.compare("smith", "smeth").get should be (true) + MetaphoneMetric.compare("merci", "mercy").get should be (true) + } + } + "phonetically dissimilar arguments" should returns { + "Boolean indicating false" in { + MetaphoneMetric.compare("dumb", "gum").get should be (false) + MetaphoneMetric.compare("smith", "kiss").get should be (false) + MetaphoneMetric.compare("merci", "burpy").get should be (false) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala new file mode 100755 index 0000000..d2af38f --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisAlgorithmSpec.scala @@ -0,0 +1,191 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class NysiisAlgorithmSpec extends ScalaTest { + "NysiisAlgorithm" should provide { + "compute method" when passed { + "empty argument" should returns { + "None" in { + NysiisAlgorithm.compute("").isDefined should be (false) + } + } + "non-phonetic argument" should returns { + "None" in { + NysiisAlgorithm.compute("123").isDefined should be (false) + } + } + "phonetic argument" should returns { + "Some" in { + // a + NysiisAlgorithm.compute("a").get should equal ("a") + NysiisAlgorithm.compute("aa").get should equal ("a") + + // b + NysiisAlgorithm.compute("b").get should equal ("b") + NysiisAlgorithm.compute("bb").get should equal ("bb") + + // c + NysiisAlgorithm.compute("c").get should equal ("c") + NysiisAlgorithm.compute("cc").get should equal ("cc") + + // d + NysiisAlgorithm.compute("d").get should equal ("d") + NysiisAlgorithm.compute("dd").get should equal ("dd") + + // e + NysiisAlgorithm.compute("e").get should equal ("e") + NysiisAlgorithm.compute("ee").get should equal ("y") + + // f + NysiisAlgorithm.compute("f").get should equal ("f") + NysiisAlgorithm.compute("ff").get should equal ("ff") + + // g + NysiisAlgorithm.compute("g").get should equal ("g") + NysiisAlgorithm.compute("gg").get should equal ("gg") + + // h + NysiisAlgorithm.compute("h").get should equal ("h") + NysiisAlgorithm.compute("hh").get should equal ("hh") + + // i + NysiisAlgorithm.compute("i").get should equal ("i") + NysiisAlgorithm.compute("ii").get should equal ("i") + + // j + NysiisAlgorithm.compute("j").get should equal ("j") + NysiisAlgorithm.compute("jj").get should equal ("jj") + + // k + NysiisAlgorithm.compute("k").get should equal ("c") + NysiisAlgorithm.compute("kk").get should equal ("cc") + + // l + NysiisAlgorithm.compute("l").get should equal ("l") + NysiisAlgorithm.compute("ll").get should equal ("ll") + + // m + NysiisAlgorithm.compute("m").get should equal ("m") + NysiisAlgorithm.compute("mm").get should equal ("mn") + + // n + NysiisAlgorithm.compute("n").get should equal ("n") + NysiisAlgorithm.compute("nn").get should equal ("nn") + + // o + NysiisAlgorithm.compute("o").get should equal ("o") + NysiisAlgorithm.compute("oo").get should equal ("o") + + // p + NysiisAlgorithm.compute("p").get should equal ("p") + NysiisAlgorithm.compute("pp").get should equal ("pp") + + // q + NysiisAlgorithm.compute("q").get should equal ("q") + NysiisAlgorithm.compute("qq").get should equal ("qg") + + // r + NysiisAlgorithm.compute("r").get should equal ("r") + NysiisAlgorithm.compute("rr").get should equal ("rr") + + // s + NysiisAlgorithm.compute("s").get should equal ("s") + NysiisAlgorithm.compute("ss").get should equal ("s") + + // t + NysiisAlgorithm.compute("t").get should equal ("t") + NysiisAlgorithm.compute("tt").get should equal ("tt") + + // u + NysiisAlgorithm.compute("u").get should equal ("u") + NysiisAlgorithm.compute("uu").get should equal ("u") + + // v + NysiisAlgorithm.compute("v").get should equal ("v") + NysiisAlgorithm.compute("vv").get should equal ("vv") + + // w + NysiisAlgorithm.compute("w").get should equal ("w") + NysiisAlgorithm.compute("ww").get should equal ("ww") + + // x + NysiisAlgorithm.compute("x").get should equal ("x") + NysiisAlgorithm.compute("xx").get should equal ("xx") + + // y + NysiisAlgorithm.compute("y").get should equal ("y") + NysiisAlgorithm.compute("yy").get should equal ("yy") + + // z + NysiisAlgorithm.compute("z").get should equal ("z") + NysiisAlgorithm.compute("zz").get should equal ("z") + + // Head cases. + NysiisAlgorithm.compute("mac").get should equal ("mc") + NysiisAlgorithm.compute("kn").get should equal ("nn") + NysiisAlgorithm.compute("k").get should equal ("c") + NysiisAlgorithm.compute("ph").get should equal ("ff") + NysiisAlgorithm.compute("pf").get should equal ("ff") + NysiisAlgorithm.compute("sch").get should equal ("s") // dropby wrongly says ss + + // Last cases. + NysiisAlgorithm.compute("ee").get should equal ("y") + NysiisAlgorithm.compute("ie").get should equal ("y") + NysiisAlgorithm.compute("dt").get should equal ("d") + NysiisAlgorithm.compute("rt").get should equal ("d") + NysiisAlgorithm.compute("rd").get should equal ("d") + NysiisAlgorithm.compute("nt").get should equal ("d") + NysiisAlgorithm.compute("nd").get should equal ("d") + + // Core cases. + NysiisAlgorithm.compute("eev").get should equal ("eaf") + NysiisAlgorithm.compute("zev").get should equal ("zaf") + NysiisAlgorithm.compute("kkn").get should equal ("cn") + NysiisAlgorithm.compute("sschn").get should equal ("ssn") + NysiisAlgorithm.compute("pph").get should equal ("pf") + + // Miscellaneous. + NysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") + NysiisAlgorithm.compute("phone").get should equal ("ffan") + NysiisAlgorithm.compute("aggregate").get should equal ("agragat") + NysiisAlgorithm.compute("accuracy").get should equal ("acaracy") + NysiisAlgorithm.compute("encyclopedia").get should equal ("encyclapad") + NysiisAlgorithm.compute("honorificabilitudinitatibus").get should equal ("hanarafacabalatadanatatab") + NysiisAlgorithm.compute("antidisestablishmentarianism").get should equal ("antadasastablasnantaranasn") + + // Dropby. + NysiisAlgorithm.compute("macintosh").get should equal ("mcant") + NysiisAlgorithm.compute("knuth").get should equal ("nnat") + NysiisAlgorithm.compute("koehn").get should equal ("can") // dropby wrongly says c + NysiisAlgorithm.compute("phillipson").get should equal ("ffalapsan") + NysiisAlgorithm.compute("pfeister").get should equal ("ffastar") + NysiisAlgorithm.compute("schoenhoeft").get should equal ("ssanaft") + NysiisAlgorithm.compute("mckee").get should equal ("mcy") + NysiisAlgorithm.compute("heitschmedt").get should equal ("hatsnad") + NysiisAlgorithm.compute("bart").get should equal ("bad") + NysiisAlgorithm.compute("hurd").get should equal ("had") + NysiisAlgorithm.compute("hunt").get should equal ("had") + NysiisAlgorithm.compute("westerlund").get should equal ("wastarlad") + NysiisAlgorithm.compute("casstevens").get should equal ("castafan") + NysiisAlgorithm.compute("vasquez").get should equal ("vasg") + NysiisAlgorithm.compute("frazier").get should equal ("frasar") + NysiisAlgorithm.compute("bowman").get should equal ("banan") + NysiisAlgorithm.compute("mcknight").get should equal ("mcnagt") + NysiisAlgorithm.compute("rickert").get should equal ("racad") + NysiisAlgorithm.compute("deutsch").get should equal ("dat") // dropby wrongly says dats + NysiisAlgorithm.compute("westphal").get should equal ("wastfal") + NysiisAlgorithm.compute("shriver").get should equal ("shravar") + NysiisAlgorithm.compute("kuhl").get should equal ("cal") // dropby wrongly says c + NysiisAlgorithm.compute("rawson").get should equal ("rasan") + NysiisAlgorithm.compute("jiles").get should equal ("jal") + NysiisAlgorithm.compute("carraway").get should equal ("caray") + NysiisAlgorithm.compute("yamada").get should equal ("yanad") + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala new file mode 100755 index 0000000..3e53211 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/NysiisMetricSpec.scala @@ -0,0 +1,37 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class NysiisMetricSpec extends ScalaTest { + "NysiisMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + NysiisMetric.compare("", "").isDefined should be (false) + NysiisMetric.compare("abc", "").isDefined should be (false) + NysiisMetric.compare("", "xyz").isDefined should be (false) + } + } + "non-phonetic arguments" should returns { + "None" in { + NysiisMetric.compare("123", "123").isDefined should be (false) + NysiisMetric.compare("123", "").isDefined should be (false) + NysiisMetric.compare("", "123").isDefined should be (false) + } + } + "phonetically similar arguments" should returns { + "Boolean indicating true" in { + NysiisMetric.compare("ham", "hum").get should be (true) + } + } + "phonetically dissimilar arguments" should returns { + "Boolean indicating false" in { + NysiisMetric.compare("dumb", "gum").get should be (false) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala new file mode 100755 index 0000000..fce2811 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisAlgorithmSpec.scala @@ -0,0 +1,208 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class RefinedNysiisAlgorithmSpec extends ScalaTest { + "RefinedNysiisAlgorithm" should provide { + "compute method" when passed { + "empty argument" should returns { + "None" in { + RefinedNysiisAlgorithm.compute("").isDefined should be (false) + } + } + "non-phonetic argument" should returns { + "None" in { + RefinedNysiisAlgorithm.compute("123").isDefined should be (false) + } + } + "phonetic argument" should returns { + "Some" in { + // a + RefinedNysiisAlgorithm.compute("a").get should equal ("a") + RefinedNysiisAlgorithm.compute("aa").get should equal ("a") + + // b + RefinedNysiisAlgorithm.compute("b").get should equal ("b") + RefinedNysiisAlgorithm.compute("bb").get should equal ("b") + + // c + RefinedNysiisAlgorithm.compute("c").get should equal ("c") + RefinedNysiisAlgorithm.compute("cc").get should equal ("c") + + // d + RefinedNysiisAlgorithm.compute("d").get should equal ("d") + RefinedNysiisAlgorithm.compute("dd").get should equal ("d") + + // e + RefinedNysiisAlgorithm.compute("e").get should equal ("e") + RefinedNysiisAlgorithm.compute("ee").get should equal ("y") + + // f + RefinedNysiisAlgorithm.compute("f").get should equal ("f") + RefinedNysiisAlgorithm.compute("ff").get should equal ("f") + + // g + RefinedNysiisAlgorithm.compute("g").get should equal ("g") + RefinedNysiisAlgorithm.compute("gg").get should equal ("g") + + // h + RefinedNysiisAlgorithm.compute("h").get should equal ("h") + RefinedNysiisAlgorithm.compute("hh").get should equal ("h") + + // i + RefinedNysiisAlgorithm.compute("i").get should equal ("i") + RefinedNysiisAlgorithm.compute("ii").get should equal ("i") + + // j + RefinedNysiisAlgorithm.compute("j").get should equal ("j") + RefinedNysiisAlgorithm.compute("jj").get should equal ("j") + + // k + RefinedNysiisAlgorithm.compute("k").get should equal ("c") + RefinedNysiisAlgorithm.compute("kk").get should equal ("c") + + // l + RefinedNysiisAlgorithm.compute("l").get should equal ("l") + RefinedNysiisAlgorithm.compute("ll").get should equal ("l") + + // m + RefinedNysiisAlgorithm.compute("m").get should equal ("m") + RefinedNysiisAlgorithm.compute("mm").get should equal ("mn") + + // n + RefinedNysiisAlgorithm.compute("n").get should equal ("n") + RefinedNysiisAlgorithm.compute("nn").get should equal ("n") + + // o + RefinedNysiisAlgorithm.compute("o").get should equal ("o") + RefinedNysiisAlgorithm.compute("oo").get should equal ("o") + + // p + RefinedNysiisAlgorithm.compute("p").get should equal ("p") + RefinedNysiisAlgorithm.compute("pp").get should equal ("p") + + // q + RefinedNysiisAlgorithm.compute("q").get should equal ("q") + RefinedNysiisAlgorithm.compute("qq").get should equal ("qg") + + // r + RefinedNysiisAlgorithm.compute("r").get should equal ("r") + RefinedNysiisAlgorithm.compute("rr").get should equal ("r") + + // s + RefinedNysiisAlgorithm.compute("s").get should equal ("s") + RefinedNysiisAlgorithm.compute("ss").get should equal ("s") + + // t + RefinedNysiisAlgorithm.compute("t").get should equal ("t") + RefinedNysiisAlgorithm.compute("tt").get should equal ("t") + + // u + RefinedNysiisAlgorithm.compute("u").get should equal ("u") + RefinedNysiisAlgorithm.compute("uu").get should equal ("u") + + // v + RefinedNysiisAlgorithm.compute("v").get should equal ("v") + RefinedNysiisAlgorithm.compute("vv").get should equal ("v") + + // w + RefinedNysiisAlgorithm.compute("w").get should equal ("w") + RefinedNysiisAlgorithm.compute("ww").get should equal ("w") + + // x + RefinedNysiisAlgorithm.compute("x").get should equal ("x") + RefinedNysiisAlgorithm.compute("xx").get should equal ("x") + + // y + RefinedNysiisAlgorithm.compute("y").get should equal ("y") + RefinedNysiisAlgorithm.compute("yy").get should equal ("y") + RefinedNysiisAlgorithm.compute("ybyb").get should equal ("ybab") + + // z + RefinedNysiisAlgorithm.compute("z").get should equal ("z") + RefinedNysiisAlgorithm.compute("zz").get should equal ("z") + + // Head cases. + RefinedNysiisAlgorithm.compute("mac").get should equal ("mc") + RefinedNysiisAlgorithm.compute("pf").get should equal ("f") + + // Last cases. + RefinedNysiisAlgorithm.compute("ix").get should equal ("ic") + RefinedNysiisAlgorithm.compute("ex").get should equal ("ec") + RefinedNysiisAlgorithm.compute("ye").get should equal ("y") + RefinedNysiisAlgorithm.compute("ee").get should equal ("y") + RefinedNysiisAlgorithm.compute("ie").get should equal ("y") + RefinedNysiisAlgorithm.compute("dt").get should equal ("d") + RefinedNysiisAlgorithm.compute("rt").get should equal ("d") + RefinedNysiisAlgorithm.compute("rd").get should equal ("d") + RefinedNysiisAlgorithm.compute("nt").get should equal ("d") + RefinedNysiisAlgorithm.compute("nd").get should equal ("d") + + // Core cases. + RefinedNysiisAlgorithm.compute("bevb").get should equal ("bafb") + RefinedNysiisAlgorithm.compute("bghtb").get should equal ("bgtb") + RefinedNysiisAlgorithm.compute("bdgb").get should equal ("bgb") + RefinedNysiisAlgorithm.compute("bphb").get should equal ("bfb") + RefinedNysiisAlgorithm.compute("bknb").get should equal ("bnb") + RefinedNysiisAlgorithm.compute("bshb").get should equal ("bsb") + RefinedNysiisAlgorithm.compute("bschb").get should equal ("bsb") + RefinedNysiisAlgorithm.compute("bywb").get should equal ("bab") + RefinedNysiisAlgorithm.compute("byw").get should equal ("by") + RefinedNysiisAlgorithm.compute("ywb").get should equal ("yb") + RefinedNysiisAlgorithm.compute("bwrb").get should equal ("brb") + + // Transcode cases. + RefinedNysiisAlgorithm.compute("bay").get should equal ("by") + + // Miscellaneous. + RefinedNysiisAlgorithm.compute("macdonald").get should equal ("mcdanald") + RefinedNysiisAlgorithm.compute("phone").get should equal ("fan") + RefinedNysiisAlgorithm.compute("aggregate").get should equal ("agragat") + RefinedNysiisAlgorithm.compute("accuracy").get should equal ("acaracy") + RefinedNysiisAlgorithm.compute("encyclopedia").get should equal ("encaclapad") + RefinedNysiisAlgorithm.compute("honorificabilitudinitatibus").get should equal ("hanarafacabalatadanatatab") + RefinedNysiisAlgorithm.compute("antidisestablishmentarianism").get should equal ("antadasastablasnantaranasn") + + // Dropby. + RefinedNysiisAlgorithm.compute("edwards").get should equal ("edwad") + RefinedNysiisAlgorithm.compute("parez").get should equal ("par") + RefinedNysiisAlgorithm.compute("macintosh").get should equal ("mcantas") + RefinedNysiisAlgorithm.compute("phillipson").get should equal ("falapsan") + RefinedNysiisAlgorithm.compute("haddix").get should equal ("hadac") + RefinedNysiisAlgorithm.compute("essex").get should equal ("esac") + RefinedNysiisAlgorithm.compute("moye").get should equal ("my") + RefinedNysiisAlgorithm.compute("mckee").get should equal ("mcy") + RefinedNysiisAlgorithm.compute("mackie").get should equal ("mcy") + RefinedNysiisAlgorithm.compute("heitschmidt").get should equal ("hatsnad") + RefinedNysiisAlgorithm.compute("bart").get should equal ("bad") + RefinedNysiisAlgorithm.compute("hurd").get should equal ("had") + RefinedNysiisAlgorithm.compute("hunt").get should equal ("had") + RefinedNysiisAlgorithm.compute("westerlund").get should equal ("wastarlad") + RefinedNysiisAlgorithm.compute("evers").get should equal ("evar") + RefinedNysiisAlgorithm.compute("devito").get should equal ("dafat") + RefinedNysiisAlgorithm.compute("rawson").get should equal ("rasan") + RefinedNysiisAlgorithm.compute("shoulders").get should equal ("saldar") + RefinedNysiisAlgorithm.compute("leighton").get should equal ("lagtan") + RefinedNysiisAlgorithm.compute("wooldridge").get should equal ("waldrag") + RefinedNysiisAlgorithm.compute("oliphant").get should equal ("olafad") + RefinedNysiisAlgorithm.compute("hatchett").get should equal ("hatcat") + RefinedNysiisAlgorithm.compute("mcknight").get should equal ("mcnagt") + RefinedNysiisAlgorithm.compute("rickert").get should equal ("racad") + RefinedNysiisAlgorithm.compute("bowman").get should equal ("banan") + RefinedNysiisAlgorithm.compute("vasquez").get should equal ("vasg") + RefinedNysiisAlgorithm.compute("bashaw").get should equal ("bas") + RefinedNysiisAlgorithm.compute("schoenhoeft").get should equal ("sanaft") // dropby wrongly says scanaft + RefinedNysiisAlgorithm.compute("heywood").get should equal ("had") + RefinedNysiisAlgorithm.compute("hayman").get should equal ("hanan") + RefinedNysiisAlgorithm.compute("seawright").get should equal ("saragt") + RefinedNysiisAlgorithm.compute("kratzer").get should equal ("cratsar") + RefinedNysiisAlgorithm.compute("canaday").get should equal ("canady") + RefinedNysiisAlgorithm.compute("crepeau").get should equal ("crap") + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala new file mode 100755 index 0000000..46b177b --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedNysiisMetricSpec.scala @@ -0,0 +1,37 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class RefinedNysiisMetricSpec extends ScalaTest { + "RefinedNysiisMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + RefinedNysiisMetric.compare("", "").isDefined should be (false) + RefinedNysiisMetric.compare("abc", "").isDefined should be (false) + RefinedNysiisMetric.compare("", "xyz").isDefined should be (false) + } + } + "non-phonetic arguments" should returns { + "None" in { + RefinedNysiisMetric.compare("123", "123").isDefined should be (false) + RefinedNysiisMetric.compare("123", "").isDefined should be (false) + RefinedNysiisMetric.compare("", "123").isDefined should be (false) + } + } + "phonetically similar arguments" should returns { + "Boolean indicating true" in { + RefinedNysiisMetric.compare("ham", "hum").get should be (true) + } + } + "phonetically dissimilar arguments" should returns { + "Boolean indicating false" in { + RefinedNysiisMetric.compare("dumb", "gum").get should be (false) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala new file mode 100755 index 0000000..57e32cf --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexAlgorithmSpec.scala @@ -0,0 +1,162 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class RefinedSoundexAlgorithmSpec extends ScalaTest { + "RefinedSoundexAlgorithm" should provide { + "compute method" when passed { + "empty argument" should returns { + "None" in { + RefinedSoundexAlgorithm.compute("").isDefined should be (false) + } + } + "non-phonetic argument" should returns { + "None" in { + RefinedSoundexAlgorithm.compute("123").isDefined should be (false) + } + } + "phonetic argument" should returns { + "Some" in { + // a + RefinedSoundexAlgorithm.compute("a").get should equal ("a0") + RefinedSoundexAlgorithm.compute("aa").get should equal ("a0") + + // b + RefinedSoundexAlgorithm.compute("b").get should equal ("b1") + RefinedSoundexAlgorithm.compute("bb").get should equal ("b1") + + // c + RefinedSoundexAlgorithm.compute("c").get should equal ("c3") + RefinedSoundexAlgorithm.compute("cc").get should equal ("c3") + + // d + RefinedSoundexAlgorithm.compute("d").get should equal ("d6") + RefinedSoundexAlgorithm.compute("dd").get should equal ("d6") + + // e + RefinedSoundexAlgorithm.compute("e").get should equal ("e0") + RefinedSoundexAlgorithm.compute("ee").get should equal ("e0") + + // f + RefinedSoundexAlgorithm.compute("f").get should equal ("f2") + RefinedSoundexAlgorithm.compute("ff").get should equal ("f2") + + // g + RefinedSoundexAlgorithm.compute("g").get should equal ("g4") + RefinedSoundexAlgorithm.compute("gg").get should equal ("g4") + + // h + RefinedSoundexAlgorithm.compute("h").get should equal ("h0") + RefinedSoundexAlgorithm.compute("hh").get should equal ("h0") + + // i + RefinedSoundexAlgorithm.compute("i").get should equal ("i0") + RefinedSoundexAlgorithm.compute("ii").get should equal ("i0") + + // j + RefinedSoundexAlgorithm.compute("j").get should equal ("j4") + RefinedSoundexAlgorithm.compute("jj").get should equal ("j4") + + // k + RefinedSoundexAlgorithm.compute("k").get should equal ("k3") + RefinedSoundexAlgorithm.compute("kk").get should equal ("k3") + + // l + RefinedSoundexAlgorithm.compute("l").get should equal ("l7") + RefinedSoundexAlgorithm.compute("ll").get should equal ("l7") + + // m + RefinedSoundexAlgorithm.compute("m").get should equal ("m8") + RefinedSoundexAlgorithm.compute("mm").get should equal ("m8") + + // n + RefinedSoundexAlgorithm.compute("n").get should equal ("n8") + RefinedSoundexAlgorithm.compute("nn").get should equal ("n8") + + // o + RefinedSoundexAlgorithm.compute("o").get should equal ("o0") + RefinedSoundexAlgorithm.compute("oo").get should equal ("o0") + + // p + RefinedSoundexAlgorithm.compute("p").get should equal ("p1") + RefinedSoundexAlgorithm.compute("pp").get should equal ("p1") + + // q + RefinedSoundexAlgorithm.compute("q").get should equal ("q5") + RefinedSoundexAlgorithm.compute("qq").get should equal ("q5") + + // r + RefinedSoundexAlgorithm.compute("r").get should equal ("r9") + RefinedSoundexAlgorithm.compute("rr").get should equal ("r9") + + // s + RefinedSoundexAlgorithm.compute("s").get should equal ("s3") + RefinedSoundexAlgorithm.compute("ss").get should equal ("s3") + + // t + RefinedSoundexAlgorithm.compute("t").get should equal ("t6") + RefinedSoundexAlgorithm.compute("tt").get should equal ("t6") + + // u + RefinedSoundexAlgorithm.compute("u").get should equal ("u0") + RefinedSoundexAlgorithm.compute("uu").get should equal ("u0") + + // v + RefinedSoundexAlgorithm.compute("v").get should equal ("v2") + RefinedSoundexAlgorithm.compute("vv").get should equal ("v2") + + // w + RefinedSoundexAlgorithm.compute("w").get should equal ("w0") + RefinedSoundexAlgorithm.compute("ww").get should equal ("w0") + + // x + RefinedSoundexAlgorithm.compute("x").get should equal ("x5") + RefinedSoundexAlgorithm.compute("xx").get should equal ("x5") + + // y + RefinedSoundexAlgorithm.compute("y").get should equal ("y0") + RefinedSoundexAlgorithm.compute("yy").get should equal ("y0") + + // z + RefinedSoundexAlgorithm.compute("z").get should equal ("z5") + RefinedSoundexAlgorithm.compute("zz").get should equal ("z5") + + // Starting with letter then numbers. + RefinedSoundexAlgorithm.compute("x123456").get should equal ("x5") + RefinedSoundexAlgorithm.compute("a123456").get should equal ("a0") + RefinedSoundexAlgorithm.compute("f123456").get should equal ("f2") + + // Miscellaneous. + RefinedSoundexAlgorithm.compute("braz").get should equal ("b1905") + RefinedSoundexAlgorithm.compute("broz").get should equal ("b1905") + RefinedSoundexAlgorithm.compute("caren").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("carren").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("coram").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("corran").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("curreen").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("curwen").get should equal ("c30908") + RefinedSoundexAlgorithm.compute("hairs").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hark").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hars").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hayers").get should equal ("h093") + RefinedSoundexAlgorithm.compute("heers").get should equal ("h093") + RefinedSoundexAlgorithm.compute("hiers").get should equal ("h093") + RefinedSoundexAlgorithm.compute("lambard").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lambart").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lambert").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lambird").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lampaert").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lampart").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lamport").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("limbert").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("lombard").get should equal ("l7081096") + RefinedSoundexAlgorithm.compute("nolton").get should equal ("n807608") + RefinedSoundexAlgorithm.compute("noulton").get should equal ("n807608") + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala new file mode 100755 index 0000000..97a168b --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/RefinedSoundexMetricSpec.scala @@ -0,0 +1,37 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class RefinedSoundexMetricSpec extends ScalaTest { + "RefinedSoundexMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + RefinedSoundexMetric.compare("", "").isDefined should be (false) + RefinedSoundexMetric.compare("abc", "").isDefined should be (false) + RefinedSoundexMetric.compare("", "xyz").isDefined should be (false) + } + } + "non-phonetic arguments" should returns { + "None" in { + RefinedSoundexMetric.compare("123", "123").isDefined should be (false) + RefinedSoundexMetric.compare("123", "").isDefined should be (false) + RefinedSoundexMetric.compare("", "123").isDefined should be (false) + } + } + "phonetically similar arguments" should returns { + "Boolean indicating true" in { + RefinedSoundexMetric.compare("robert", "rupert").get should be (true) + } + } + "phonetically dissimilar arguments" should returns { + "Boolean indicating false" in { + RefinedSoundexMetric.compare("robert", "rubin").get should be (false) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala new file mode 100755 index 0000000..ec8b2ba --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexAlgorithmSpec.scala @@ -0,0 +1,161 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class SoundexAlgorithmSpec extends ScalaTest { + "SoundexAlgorithm" should provide { + "compute method" when passed { + "empty argument" should returns { + "None" in { + SoundexAlgorithm.compute("").isDefined should be (false) + } + } + "non-phonetic argument" should returns { + "None" in { + SoundexAlgorithm.compute("123").isDefined should be (false) + } + } + "phonetic argument" should returns { + "Some" in { + // a + SoundexAlgorithm.compute("a").get should equal ("a000") + SoundexAlgorithm.compute("aa").get should equal ("a000") + + // b + SoundexAlgorithm.compute("b").get should equal ("b000") + SoundexAlgorithm.compute("bb").get should equal ("b000") + + // c + SoundexAlgorithm.compute("c").get should equal ("c000") + SoundexAlgorithm.compute("cc").get should equal ("c000") + + // d + SoundexAlgorithm.compute("d").get should equal ("d000") + SoundexAlgorithm.compute("dd").get should equal ("d000") + + // e + SoundexAlgorithm.compute("e").get should equal ("e000") + SoundexAlgorithm.compute("ee").get should equal ("e000") + + // f + SoundexAlgorithm.compute("f").get should equal ("f000") + SoundexAlgorithm.compute("ff").get should equal ("f000") + + // g + SoundexAlgorithm.compute("g").get should equal ("g000") + SoundexAlgorithm.compute("gg").get should equal ("g000") + + // h + SoundexAlgorithm.compute("h").get should equal ("h000") + SoundexAlgorithm.compute("hh").get should equal ("h000") + + // i + SoundexAlgorithm.compute("i").get should equal ("i000") + SoundexAlgorithm.compute("ii").get should equal ("i000") + + // j + SoundexAlgorithm.compute("j").get should equal ("j000") + SoundexAlgorithm.compute("jj").get should equal ("j000") + + // k + SoundexAlgorithm.compute("k").get should equal ("k000") + SoundexAlgorithm.compute("kk").get should equal ("k000") + + // l + SoundexAlgorithm.compute("l").get should equal ("l000") + SoundexAlgorithm.compute("ll").get should equal ("l000") + + // m + SoundexAlgorithm.compute("m").get should equal ("m000") + SoundexAlgorithm.compute("mm").get should equal ("m000") + + // n + SoundexAlgorithm.compute("n").get should equal ("n000") + SoundexAlgorithm.compute("nn").get should equal ("n000") + + // o + SoundexAlgorithm.compute("o").get should equal ("o000") + SoundexAlgorithm.compute("oo").get should equal ("o000") + + // p + SoundexAlgorithm.compute("p").get should equal ("p000") + SoundexAlgorithm.compute("pp").get should equal ("p000") + + // q + SoundexAlgorithm.compute("q").get should equal ("q000") + SoundexAlgorithm.compute("qq").get should equal ("q000") + + // r + SoundexAlgorithm.compute("r").get should equal ("r000") + SoundexAlgorithm.compute("rr").get should equal ("r000") + + // s + SoundexAlgorithm.compute("s").get should equal ("s000") + SoundexAlgorithm.compute("ss").get should equal ("s000") + + // t + SoundexAlgorithm.compute("t").get should equal ("t000") + SoundexAlgorithm.compute("tt").get should equal ("t000") + + // u + SoundexAlgorithm.compute("u").get should equal ("u000") + SoundexAlgorithm.compute("uu").get should equal ("u000") + + // v + SoundexAlgorithm.compute("v").get should equal ("v000") + SoundexAlgorithm.compute("vv").get should equal ("v000") + + // w + SoundexAlgorithm.compute("w").get should equal ("w000") + SoundexAlgorithm.compute("ww").get should equal ("w000") + + // x + SoundexAlgorithm.compute("x").get should equal ("x000") + SoundexAlgorithm.compute("xx").get should equal ("x000") + + // y + SoundexAlgorithm.compute("y").get should equal ("y000") + SoundexAlgorithm.compute("yy").get should equal ("y000") + + // z + SoundexAlgorithm.compute("z").get should equal ("z000") + SoundexAlgorithm.compute("zz").get should equal ("z000") + + // Starting with letter then numbers. + SoundexAlgorithm.compute("x123456").get should equal ("x000") + SoundexAlgorithm.compute("a123456").get should equal ("a000") + SoundexAlgorithm.compute("f123456").get should equal ("f000") + + // Miscellaneous. + SoundexAlgorithm.compute("abc").get should equal ("a120") + SoundexAlgorithm.compute("xyz").get should equal ("x200") + SoundexAlgorithm.compute("robert").get should equal ("r163") + SoundexAlgorithm.compute("rupert").get should equal ("r163") + SoundexAlgorithm.compute("rubin").get should equal ("r150") + SoundexAlgorithm.compute("ashcraft").get should equal ("a261") + SoundexAlgorithm.compute("tymczak").get should equal ("t522") + SoundexAlgorithm.compute("pfister").get should equal ("p236") + SoundexAlgorithm.compute("euler").get should equal ("e460") + SoundexAlgorithm.compute("gauss").get should equal ("g200") + SoundexAlgorithm.compute("hilbert").get should equal ("h416") + SoundexAlgorithm.compute("knuth").get should equal ("k530") + SoundexAlgorithm.compute("lloyd").get should equal ("l300") + SoundexAlgorithm.compute("lukasiewicz").get should equal ("l222") + SoundexAlgorithm.compute("ashcroft").get should equal ("a261") + SoundexAlgorithm.compute("tymczak").get should equal ("t522") + SoundexAlgorithm.compute("pfister").get should equal ("p236") + SoundexAlgorithm.compute("ellery").get should equal ("e460") + SoundexAlgorithm.compute("ghosh").get should equal ("g200") + SoundexAlgorithm.compute("heilbronn").get should equal ("h416") + SoundexAlgorithm.compute("kant").get should equal ("k530") + SoundexAlgorithm.compute("ladd").get should equal ("l300") + SoundexAlgorithm.compute("lissajous").get should equal ("l222") + SoundexAlgorithm.compute("fusedale").get should equal ("f234") + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala new file mode 100755 index 0000000..78dae78 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/phonetic/SoundexMetricSpec.scala @@ -0,0 +1,37 @@ +package com.rockymadden.stringmetric.phonetic + +import com.rockymadden.stringmetric.ScalaTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner + +@RunWith(classOf[JUnitRunner]) +final class SoundexMetricSpec extends ScalaTest { + "SoundexMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + SoundexMetric.compare("", "").isDefined should be (false) + SoundexMetric.compare("abc", "").isDefined should be (false) + SoundexMetric.compare("", "xyz").isDefined should be (false) + } + } + "non-phonetic arguments" should returns { + "None" in { + SoundexMetric.compare("123", "123").isDefined should be (false) + SoundexMetric.compare("123", "").isDefined should be (false) + SoundexMetric.compare("", "123").isDefined should be (false) + } + } + "phonetically similar arguments" should returns { + "Boolean indicating true" in { + SoundexMetric.compare("robert", "rupert").get should be (true) + } + } + "phonetically dissimilar arguments" should returns { + "Boolean indicating false" in { + SoundexMetric.compare("robert", "rubin").get should be (false) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala new file mode 100755 index 0000000..4008683 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricSpec.scala @@ -0,0 +1,62 @@ +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 DiceSorensenMetricSpec extends ScalaTest { + "DiceSorensenMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + DiceSorensenMetric.compare("", "")(1).isDefined should be (false) + DiceSorensenMetric.compare("abc", "")(1).isDefined should be (false) + DiceSorensenMetric.compare("", "xyz")(1).isDefined should be (false) + } + } + "equal arguments" should returns { + "1" in { + DiceSorensenMetric.compare("abc", "abc")(1).get should be (1) + DiceSorensenMetric.compare("abc", "abc")(2).get should be (1) + DiceSorensenMetric.compare("abc", "abc")(3).get should be (1) + } + } + "unequal arguments" should returns { + "0" in { + DiceSorensenMetric.compare("abc", "xyz")(1).get should be (0) + DiceSorensenMetric.compare("abc", "xyz")(2).get should be (0) + DiceSorensenMetric.compare("abc", "xyz")(3).get should be (0) + } + } + "invalid arguments" should returns { + "None" in { + DiceSorensenMetric.compare("n", "naght")(2).isDefined should be (false) + DiceSorensenMetric.compare("night", "n")(2).isDefined should be (false) + DiceSorensenMetric.compare("ni", "naght")(3).isDefined should be (false) + DiceSorensenMetric.compare("night", "na")(3).isDefined should be (false) + } + } + "valid arguments" should returns { + "Double indicating distance" in { + DiceSorensenMetric.compare("night", "nacht")(1).get should be (0.6) + DiceSorensenMetric.compare("night", "naght")(1).get should be (0.8) + DiceSorensenMetric.compare("context", "contact")(1).get should be (0.7142857142857143) + + DiceSorensenMetric.compare("night", "nacht")(2).get should be (0.25) + DiceSorensenMetric.compare("night", "naght")(2).get should be (0.5) + DiceSorensenMetric.compare("context", "contact")(2).get should be (0.5) + DiceSorensenMetric.compare("contextcontext", "contact")(2).get should be (0.3157894736842105) + DiceSorensenMetric.compare("context", "contactcontact")(2).get should be (0.3157894736842105) + DiceSorensenMetric.compare("ht", "nacht")(2).get should be (0.4) + DiceSorensenMetric.compare("xp", "nacht")(2).get should be (0) + DiceSorensenMetric.compare("ht", "hththt")(2).get should be (0.3333333333333333) + + DiceSorensenMetric.compare("night", "nacht")(3).get should be (0) + DiceSorensenMetric.compare("night", "naght")(3).get should be (0.3333333333333333) + DiceSorensenMetric.compare("context", "contact")(3).get should be (0.4) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala new file mode 100755 index 0000000..95cdbba --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/HammingMetricSpec.scala @@ -0,0 +1,39 @@ +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 HammingMetricSpec extends ScalaTest { + "HammingMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + HammingMetric.compare("", "").isDefined should be (false) + HammingMetric.compare("abc", "").isDefined should be (false) + HammingMetric.compare("", "xyz").isDefined should be (false) + } + } + "equal arguments" should returns { + "0" in { + HammingMetric.compare("abc", "abc").get should be (0) + HammingMetric.compare("123", "123").get should be (0) + } + } + "unequal arguments" should returns { + "Int indicating distance" in { + HammingMetric.compare("abc", "xyz").get should be (3) + HammingMetric.compare("123", "456").get should be (3) + } + } + "valid arguments" should returns { + "Int indicating distance" in { + HammingMetric.compare("toned", "roses").get should be (3) + HammingMetric.compare("1011101", "1001001").get should be (2) + HammingMetric.compare("2173896", "2233796").get should be (3) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala new file mode 100755 index 0000000..e9440e4 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroMetricSpec.scala @@ -0,0 +1,53 @@ +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 JaroMetricSpec extends ScalaTest { + "JaroMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + JaroMetric.compare("", "").isDefined should be (false) + JaroMetric.compare("abc", "").isDefined should be (false) + JaroMetric.compare("", "xyz").isDefined should be (false) + } + } + "equal arguments" should returns { + "1" in { + JaroMetric.compare("a", "a").get should be (1) + JaroMetric.compare("abc", "abc").get should be (1) + JaroMetric.compare("123", "123").get should be (1) + } + } + "unequal arguments" should returns { + "0" in { + JaroMetric.compare("abc", "xyz").get should be (0) + JaroMetric.compare("123", "456").get should be (0) + } + } + "valid arguments" should returns { + "Double indicating distance" in { + JaroMetric.compare("aa", "a").get should be (0.8333333333333334) + JaroMetric.compare("a", "aa").get should be (0.8333333333333334) + JaroMetric.compare("veryveryverylong", "v").get should be (0.6875) + JaroMetric.compare("v", "veryveryverylong").get should be (0.6875) + JaroMetric.compare("martha", "marhta").get should be (0.9444444444444445) + JaroMetric.compare("dwayne", "duane").get should be (0.8222222222222223) + JaroMetric.compare("dixon", "dicksonx").get should be (0.7666666666666666) + JaroMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) + JaroMetric.compare("jones", "johnson").get should be (0.7904761904761904) + JaroMetric.compare("henka", "henkan").get should be (0.9444444444444445) + JaroMetric.compare("fvie", "ten").get should be (0) + + JaroMetric.compare("zac ephron", "zac efron").get should be > + JaroMetric.compare("zac ephron", "kai ephron").get + JaroMetric.compare("brittney spears", "britney spears").get should be > + JaroMetric.compare("brittney spears", "brittney startzman").get + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala new file mode 100755 index 0000000..c2ad5eb --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/JaroWinklerMetricSpec.scala @@ -0,0 +1,53 @@ +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 JaroWinklerMetricSpec extends ScalaTest { + "JaroWinklerMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + JaroWinklerMetric.compare("", "").isDefined should be (false) + JaroWinklerMetric.compare("abc", "").isDefined should be (false) + JaroWinklerMetric.compare("", "xyz").isDefined should be (false) + } + } + "equal arguments" should returns { + "1" in { + JaroWinklerMetric.compare("a", "a").get should be (1) + JaroWinklerMetric.compare("abc", "abc").get should be (1) + JaroWinklerMetric.compare("123", "123").get should be (1) + } + } + "unequal arguments" should returns { + "0" in { + JaroWinklerMetric.compare("abc", "xyz").get should be (0) + JaroWinklerMetric.compare("123", "456").get should be (0) + } + } + "valid arguments" should returns { + "Double indicating distance" in { + JaroWinklerMetric.compare("aa", "a").get should be (0.8500000000000001) + JaroWinklerMetric.compare("a", "aa").get should be (0.8500000000000001) + JaroWinklerMetric.compare("veryveryverylong", "v").get should be (0.71875) + JaroWinklerMetric.compare("v", "veryveryverylong").get should be (0.71875) + JaroWinklerMetric.compare("martha", "marhta").get should be (0.9611111111111111) + JaroWinklerMetric.compare("dwayne", "duane").get should be (0.8400000000000001) + JaroWinklerMetric.compare("dixon", "dicksonx").get should be (0.8133333333333332) + JaroWinklerMetric.compare("abcvwxyz", "cabvwxyz").get should be (0.9583333333333334) + JaroWinklerMetric.compare("jones", "johnson").get should be (0.8323809523809523) + JaroWinklerMetric.compare("henka", "henkan").get should be (0.9666666666666667) + JaroWinklerMetric.compare("fvie", "ten").get should be (0) + + JaroWinklerMetric.compare("zac ephron", "zac efron").get should be > + JaroWinklerMetric.compare("zac ephron", "kai ephron").get + JaroWinklerMetric.compare("brittney spears", "britney spears").get should be > + JaroWinklerMetric.compare("brittney spears", "brittney startzman").get + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala new file mode 100755 index 0000000..4f78643 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/LevenshteinMetricSpec.scala @@ -0,0 +1,52 @@ +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 LevenshteinMetricSpec extends ScalaTest { + "LevenshteinMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + LevenshteinMetric.compare("", "").isDefined should be (false) + LevenshteinMetric.compare("abc", "").isDefined should be (false) + LevenshteinMetric.compare("", "xyz").isDefined should be (false) + } + } + "equal arguments" should returns { + "0" in { + LevenshteinMetric.compare("abc", "abc").get should be (0) + LevenshteinMetric.compare("123", "123").get should be (0) + } + } + "unequal arguments" should returns { + "Int indicating distance" in { + LevenshteinMetric.compare("abc", "xyz").get should be (3) + LevenshteinMetric.compare("123", "456").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("sitting", "kitten").get should be (3) + LevenshteinMetric.compare("kitten", "sitting").get should be (3) + LevenshteinMetric.compare("cake", "drake").get should be (2) + LevenshteinMetric.compare("drake", "cake").get should be (2) + LevenshteinMetric.compare("saturday", "sunday").get should be (3) + LevenshteinMetric.compare("sunday", "saturday").get should be (3) + LevenshteinMetric.compare("book", "back").get should be (2) + LevenshteinMetric.compare("dog", "fog").get should be (1) + LevenshteinMetric.compare("foq", "fog").get should be (1) + LevenshteinMetric.compare("fvg", "fog").get should be (1) + LevenshteinMetric.compare("encyclopedia", "encyclopediaz").get should be (1) + LevenshteinMetric.compare("encyclopediz", "encyclopediaz").get should be (1) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala new file mode 100755 index 0000000..b41f37c --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramAlgorithmSpec.scala @@ -0,0 +1,53 @@ +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 NGramAlgorithmSpec extends ScalaTest { + "NGramAlgorithm" should provide { + "compute method" when passed { + "empty argument" should returns { + "None" in { + NGramAlgorithm.compute("")(1).isDefined should be (false) + } + } + "invalid n argument" should throws { + "IllegalArgumentException" in { + evaluating { + NGramAlgorithm.compute("")(0).isDefined should be (false) + } should produce [IllegalArgumentException] + + evaluating { + NGramAlgorithm.compute("")(-1).isDefined should be (false) + } should produce [IllegalArgumentException] + } + } + "valid argument" should returns { + "Array[String]" in { + NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(1).get should equal ( + Array( + "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", + "s", "t", "u", "v", "w", "x", "y", "z" + ) + ) + + NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(2).get should equal ( + Array( + "ab", "bc", "cd", "de", "ef", "fg", "gh", "hi", "ij", "jk", "kl", "lm", "mn", "no", "op", + "pq", "qr", "rs", "st", "tu", "uv", "vw", "wx", "xy", "yz" + ) + ) + + NGramAlgorithm.compute("abcdefghijklmnopqrstuvwxyz")(3).get should equal ( + Array( + "abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl", "klm", "lmn", "mno", + "nop", "opq", "pqr", "qrs", "rst", "stu", "tuv", "uvw", "vwx", "wxy", "xyz" + ) + ) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala new file mode 100755 index 0000000..a46f103 --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/NGramMetricSpec.scala @@ -0,0 +1,62 @@ +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 NGramMetricSpec extends ScalaTest { + "NGramMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + NGramMetric.compare("", "")(1).isDefined should be (false) + NGramMetric.compare("abc", "")(1).isDefined should be (false) + NGramMetric.compare("", "xyz")(1).isDefined should be (false) + } + } + "equal arguments" should returns { + "1" in { + NGramMetric.compare("abc", "abc")(1).get should be (1) + NGramMetric.compare("abc", "abc")(2).get should be (1) + NGramMetric.compare("abc", "abc")(3).get should be (1) + } + } + "unequal arguments" should returns { + "0" in { + NGramMetric.compare("abc", "xyz")(1).get should be (0) + NGramMetric.compare("abc", "xyz")(2).get should be (0) + NGramMetric.compare("abc", "xyz")(3).get should be (0) + } + } + "invalid arguments" should returns { + "None" in { + NGramMetric.compare("n", "naght")(2).isDefined should be (false) + NGramMetric.compare("night", "n")(2).isDefined should be (false) + NGramMetric.compare("ni", "naght")(3).isDefined should be (false) + NGramMetric.compare("night", "na")(3).isDefined should be (false) + } + } + "valid arguments" should returns { + "Double indicating distance" in { + NGramMetric.compare("night", "nacht")(1).get should be (0.6) + NGramMetric.compare("night", "naght")(1).get should be (0.8) + NGramMetric.compare("context", "contact")(1).get should be (0.7142857142857143) + + NGramMetric.compare("night", "nacht")(2).get should be (0.25) + NGramMetric.compare("night", "naght")(2).get should be (0.5) + NGramMetric.compare("context", "contact")(2).get should be (0.5) + NGramMetric.compare("contextcontext", "contact")(2).get should be (0.23076923076923078) + NGramMetric.compare("context", "contactcontact")(2).get should be (0.23076923076923078) + NGramMetric.compare("ht", "nacht")(2).get should be (0.25) + NGramMetric.compare("xp", "nacht")(2).get should be (0) + NGramMetric.compare("ht", "hththt")(2).get should be (0.2) + + NGramMetric.compare("night", "nacht")(3).get should be (0) + NGramMetric.compare("night", "naght")(3).get should be (0.3333333333333333) + NGramMetric.compare("context", "contact")(3).get should be (0.4) + } + } + } + } +}
\ No newline at end of file diff --git a/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala new file mode 100755 index 0000000..cefd80f --- /dev/null +++ b/core/source/test/scala/com/rockymadden/stringmetric/similarity/WeightedLevenshteinMetricSpec.scala @@ -0,0 +1,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 WeightedLevenshteinMetricSpec extends ScalaTest { + import WeightedLevenshteinMetricSpec.Options + + "WeightedLevenshteinMetric" should provide { + "compare method" when passed { + "empty arguments" should returns { + "None" in { + WeightedLevenshteinMetric.compare("", "")(Options).isDefined should be (false) + WeightedLevenshteinMetric.compare("abc", "")(Options).isDefined should be (false) + WeightedLevenshteinMetric.compare("", "xyz")(Options).isDefined should be (false) + } + } + "equal arguments" should returns { + "0" in { + WeightedLevenshteinMetric.compare("abc", "abc")(Options).get should be (0) + WeightedLevenshteinMetric.compare("123", "123")(Options).get should be (0) + } + } + "unequal arguments" should returns { + "Double indicating distance" in { + WeightedLevenshteinMetric.compare("abc", "xyz")(Options).get should be (3) + WeightedLevenshteinMetric.compare("123", "456")(Options).get should be (3) + } + } + "valid arguments" should returns { + "Double indicating distance" in { + WeightedLevenshteinMetric.compare("az", "z")(Options).get should be (10) + WeightedLevenshteinMetric.compare("z", "az")(Options).get should be (0.1) + WeightedLevenshteinMetric.compare("a", "z")(Options).get should be (1) + WeightedLevenshteinMetric.compare("z", "a")(Options).get should be (1) + WeightedLevenshteinMetric.compare("ab", "yz")(Options).get should be (2) + WeightedLevenshteinMetric.compare("yz", "ab")(Options).get should be (2) + WeightedLevenshteinMetric.compare("0", "0123456789")(Options).get should be (0.9) + WeightedLevenshteinMetric.compare("0123456789", "0")(Options).get should be (90) + WeightedLevenshteinMetric.compare("book", "back")(Options).get should be (2) + WeightedLevenshteinMetric.compare("back", "book")(Options).get should be (2) + WeightedLevenshteinMetric.compare("hosp", "hospital")(Options).get should be (0.4) + WeightedLevenshteinMetric.compare("hospital", "hosp")(Options).get should be (40) + WeightedLevenshteinMetric.compare("clmbs blvd", "columbus boulevard")(Options).get should be (0.8) + WeightedLevenshteinMetric.compare("columbus boulevard", "clmbs blvd")(Options).get should be (80) + } + } + } + } +} + +object WeightedLevenshteinMetricSpec { + private final val Options = Tuple3[BigDecimal, BigDecimal, BigDecimal](10, 0.1, 1) +}
\ No newline at end of file |