Skip to content

Commit

Permalink
Added test for Show type class (show function).
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthewar committed Sep 12, 2018
1 parent f2d9c0a commit 567baf1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion test/Spec/Parser/Types/Token.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ validUpperStrings = QC.testProperty "Valid upper case strings" $
abstractLiteralTests :: TestTree
abstractLiteralTests = testGroup "Abstract literal class tests"
[ abstractLiteralEqTests
--, abstractLiteralShowTests
, abstractLiteralShowTests
]

-- |Tests for the derived 'Eq' type class for 'AbstractLiteral' type
Expand All @@ -83,6 +83,20 @@ abstractLiteralEqTests = testGroup "Eq type class tests"
real <- QC.arbitrary
QC.elements [(UniversalInteger int,UniversalReal real),(UniversalReal real,UniversalInteger int)]

-- |Tests for the derived 'Show' type class for 'AbstractLiteral' type
abstractLiteralShowTests :: TestTree
abstractLiteralShowTests = QC.testProperty "Show type class test" $
QC.forAll genShowLiteral $ \(ExpectedOutput input expectedOutput) -> show input == expectedOutput
where genShowLiteral = convertShow <$> genLiteral
genLiteral = QC.oneof [ UniversalInteger <$> QC.arbitrary
, UniversalReal <$> QC.arbitrary
]
convertShow lit@(UniversalInteger val) = ExpectedOutput lit $ "UniversalInteger " ++ showValue val
convertShow lit@(UniversalReal val) = ExpectedOutput lit $ "UniversalReal " ++ showValue val
showValue val
| val < 0 = "(" ++ show val ++ ")"
| otherwise = show val

-- |Tests for constructor function of 'BitString'
-- Uses constructor function 'mkBitString'
bitStringTests :: TestTree
Expand Down

0 comments on commit 567baf1

Please sign in to comment.