{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-}
module Main where

import qualified Data.Map.Strict as Map
import Huffman
import Test.HUnit
import Auxiliaries (Bit (..))

type CodingTable = Map.Map Char [Bit]

test_isConsistent :: IO ()
test_isConsistent = do
  assertEqual "test1_Valid_tree" True (isConsistent exercise1TreeValid)
  assertEqual "test2_Invalid_tree" False (isConsistent exercise1TreeInvalid)

test_toCodingTable :: IO ()
test_toCodingTable = do
  assertEqual "test1_ValidTree" treeValidCodingTable (toCodingTable exercise1TreeValid)
  assertEqual "test2_OneLeaf" treeOnlyLeafCodingTable (toCodingTable (Root (Leaf 'A' 2)))

test_encode :: IO ()
test_encode = do
  assertEqual "test encode Ente" enteEncoded (encode codingTableForTesting "Ente")
  assertEqual "test encode Eren" erenEncoded (encode codingTableForTesting "Eren")
  assertEqual "test encode Start" startEncoded (encode codingTableForTesting "Start")
  assertEqual "test encode Rain" rainEncoded (encode codingTableForTesting "Rain")

test_decode :: IO ()
test_decode = do
  assertEqual "test decode Ente" "ENTE" (decode exercise1TreeValid (encode codingTableForTesting "ENTE"))
  assertEqual "test decode Eren" "EREN" (decode exercise1TreeValid (encode codingTableForTesting "EREN"))
  assertEqual "test decode Start" "START" (decode exercise1TreeValid (encode codingTableForTesting "START"))
  assertEqual "test decode Rain" "RAIN" (decode exercise1TreeValid (encode codingTableForTesting "RAIN"))

test_buildHTree :: IO ()
test_buildHTree = do
  assertEqual "test buildHTree" nodeList (buildHTree "nIiaAaRrRr")

test_toDecodeTree :: IO ()
test_toDecodeTree = pure ()

test_toFromWord8 :: IO ()
test_toFromWord8 = pure ()

test_encodeDecodeFile :: IO ()
test_encodeDecodeFile = pure ()

allTests :: Test
allTests =
  TestList
    [ mkTest "toCodingTable" test_toCodingTable
    , mkTest "encode" test_encode
    , mkTest "isConsistent" test_isConsistent
    , mkTest "decode" test_decode
    , mkTest "buildHTree" test_buildHTree
    , mkTest "toDecodeTree" test_toDecodeTree
    , mkTest "toFromWord8" test_toFromWord8
    , mkTest "encodeDecodeFile" test_encodeDecodeFile
    ]
  where
    mkTest label ass = TestLabel label (TestCase ass)

main :: IO ()
main = runTestTTAndExit allTests
