From 988b8a75befb6bc14c0f26f7ec92d34b86def969 Mon Sep 17 00:00:00 2001 From: Rocky Madden Date: Mon, 3 Dec 2012 09:55:19 -0700 Subject: Added OptionMapArray and OptionMapList case classes. --- .../hashtree/stringmetric/cli/OptionMapType.scala | 22 +++++++++ .../cli/phonetic/metaphoneAlgorithm.scala | 2 +- .../cli/phonetic/metaphoneMetric.scala | 4 +- .../cli/phonetic/nysiisAlgorithm.scala | 2 +- .../stringmetric/cli/phonetic/nysiisMetric.scala | 4 +- .../cli/phonetic/refinedNysiisAlgorithm.scala | 2 +- .../cli/phonetic/refinedNysiisMetric.scala | 4 +- .../cli/phonetic/refinedSoundexAlgorithm.scala | 2 +- .../cli/phonetic/refinedSoundexMetric.scala | 4 +- .../cli/phonetic/soundexAlgorithm.scala | 2 +- .../stringmetric/cli/phonetic/soundexMetric.scala | 4 +- .../cli/similarity/diceSorensenMetric.scala | 4 +- .../cli/similarity/hammingMetric.scala | 4 +- .../stringmetric/cli/similarity/jaroMetric.scala | 4 +- .../cli/similarity/jaroWinklerMetric.scala | 4 +- .../cli/similarity/levenshteinMetric.scala | 4 +- .../cli/similarity/nGramAlgorithm.scala | 2 +- .../stringmetric/cli/similarity/nGramMetric.scala | 4 +- .../cli/similarity/weightedLevenshteinMetric.scala | 4 +- .../stringmetric/cli/OptionMapTypeSpec.scala | 56 ++++++++++++++++++++++ 20 files changed, 108 insertions(+), 30 deletions(-) (limited to 'cli/source') diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala index 43f1210..c4f76a5 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/OptionMapType.scala @@ -4,6 +4,15 @@ sealed abstract class OptionMapType[T](protected[this] val stringSelf: String) { def get(): Option[T] } +final case class OptionMapArray(arrayString: String) extends OptionMapType[Array[String]](arrayString) { + private[this] lazy val self = try { + if (stringSelf.length == 0) None + else Some(stringSelf.split(" ")) + } catch { case _ => None } + + override def get() = self +} + final case class OptionMapBigDecimal(bigDecimalString: String) extends OptionMapType[BigDecimal](bigDecimalString) { private[this] lazy val self = try { Some(BigDecimal(stringSelf)) } catch { case _ => None } @@ -34,6 +43,15 @@ final case class OptionMapInt(intString: String) extends OptionMapType[Int](intS override def get() = self } +final case class OptionMapList(listString: String) extends OptionMapType[List[String]](listString) { + private[this] lazy val self = try { + if (stringSelf.length == 0) None + else Some(stringSelf.split(" ").toList) + } catch { case _ => None } + + override def get() = self +} + final case class OptionMapLong(longString: String) extends OptionMapType[Long](longString) { private[this] lazy val self = try { Some(stringSelf.toLong) } catch { case _ => None } @@ -53,6 +71,8 @@ object OptionMapType { implicit def OptionMapTypeToT[T](optionMapType: OptionMapType[T]): T = optionMapType.get.get + implicit def StringToOptionMapArray(string: String): OptionMapArray = new OptionMapArray(string) + implicit def StringToOptionMapBigDecimal(string: String): OptionMapBigDecimal = new OptionMapBigDecimal(string) implicit def StringToOptionMapBigInt(string: String): OptionMapBigInt = new OptionMapBigInt(string) @@ -63,6 +83,8 @@ object OptionMapType { implicit def StringToOptionMapInt(string: String): OptionMapInt = new OptionMapInt(string) + implicit def StringToOptionMapList(string: String): OptionMapList = new OptionMapList(string) + implicit def StringToOptionMapLong(string: String): OptionMapLong = new OptionMapLong(string) implicit def StringToOptionMapShort(string: String): OptionMapShort = new OptionMapShort(string) diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneAlgorithm.scala index aa8fa25..6dd2647 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneAlgorithm.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneAlgorithm.scala @@ -17,7 +17,7 @@ object metaphoneAlgorithm extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 1) { execute(options) exit(options) // Invalid syntax. diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneMetric.scala index c4d31c3..581de0e 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/metaphoneMetric.scala @@ -17,7 +17,7 @@ object metaphoneMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object metaphoneMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( MetaphoneMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisAlgorithm.scala index 940a3c5..6d96299 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisAlgorithm.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisAlgorithm.scala @@ -17,7 +17,7 @@ object nysiisAlgorithm extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 1) { execute(options) exit(options) // Invalid syntax. diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisMetric.scala index ea0180c..5ad2fd7 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/nysiisMetric.scala @@ -17,7 +17,7 @@ object nysiisMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object nysiisMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( NysiisMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala index 947fe14..8619e16 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisAlgorithm.scala @@ -17,7 +17,7 @@ object refinedNysiisAlgorithm extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 1) { execute(options) exit(options) // Invalid syntax. diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala index 01dfeaf..e09208e 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedNysiisMetric.scala @@ -17,7 +17,7 @@ object refinedNysiisMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object refinedNysiisMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( RefinedNysiisMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexAlgorithm.scala index b088158..c28a071 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexAlgorithm.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexAlgorithm.scala @@ -17,7 +17,7 @@ object refinedSoundexAlgorithm extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 1) { execute(options) exit(options) // Invalid syntax. diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexMetric.scala index 35344cf..483a0b8 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/refinedSoundexMetric.scala @@ -17,7 +17,7 @@ object refinedSoundexMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object refinedSoundexMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( RefinedSoundexMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexAlgorithm.scala index d970b6c..02ef536 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexAlgorithm.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexAlgorithm.scala @@ -17,7 +17,7 @@ object soundexAlgorithm extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 1) { execute(options) exit(options) // Invalid syntax. diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexMetric.scala index 4ccc8be..7f09197 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/phonetic/soundexMetric.scala @@ -17,7 +17,7 @@ object soundexMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object soundexMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( SoundexMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala index 2c88022..57e4f72 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/diceSorensenMetric.scala @@ -17,7 +17,7 @@ object diceSorensenMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1 + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2 && options.contains('n) && OptionMapInt(options('n)).isDefined ) { execute(options) @@ -46,7 +46,7 @@ object diceSorensenMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) val n = OptionMapInt(options('n)) println( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/hammingMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/hammingMetric.scala index 6cf7b33..6830d56 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/hammingMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/hammingMetric.scala @@ -17,7 +17,7 @@ object hammingMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object hammingMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( HammingMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroMetric.scala index 9d54257..b00ddb6 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroMetric.scala @@ -14,7 +14,7 @@ object jaroMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -39,7 +39,7 @@ object jaroMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( JaroMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroWinklerMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroWinklerMetric.scala index 1822e39..0b2896c 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroWinklerMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/jaroWinklerMetric.scala @@ -17,7 +17,7 @@ object jaroWinklerMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -42,7 +42,7 @@ object jaroWinklerMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( JaroWinklerMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/levenshteinMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/levenshteinMetric.scala index 0aecf0f..a535af8 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/levenshteinMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/levenshteinMetric.scala @@ -17,7 +17,7 @@ object levenshteinMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1) { + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2) { execute(options) exit(options) // Invalid syntax. @@ -43,7 +43,7 @@ object levenshteinMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) println( LevenshteinMetric.compare( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramAlgorithm.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramAlgorithm.scala index 8dffafe..f696823 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramAlgorithm.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramAlgorithm.scala @@ -16,7 +16,7 @@ object nGramAlgorithm extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 0 + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 1 && options.contains('n) && OptionMapInt(options('n)).isDefined ) { execute(options) diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramMetric.scala index d28a432..a08a148 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/nGramMetric.scala @@ -17,7 +17,7 @@ object nGramMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1 + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2 && options.contains('n) && OptionMapInt(options('n)).isDefined ) { execute(options) @@ -46,7 +46,7 @@ object nGramMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) val n = OptionMapInt(options('n)) println( diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/weightedLevenshteinMetric.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/weightedLevenshteinMetric.scala index d785c98..0265a72 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/weightedLevenshteinMetric.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/similarity/weightedLevenshteinMetric.scala @@ -19,7 +19,7 @@ object weightedLevenshteinMetric extends Command { help() exit(options) // Execute. - } else if (options.contains('dashless) && options('dashless).count(_ == ' ') == 1 + } else if (options.contains('dashless) && (OptionMapArray(options('dashless)): Array[String]).length == 2 && options.contains('deleteWeight) && OptionMapDouble(options('deleteWeight)).isDefined && options.contains('insertWeight) && OptionMapDouble(options('insertWeight)).isDefined && options.contains('substituteWeight) && OptionMapDouble(options('substituteWeight)).isDefined @@ -55,7 +55,7 @@ object weightedLevenshteinMetric extends Command { } override def execute(options: OptionMap): Unit = { - val strings = options('dashless).split(" ") + val strings = OptionMapArray(options('dashless)) val weights = Tuple3[BigDecimal, BigDecimal, BigDecimal]( OptionMapBigDecimal(options('deleteWeight)), OptionMapBigDecimal(options('insertWeight)), diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala index 143d64b..b8c0561 100755 --- a/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/OptionMapTypeSpec.scala @@ -6,10 +6,32 @@ import org.scalatest.junit.JUnitRunner @RunWith(classOf[JUnitRunner]) final class OptionMapTypeSpec extends ScalaTest { + "OptionMapArray" should provide { + "get method" when passed { + "invalid argument" should returns { + "None" in { + OptionMapArray("").get.isDefined should be (false) + + (OptionMapArray(""): Option[Array[String]]).isDefined should be (false) + } + } + "valid argument" should returns { + "Array" in { + OptionMapArray("1").get.get should equal (Array("1")) + + OptionMapArray("1 2 3").get.get should equal (Array("1", "2", "3")) + + (OptionMapArray("1 2 3"): Array[String]) should equal (Array("1", "2", "3")) + } + } + } + } "OptionMapBigDecimal" should provide { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapBigDecimal("").get.isDefined should be (false) + OptionMapBigDecimal("one").get.isDefined should be (false) (OptionMapBigDecimal("one"): Option[BigDecimal]).isDefined should be (false) @@ -30,6 +52,8 @@ final class OptionMapTypeSpec extends ScalaTest { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapBigInt("").get.isDefined should be (false) + OptionMapBigInt("one").get.isDefined should be (false) (OptionMapBigInt("one"): Option[BigInt]).isDefined should be (false) @@ -50,6 +74,8 @@ final class OptionMapTypeSpec extends ScalaTest { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapDouble("").get.isDefined should be (false) + OptionMapDouble("one").get.isDefined should be (false) (OptionMapDouble("one"): Option[Double]).isDefined should be (false) @@ -70,6 +96,8 @@ final class OptionMapTypeSpec extends ScalaTest { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapFloat("").get.isDefined should be (false) + OptionMapFloat("one").get.isDefined should be (false) (OptionMapFloat("one"): Option[Float]).isDefined should be (false) @@ -90,6 +118,8 @@ final class OptionMapTypeSpec extends ScalaTest { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapInt("").get.isDefined should be (false) + OptionMapInt("one").get.isDefined should be (false) (OptionMapInt("one"): Option[Int]).isDefined should be (false) @@ -106,10 +136,34 @@ final class OptionMapTypeSpec extends ScalaTest { } } } + "OptionMapList" should provide { + "get method" when passed { + "invalid argument" should returns { + "None" in { + OptionMapList("").get.isDefined should be (false) + + (OptionMapList(""): Option[List[String]]).isDefined should be (false) + } + } + "valid argument" should returns { + "List" in { + OptionMapList("1").get.get should equal (List("1")) + + OptionMapList("1 2 3").get.get should equal (List("1", "2", "3")) + + (OptionMapList("1 2 3"): List[String]) should equal (List("1", "2", "3")) + + (OptionMapList("1 2 3"): String) should equal ("List(1, 2, 3)") + } + } + } + } "OptionMapLong" should provide { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapLong("").get.isDefined should be (false) + OptionMapLong("one").get.isDefined should be (false) (OptionMapLong("one"): Option[Long]).isDefined should be (false) @@ -130,6 +184,8 @@ final class OptionMapTypeSpec extends ScalaTest { "get method" when passed { "invalid argument" should returns { "None" in { + OptionMapShort("").get.isDefined should be (false) + OptionMapShort("one").get.isDefined should be (false) (OptionMapShort("one"): Option[Short]).isDefined should be (false) -- cgit v1.2.3