handle numbers combined with text

This commit is contained in:
Filip Gralinski 2015-11-06 23:24:46 +01:00 committed by Filip Gralinski
parent b52819f67e
commit e66a8d8341
6 changed files with 20 additions and 1 deletions

View File

@ -201,5 +201,8 @@ itemError :: (Double, Double) -> Double
itemError (exp, out) = (exp-out)**2 itemError (exp, out) = (exp-out)**2
getValue :: Either String (Double, Text) -> Double getValue :: Either String (Double, Text) -> Double
getValue (Right (x, _)) = x getValue (Right (x, reminder)) =
if Data.Text.null reminder || Data.Text.head reminder == '\t'
then x
else throw $ UnexpectedData "number expected"
getValue (Left s) = throw $ UnexpectedData s getValue (Left s) = throw $ UnexpectedData s

View File

@ -42,6 +42,9 @@ main = hspec $ do
runGEvalTest "empty-output" `shouldThrow` (== EmptyOutput) runGEvalTest "empty-output" `shouldThrow` (== EmptyOutput)
it "unexpected data is handled" $ it "unexpected data is handled" $
runGEvalTest "unexpected-data" `shouldThrow` (== UnexpectedData "input does not start with a digit") runGEvalTest "unexpected-data" `shouldThrow` (== UnexpectedData "input does not start with a digit")
it "unwanted data is handled" $
runGEvalTest "unwanted-data" `shouldThrow` (== UnexpectedData "number expected")
extractVal :: (Either (ParserResult GEvalOptions) (Maybe MetricValue)) -> IO MetricValue extractVal :: (Either (ParserResult GEvalOptions) (Maybe MetricValue)) -> IO MetricValue
extractVal (Right (Just val)) = return val extractVal (Right (Just val)) = return val

View File

@ -0,0 +1,4 @@
1 X
2xyz Y
3.3 Z
4.0 Z
1 1 X
2 2xyz Y
3 3.3 Z
4 4.0 Z

View File

@ -0,0 +1 @@
--metric RMSE

View File

@ -0,0 +1,4 @@
1.2
2.3
1.0
5.0
1 1.2
2 2.3
3 1.0
4 5.0

View File

@ -0,0 +1,4 @@
1 a
2 b
1 a
2 a
1 1 a
2 2 b
3 1 a
4 2 a