Add function for zero-padded decimal encoding of two digit numers

This commit is contained in:
Andrew Martin 2019-12-30 20:14:15 -05:00 committed by GitHub
parent 10ed08c77d
commit 2b85e2cb84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View file

@ -64,6 +64,10 @@ tests = testGroup "Tests"
runConcat 1 (word64PaddedUpperHex w)
===
pack (showWord64PaddedUpperHex w)
, TQC.testProperty "wordPaddedTwoDigitDec" $ TQC.forAll (TQC.choose (0,99)) $ \w ->
Bounded.run Nat.two (Bounded.wordPaddedTwoDigitDec w)
===
pack (zeroPadL 2 (show w))
, TQC.testProperty "word8Dec" $ \w ->
runConcat 1 (word8Dec w)
===
@ -278,3 +282,8 @@ c2w = fromIntegral . ord
instance Arbitrary Word128 where
arbitrary = liftA2 Word128 TQC.arbitrary TQC.arbitrary
zeroPadL :: Int -> String -> String
zeroPadL n s
| length s < n = replicate (n - length s) '0' ++ s
| otherwise = s