File: List.hs

package info (click to toggle)
haskell-parameterized-utils 2.1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 564 kB
  • sloc: haskell: 7,887; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 814 bytes parent folder | download | duplicates (3)
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
module Test.List
  ( tests
  ) where

import           Control.Monad.Identity
import           Data.Functor.Const
import qualified Data.Parameterized.List as PL
import           Data.Parameterized.Some
import           Test.Tasty
import           Test.Tasty.HUnit

-- | Test ifoldlM indexing is correct by summing a list using it.
testIfoldlMSum :: [Integer] -> TestTree
testIfoldlMSum l =
  testCase ("ifoldlMSum " ++ show l) $
    case PL.fromListWith (Some . Const) l of
      Some pl ->
        let expected = sum l
            actual = PL.ifoldlM (\r i v -> Identity $ r + if pl PL.!! i == v then getConst v else 0) 0 pl
        in expected @?= runIdentity actual


tests :: TestTree
tests = testGroup "List"
  [ testIfoldlMSum []
  , testIfoldlMSum [1]
  , testIfoldlMSum [1,2]
  , testIfoldlMSum [1,2,3]
  ]