Sha256: 856d992252d2c797dd7e796b00d77522fefc2243f0a73a8c680aec66c58b2b8b

Contents?: true

Size: 1003 Bytes

Versions: 229

Compression:

Stored size: 1003 Bytes

Contents

import Data.Char         (intToDigit)
import Test.Hspec        (Spec, it)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)
import Test.QuickCheck   (Positive(Positive), (==>), property)

import qualified Numeric as Num (showIntAtBase)

import Trinary (readTri, showTri)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = do

    let refShowTri n = Num.showIntAtBase 3 intToDigit n ""

    it "can show Int trinary" $
      property $ \(Positive n) -> refShowTri n == showTri (n :: Int)

    it "can show Integer trinary" $
      property $ \(Positive n) -> refShowTri n == showTri (n :: Integer)

    it "can read Int trinary" $
      property $ \(Positive n) -> n == readTri (refShowTri (n :: Int))

    it "can read Integer trinary" $
      property $ \(Positive n) -> n == readTri (refShowTri (n :: Integer))

    it "can read invalid trinary" $
      \n -> any (`notElem` ['0'..'2']) (show n) ==> (readTri . show $ n) == (0 :: Int)

Version data entries

229 entries across 229 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.179 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.178 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.177 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.176 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.175 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.174 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.173 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.172 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.171 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.170 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.169 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.167 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.166 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.165 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.164 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.163 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.162 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.161 tracks/haskell/exercises/trinary/test/Tests.hs
trackler-2.2.1.160 tracks/haskell/exercises/trinary/test/Tests.hs