diff options
-rwxr-xr-x | cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala | 4 | ||||
-rwxr-xr-x | cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala b/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala index 94f22c6..f2975d9 100755 --- a/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala +++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala @@ -11,4 +11,8 @@ object ParseUtility { def parseFloat(string: String): Option[Float] = try { Some(string.toFloat) } catch { case _ => None } def parseInt(string: String): Option[Int] = try { Some(string.toInt) } catch { case _ => None } + + def parseLong(string: String): Option[Long] = try { Some(string.toLong) } catch { case _ => None } + + def parseShort(string: String): Option[Short] = try { Some(string.toShort) } catch { case _ => None } }
\ No newline at end of file diff --git a/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala b/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala index 686f3da..f265c54 100755 --- a/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala +++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala @@ -56,5 +56,29 @@ final class ParseUtilitySpec extends ScalaTest { } } } + "parseLong method" when passed { + "invalid argument" should returns { + "None" in { + ParseUtility.parseLong("one").isDefined should be (false) + } + } + "valid argument" should returns { + "Some(Long)" in { + ParseUtility.parseLong("1").get should be (1l) + } + } + } + "parseShort method" when passed { + "invalid argument" should returns { + "None" in { + ParseUtility.parseShort("one").isDefined should be (false) + } + } + "valid argument" should returns { + "Some(Short)" in { + ParseUtility.parseShort("1").get should equal (1: Short) + } + } + } } }
\ No newline at end of file |