module Test.Week8 (week8) where

import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.Golden
import qualified Data.ByteString.Lazy.Char8 as B

import Employee
import Week8

week8 :: TestTree
week8 = testGroup "Week 8 - IO" [
    exercise1
  , exercise2
  , exercise5
  ]

emptyGuest = GL [] 0
emp1 = Emp {
    empName = "John"
  , empFun = 10
  }
emp2 = Emp {
    empName = "Ed"
  , empFun = 1
  }
gl1 = glCons emp1 emptyGuest
gl2 = glCons emp2 emptyGuest

exercise1 = testGroup "Exercise 1" [
    testCase "Example 1 - glCons" $ glCons emp1 emptyGuest @?=
      GL [emp1] 10
  , testCase "Example 2 - monoid" $ mempty `mappend` glCons emp1 emptyGuest @?=
      glCons emp1 emptyGuest
  , testCase "Example 3 - moreFun" $ moreFun gl1 gl2 @?= gl1
  ]

exercise2 = testGroup "Exercise 2, 3, 4" [
    testCase "Example 1" $ fun (maxFun testCompany2) @?= 17
  ]

exercise5 = testGroup "Exercise 5" [
    testCaseSteps "Example 1" $ \step -> do
      company <- readFile "src/company.txt"
      fun (maxFun (read company)) @?= 316
  , goldenVsString "Example 2" "test/golden/week8-e5.txt" $
    fmap B.pack $ process
  ]


