Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Feb 21, 2024
1 parent 77db4e5 commit cd73f39
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
14 changes: 14 additions & 0 deletions Golds/decodeE4M3_+NaN.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Arguments: -fe4m3 0b_0111_1111
Exit code: ExitSuccess
Satisfiable. Model:
DECODED = NaN :: FloatingPoint 4 4
7 6543 210
S -E4- S3-
Binary layout: 0 1111 111
Hex layout: 7F
Precision: 4 exponent bits, 3 significand bits
Sign: Positive
Exponent: 8 (Stored: 15, Bias: 7)
Classification: FP_NAN (Quiet)
Value: NaN
Note: Representation for NaN's is not unique
14 changes: 14 additions & 0 deletions Golds/decodeE4M3_-NaN.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Arguments: -fe4m3 0b_1111_1111
Exit code: ExitSuccess
Satisfiable. Model:
DECODED = NaN :: FloatingPoint 4 4
7 6543 210
S -E4- S3-
Binary layout: 1 1111 111
Hex layout: FF
Precision: 4 exponent bits, 3 significand bits
Sign: Negative
Exponent: 8 (Stored: 15, Bias: 7)
Classification: FP_NAN (Quiet)
Value: NaN
Note: Representation for NaN's is not unique
43 changes: 24 additions & 19 deletions src/CrackNum/TestSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import System.Process (readProcessWithExitCode)

import Data.List (intercalate)

gold :: TestName -> [String] -> TestTree
gold n args = goldenVsFileDiff n diff gf gfTmp (rm gfTmp >> run)
gold :: TestName -> String -> TestTree
gold n as = goldenVsFileDiff n diff gf gfTmp (rm gfTmp >> run)
where gf = "Golds" </> n <.> "gold"
gfTmp = gf ++ "_temp"

rm f = removeFile f `C.catch` (\(_ :: C.SomeException) -> return ())

as = unwords args
args = words as

run = do (ec, so, se) <- readProcessWithExitCode "crackNum" args ""
writeFile gfTmp $ intercalate "\n" $ [ "Arguments: " ++ as
, "Exit code: " ++ show ec
Expand All @@ -50,25 +51,25 @@ runTests = defaultMain tests
tests :: TestTree
tests = testGroup "CrackNum" [
testGroup "Encode" [
gold "encode0" ["-i4", "--", "-2"]
, gold "encode1" ["-w4", "2"]
, gold "encode2" ["-f3+4", "2.5"]
, gold "encode3" ["-f3+4", "2.5", "-rRTZ"]
, gold "encode4" ["-fbp", "2.5"]
, gold "encode5" ["-fdp", "2.5"]
gold "encode0" "-i4 -- -2"
, gold "encode1" "-w4 2"
, gold "encode2" "-f3+4 2.5"
, gold "encode3" "-f3+4 2.5 -rRTZ"
, gold "encode4" "-fbp 2.5"
, gold "encode5" "-fdp 2.5"
]
, testGroup "Decode" [
gold "decode0" ["-i4", "0b0110"]
, gold "decode1" ["-w4", "0xE"]
, gold "decode2" ["-f3+4", "0b0111001"]
, gold "decode3" ["-fbp", "0x000F"]
, gold "decode4" ["-fdp", "0x8000000000000000"]
, gold "decode5" ["-fhp", "0x7c01"]
, gold "decode6" ["-fhp", "-l8", "128'hffffffffffffffffbdffaaffdc71fc60"]
gold "decode0" "-i4 0b0110"
, gold "decode1" "-w4 0xE"
, gold "decode2" "-f3+4 0b0111001"
, gold "decode3" "-fbp 0x000F"
, gold "decode4" "-fdp 0x8000000000000000"
, gold "decode5" "-fhp 0x7c01"
, gold "decode6" "-fhp -l8 128'hffffffffffffffffbdffaaffdc71fc60"
]
, testGroup "DecodeE4M3" [
gold ("decodeE4M3_" ++ show (if sign then (-val :: Int) else val))
["-fe4m3", "0b" ++ (if sign then "1" else "0") ++ "1111" ++ frac]
$ "-fe4m3 0b" ++ (if sign then "1" else "0") ++ "1111" ++ frac
| (val, frac) <- [ (256, "000")
, (288, "001")
, (320, "010")
Expand All @@ -79,8 +80,12 @@ tests = testGroup "CrackNum" [
]
, sign <- [False, True]
]
, testGroup "DecodeE4M3_NaN" [
gold "decodeE4M3_+NaN" "-fe4m3 0b_0111_1111"
, gold "decodeE4M3_-NaN" "-fe4m3 0b_1111_1111"
]
, testGroup "Bad" [
gold "badInvocation0" ["-f3+4", "0b01"]
, gold "badInvocation1" ["-f3+4", "0xFFFF"]
gold "badInvocation0" "-f3+4 0b01"
, gold "badInvocation1" "-f3+4 0xFFFF"
]
]

0 comments on commit cd73f39

Please sign in to comment.