-------------------------------------------------------------------------
--
--         Test.hs
--
--  The test module of the Huffman example
--
--  (c) Addison-Wesley, 1996-2011.
--
-------------------------------------------------------------------------

module Test where

-- The test module of the Huffman example

import Main
import Test.QuickCheck
import Data.List ( nub )


-- QuickCheck testing

checkInverse :: String -> Bool

checkInverse :: String -> Bool
checkInverse String
string = 
    Tree -> HCode -> String
decodeMessage Tree
tree (Table -> String -> HCode
codeMessage Table
table String
string) String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
string
        where
          tree :: Tree
tree = String -> Tree
codes String
string
          table :: Table
table = Tree -> Table
codeTable Tree
tree

-- prop_Hufmann :: String -> Bool

prop_Hufmann :: String -> Property
prop_Hufmann String
string =
    (String -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (String -> String
forall a. Eq a => [a] -> [a]
nub String
string) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> String -> Bool
checkInverse String
string