summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala4
-rwxr-xr-xcli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala14
2 files changed, 16 insertions, 2 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 f2975d9..092db3e 100755
--- a/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala
+++ b/cli/source/core/scala/org/hashtree/stringmetric/cli/ParseUtility.scala
@@ -1,11 +1,13 @@
package org.hashtree.stringmetric.cli
-import scala.math.BigDecimal
+import scala.math.{ BigDecimal, BigInt }
/** Utility standalone for parse based operations. */
object ParseUtility {
def parseBigDecimal(string: String): Option[BigDecimal] = try { Some(BigDecimal(string)) } catch { case _ => None }
+ def parseBigInt(string: String): Option[BigInt] = try { Some(BigInt(string)) } catch { case _ => None }
+
def parseDouble(string: String): Option[Double] = try { Some(string.toDouble) } catch { case _ => None }
def parseFloat(string: String): Option[Float] = try { Some(string.toFloat) } catch { case _ => None }
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 f265c54..a7b4adc 100755
--- a/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala
+++ b/cli/source/test/scala/org/hashtree/stringmetric/cli/ParseUtilitySpec.scala
@@ -3,7 +3,7 @@ package org.hashtree.stringmetric.cli
import org.hashtree.stringmetric.ScalaTest
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
-import scala.math.BigDecimal
+import scala.math.{ BigDecimal, BigInt }
@RunWith(classOf[JUnitRunner])
final class ParseUtilitySpec extends ScalaTest {
@@ -20,6 +20,18 @@ final class ParseUtilitySpec extends ScalaTest {
}
}
}
+ "parseBigInt method" when passed {
+ "invalid argument" should returns {
+ "None" in {
+ ParseUtility.parseBigInt("one").isDefined should be (false)
+ }
+ }
+ "valid argument" should returns {
+ "Some(BigInt)" in {
+ ParseUtility.parseBigInt("1").get should equal (1: BigInt)
+ }
+ }
+ }
"parseDouble method" when passed {
"invalid argument" should returns {
"None" in {