diff options
author | Rocky Madden <git@rockymadden.com> | 2012-11-05 18:49:06 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2012-11-05 18:49:06 -0700 |
commit | 8d1e80ff34836308a0b0331b012d961d4f08db28 (patch) | |
tree | 62df305501d531c7febe498754006ce5e47afcb7 /cli/source | |
parent | 75927d93d43e48ae75e848b2a8cb15414f658836 (diff) | |
download | stringmetric-8d1e80ff34836308a0b0331b012d961d4f08db28.tar.gz stringmetric-8d1e80ff34836308a0b0331b012d961d4f08db28.tar.bz2 stringmetric-8d1e80ff34836308a0b0331b012d961d4f08db28.zip |
Added overloaded methods for long and short.
Diffstat (limited to 'cli/source')
-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 |