check whether data is OK

This commit is contained in:
Filip Gralinski 2015-11-06 23:14:10 +01:00 committed by Filip Gralinski
parent 7f3973890d
commit b52819f67e
6 changed files with 18 additions and 0 deletions

View File

@ -82,6 +82,7 @@ data GEvalException = NoExpectedFile FilePath
| TooFewLines
| TooManyLines
| EmptyOutput
| UnexpectedData String
deriving (Eq)
instance Exception GEvalException
@ -97,6 +98,7 @@ instance Show GEvalException where
show TooFewLines = "Too few lines in the output file"
show TooManyLines = "Too many lines in the output file"
show EmptyOutput = "The output file is empty"
show (UnexpectedData message) = "Unexpected data [" ++ message ++ "]"
somethingWrongWithFilesMessage :: String -> FilePath -> String
somethingWrongWithFilesMessage msg filePath = Prelude.concat
@ -200,3 +202,4 @@ itemError (exp, out) = (exp-out)**2
getValue :: Either String (Double, Text) -> Double
getValue (Right (x, _)) = x
getValue (Left s) = throw $ UnexpectedData s

View File

@ -40,6 +40,8 @@ main = hspec $ do
runGEvalTest "error-too-many-lines" `shouldThrow` (== TooManyLines)
it "empty output is handled" $ do
runGEvalTest "empty-output" `shouldThrow` (== EmptyOutput)
it "unexpected data is handled" $
runGEvalTest "unexpected-data" `shouldThrow` (== UnexpectedData "input does not start with a digit")
extractVal :: (Either (ParserResult GEvalOptions) (Maybe MetricValue)) -> IO MetricValue
extractVal (Right (Just val)) = return val

View File

@ -0,0 +1,4 @@
2.0
1.1
xyz
2.1
1 2.0
2 1.1
3 xyz
4 2.1

View File

@ -0,0 +1 @@
--metric MSE

View File

@ -0,0 +1,4 @@
2.0
-3.0
1.0
2.5
1 2.0
2 -3.0
3 1.0
4 2.5

View File

@ -0,0 +1,4 @@
bla 2
bar 3
bla 3
bar 3
1 bla 2
2 bar 3
3 bla 3
4 bar 3