-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
octal_test.hs
42 lines (32 loc) · 1.2 KB
/
octal_test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Test.QuickCheck
import Test.QuickCheck.Test (isSuccess)
import System.Exit (ExitCode(..), exitWith)
import Octal (showOct, readOct)
import qualified Numeric as N
{-
For the appropriate amount of challenge here, you should only
use functionality present in Prelude. Try not to use
Data.List, Data.Char, Data.Bits, or Numeric.
Try and use seq, $!, or BangPatterns appropriately to ensure
that the solution is efficient.
Handling invalid input is not necessary.
-}
exitProperly :: IO Bool -> IO ()
exitProperly m = do
didSucceed <- m
exitWith $ if didSucceed then ExitSuccess else ExitFailure 1
prop_showOct_integral :: (Integral a, Show a) => (Positive a) -> Bool
prop_showOct_integral (Positive n) = N.showOct n "" == showOct n
prop_showOct_int :: (Positive Int) -> Bool
prop_showOct_int = prop_showOct_integral
prop_readOct_integral :: (Integral a, Show a) => (Positive a) -> Bool
prop_readOct_integral (Positive n) = n == readOct (N.showOct n "")
prop_readOct_int :: (Positive Int) -> Bool
prop_readOct_int = prop_readOct_integral
main :: IO ()
main = exitProperly $ all isSuccess `fmap` mapM quickCheckResult
[ prop_showOct_integral
, prop_showOct_int
, prop_readOct_integral
, prop_readOct_int
]