File: Main.hs

package info (click to toggle)
haskell-nonempty-vector 0.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 156 kB
  • sloc: haskell: 1,391; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
-- |
-- Module       : Main (tests)
-- Copyright 	: 2019-2023 (c) Emily Pillmore
-- License	: BSD
--
-- Maintainer	: Emily Pillmore <emilypi@cohomolo.gy>
-- Stability	: Experimental
-- Portability	: TypeFamilies
--
module Main
( main
) where


import Data.Maybe
import Data.Vector (Vector)
import Data.Vector.NonEmpty (NonEmptyVector)
import qualified Data.Vector.NonEmpty as NEV

import Test.QuickCheck
import Test.Tasty
import Test.Tasty.QuickCheck

main :: IO ()
main = defaultMain $ testGroup "NonEmptyVector constructor"
    [ testProperty "prop_reverse" prop_reverse
    , testProperty "prop_from_to_list" prop_from_to_list
    , testProperty "prop_from_to_vec" prop_from_to_vec
    ]

genList :: Gen [Int]
genList = listOf1 (choose (1, 100))

genNEV :: Gen (NonEmptyVector Int)
genNEV = fmap (fromJust . NEV.fromList) genList

genV :: Gen (Vector Int)
genV = NEV.toVector <$> genNEV

prop_reverse :: Property
prop_reverse =  forAll genNEV $ \t ->
  NEV.reverse (NEV.reverse t) == t

prop_from_to_list :: Property
prop_from_to_list =
  forAll genNEV $ \t ->
  forAll genList $ \u ->
    NEV.fromList (NEV.toList t) == Just t
      && fmap NEV.toList (NEV.fromList u) == Just u

prop_from_to_vec :: Property
prop_from_to_vec =
  forAll genNEV $ \t ->
  forAll genV $ \u ->
    NEV.fromVector (NEV.toVector t) == Just t
      && (NEV.toVector <$> NEV.fromVector u) == Just u