1
+ {-# LANGUAGE ConstraintKinds #-}
1
2
module Tests.Vector (tests ) where
2
3
3
4
import Boilerplater
@@ -28,18 +29,13 @@ import System.Random (Random)
28
29
import Data.Functor.Identity
29
30
import Control.Monad.Trans.Writer
30
31
31
- #if MIN_VERSION_base(4,4,0)
32
32
import Control.Monad.Zip
33
- #endif
34
-
35
- #define COMMON_CONTEXT(a, v) \
36
- VANILLA_CONTEXT (a, v), VECTOR_CONTEXT (a, v)
37
-
38
- #define VANILLA_CONTEXT(a, v) \
39
- Eq a, Show a, Arbitrary a, CoArbitrary a, TestData a, Model a ~ a, EqTest a ~ Property
40
33
41
- #define VECTOR_CONTEXT(a, v) \
42
- Eq (v a), Show (v a), Arbitrary (v a), CoArbitrary (v a), TestData (v a), Model (v a) ~ [a], EqTest (v a) ~ Property , V. Vector v a
34
+ type CommonContext a v = (VanillaContext a , VectorContext a v )
35
+ type VanillaContext a = ( Eq a , Show a , Arbitrary a , CoArbitrary a
36
+ , TestData a , Model a ~ a , EqTest a ~ Property )
37
+ type VectorContext a v = ( Eq (v a ), Show (v a ), Arbitrary (v a ), CoArbitrary (v a )
38
+ , TestData (v a ), Model (v a ) ~ [a ], EqTest (v a ) ~ Property , V. Vector v a )
43
39
44
40
-- TODO: implement Vector equivalents of list functions for some of the commented out properties
45
41
@@ -82,7 +78,7 @@ instance T.Traversable ((,) a) where
82
78
traverse f (a, b) = fmap ((,) a) $ f b
83
79
#endif
84
80
85
- testSanity :: forall a v . (COMMON_CONTEXT ( a , v ) ) => v a -> [Test ]
81
+ testSanity :: forall a v . (CommonContext a v ) => v a -> [Test ]
86
82
testSanity _ = [
87
83
testProperty " fromList.toList == id" prop_fromList_toList,
88
84
testProperty " toList.fromList == id" prop_toList_fromList,
@@ -95,7 +91,7 @@ testSanity _ = [
95
91
prop_unstream_stream (v :: v a ) = (V. unstream . V. stream) v == v
96
92
prop_stream_unstream (s :: S. Bundle v a ) = ((V. stream :: v a -> S. Bundle v a ) . V. unstream) s == s
97
93
98
- testPolymorphicFunctions :: forall a v . (COMMON_CONTEXT ( a , v ), VECTOR_CONTEXT ( Int , v ) ) => v a -> [Test ]
94
+ testPolymorphicFunctions :: forall a v . (CommonContext a v , VectorContext Int v ) => v a -> [Test ]
99
95
testPolymorphicFunctions _ = $ (testProperties [
100
96
'prop_eq,
101
97
@@ -471,26 +467,22 @@ testPolymorphicFunctions _ = $(testProperties [
471
467
constructrN xs 0 _ = xs
472
468
constructrN xs n f = constructrN (f xs : xs) (n- 1 ) f
473
469
474
- testTuplyFunctions :: forall a v . (COMMON_CONTEXT ( a , v ), VECTOR_CONTEXT (( a , a ), v ), VECTOR_CONTEXT (( a , a , a ), v ) ) => v a -> [Test ]
470
+ testTuplyFunctions :: forall a v . (CommonContext a v , VectorContext ( a , a ) v , VectorContext ( a , a , a ) v ) => v a -> [Test ]
475
471
testTuplyFunctions _ = $ (testProperties [ 'prop_zip, 'prop_zip3
476
472
, 'prop_unzip, 'prop_unzip3
477
- #if MIN_VERSION_base(4,4,0)
478
473
, 'prop_mzip, 'prop_munzip
479
- #endif
480
474
])
481
475
where
482
476
prop_zip :: P (v a -> v a -> v (a , a )) = V. zip `eq` zip
483
477
prop_zip3 :: P (v a -> v a -> v a -> v (a , a , a )) = V. zip3 `eq` zip3
484
478
prop_unzip :: P (v (a , a ) -> (v a , v a )) = V. unzip `eq` unzip
485
479
prop_unzip3 :: P (v (a , a , a ) -> (v a , v a , v a )) = V. unzip3 `eq` unzip3
486
- #if MIN_VERSION_base(4,4,0)
487
480
prop_mzip :: P (Data.Vector. Vector a -> Data.Vector. Vector a -> Data.Vector. Vector (a , a ))
488
481
= mzip `eq` zip
489
482
prop_munzip :: P (Data.Vector. Vector (a , a ) -> (Data.Vector. Vector a , Data.Vector. Vector a ))
490
483
= munzip `eq` unzip
491
- #endif
492
484
493
- testOrdFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Ord a , Ord (v a )) => v a -> [Test ]
485
+ testOrdFunctions :: forall a v . (CommonContext a v , Ord a , Ord (v a )) => v a -> [Test ]
494
486
testOrdFunctions _ = $ (testProperties
495
487
['prop_compare,
496
488
'prop_maximum, 'prop_minimum,
@@ -502,7 +494,7 @@ testOrdFunctions _ = $(testProperties
502
494
prop_minIndex :: P (v a -> Int ) = not . V. null ===> V. minIndex `eq` minIndex
503
495
prop_maxIndex :: P (v a -> Int ) = not . V. null ===> V. maxIndex `eq` maxIndex
504
496
505
- testEnumFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Enum a , Ord a , Num a , Random a ) => v a -> [Test ]
497
+ testEnumFunctions :: forall a v . (CommonContext a v , Enum a , Ord a , Num a , Random a ) => v a -> [Test ]
506
498
testEnumFunctions _ = $ (testProperties
507
499
[ 'prop_enumFromN, 'prop_enumFromThenN,
508
500
'prop_enumFromTo, 'prop_enumFromThenTo])
@@ -533,28 +525,28 @@ testEnumFunctions _ = $(testProperties
533
525
where
534
526
d = abs (j- i)
535
527
536
- testMonoidFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Monoid (v a )) => v a -> [Test ]
528
+ testMonoidFunctions :: forall a v . (CommonContext a v , Monoid (v a )) => v a -> [Test ]
537
529
testMonoidFunctions _ = $ (testProperties
538
530
[ 'prop_mempty, 'prop_mappend, 'prop_mconcat ])
539
531
where
540
532
prop_mempty :: P (v a ) = mempty `eq` mempty
541
533
prop_mappend :: P (v a -> v a -> v a ) = mappend `eq` mappend
542
534
prop_mconcat :: P ([v a ] -> v a ) = mconcat `eq` mconcat
543
535
544
- testFunctorFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Functor v ) => v a -> [Test ]
536
+ testFunctorFunctions :: forall a v . (CommonContext a v , Functor v ) => v a -> [Test ]
545
537
testFunctorFunctions _ = $ (testProperties
546
538
[ 'prop_fmap ])
547
539
where
548
540
prop_fmap :: P ((a -> a ) -> v a -> v a ) = fmap `eq` fmap
549
541
550
- testMonadFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Monad v ) => v a -> [Test ]
542
+ testMonadFunctions :: forall a v . (CommonContext a v , Monad v ) => v a -> [Test ]
551
543
testMonadFunctions _ = $ (testProperties
552
544
[ 'prop_return, 'prop_bind ])
553
545
where
554
546
prop_return :: P (a -> v a ) = return `eq` return
555
547
prop_bind :: P (v a -> (a -> v a ) -> v a ) = (>>=) `eq` (>>=)
556
548
557
- testApplicativeFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , V. Vector v (a -> a ), Applicative. Applicative v ) => v a -> [Test ]
549
+ testApplicativeFunctions :: forall a v . (CommonContext a v , V. Vector v (a -> a ), Applicative. Applicative v ) => v a -> [Test ]
558
550
testApplicativeFunctions _ = $ (testProperties
559
551
[ 'prop_applicative_pure, 'prop_applicative_appl ])
560
552
where
@@ -563,27 +555,27 @@ testApplicativeFunctions _ = $(testProperties
563
555
prop_applicative_appl :: [a -> a ] -> P (v a -> v a )
564
556
= \ fs -> (Applicative. <*>) (V. fromList fs) `eq` (Applicative. <*>) fs
565
557
566
- testAlternativeFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Applicative. Alternative v ) => v a -> [Test ]
558
+ testAlternativeFunctions :: forall a v . (CommonContext a v , Applicative. Alternative v ) => v a -> [Test ]
567
559
testAlternativeFunctions _ = $ (testProperties
568
560
[ 'prop_alternative_empty, 'prop_alternative_or ])
569
561
where
570
562
prop_alternative_empty :: P (v a ) = Applicative. empty `eq` Applicative. empty
571
563
prop_alternative_or :: P (v a -> v a -> v a )
572
564
= (Applicative. <|>) `eq` (Applicative. <|>)
573
565
574
- testBoolFunctions :: forall v . (COMMON_CONTEXT ( Bool , v ) ) => v Bool -> [Test ]
566
+ testBoolFunctions :: forall v . (CommonContext Bool v ) => v Bool -> [Test ]
575
567
testBoolFunctions _ = $ (testProperties ['prop_and, 'prop_or])
576
568
where
577
569
prop_and :: P (v Bool -> Bool ) = V. and `eq` and
578
570
prop_or :: P (v Bool -> Bool ) = V. or `eq` or
579
571
580
- testNumFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Num a ) => v a -> [Test ]
572
+ testNumFunctions :: forall a v . (CommonContext a v , Num a ) => v a -> [Test ]
581
573
testNumFunctions _ = $ (testProperties ['prop_sum, 'prop_product])
582
574
where
583
575
prop_sum :: P (v a -> a ) = V. sum `eq` sum
584
576
prop_product :: P (v a -> a ) = V. product `eq` product
585
577
586
- testNestedVectorFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) ) => v a -> [Test ]
578
+ testNestedVectorFunctions :: forall a v . (CommonContext a v ) => v a -> [Test ]
587
579
testNestedVectorFunctions _ = $ (testProperties [] )
588
580
where
589
581
-- Prelude
@@ -595,7 +587,7 @@ testNestedVectorFunctions _ = $(testProperties [])
595
587
-- prop_inits = V.inits `eq1` (inits :: v a -> [v a])
596
588
-- prop_tails = V.tails `eq1` (tails :: v a -> [v a])
597
589
598
- testGeneralBoxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector. Vector) , Ord a ) => Data.Vector. Vector a -> [Test ]
590
+ testGeneralBoxedVector :: forall a . (CommonContext a Data.Vector. Vector , Ord a ) => Data.Vector. Vector a -> [Test ]
599
591
testGeneralBoxedVector dummy = concatMap ($ dummy) [
600
592
testSanity,
601
593
testPolymorphicFunctions,
@@ -615,7 +607,7 @@ testBoolBoxedVector dummy = concatMap ($ dummy)
615
607
, testBoolFunctions
616
608
]
617
609
618
- testNumericBoxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector. Vector) , Ord a , Num a , Enum a , Random a ) => Data.Vector. Vector a -> [Test ]
610
+ testNumericBoxedVector :: forall a . (CommonContext a Data.Vector. Vector , Ord a , Num a , Enum a , Random a ) => Data.Vector. Vector a -> [Test ]
619
611
testNumericBoxedVector dummy = concatMap ($ dummy)
620
612
[
621
613
testGeneralBoxedVector
@@ -624,15 +616,15 @@ testNumericBoxedVector dummy = concatMap ($ dummy)
624
616
]
625
617
626
618
627
- testGeneralPrimitiveVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Primitive. Vector) , Data.Vector.Primitive. Prim a , Ord a ) => Data.Vector.Primitive. Vector a -> [Test ]
619
+ testGeneralPrimitiveVector :: forall a . (CommonContext a Data.Vector.Primitive. Vector , Data.Vector.Primitive. Prim a , Ord a ) => Data.Vector.Primitive. Vector a -> [Test ]
628
620
testGeneralPrimitiveVector dummy = concatMap ($ dummy) [
629
621
testSanity,
630
622
testPolymorphicFunctions,
631
623
testOrdFunctions,
632
624
testMonoidFunctions
633
625
]
634
626
635
- testNumericPrimitiveVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Primitive. Vector) , Data.Vector.Primitive. Prim a , Ord a , Num a , Enum a , Random a ) => Data.Vector.Primitive. Vector a -> [Test ]
627
+ testNumericPrimitiveVector :: forall a . (CommonContext a Data.Vector.Primitive. Vector , Data.Vector.Primitive. Prim a , Ord a , Num a , Enum a , Random a ) => Data.Vector.Primitive. Vector a -> [Test ]
636
628
testNumericPrimitiveVector dummy = concatMap ($ dummy)
637
629
[
638
630
testGeneralPrimitiveVector
@@ -641,15 +633,15 @@ testNumericPrimitiveVector dummy = concatMap ($ dummy)
641
633
]
642
634
643
635
644
- testGeneralStorableVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Storable. Vector) , Data.Vector.Storable. Storable a , Ord a ) => Data.Vector.Storable. Vector a -> [Test ]
636
+ testGeneralStorableVector :: forall a . (CommonContext a Data.Vector.Storable. Vector , Data.Vector.Storable. Storable a , Ord a ) => Data.Vector.Storable. Vector a -> [Test ]
645
637
testGeneralStorableVector dummy = concatMap ($ dummy) [
646
638
testSanity,
647
639
testPolymorphicFunctions,
648
640
testOrdFunctions,
649
641
testMonoidFunctions
650
642
]
651
643
652
- testNumericStorableVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Storable. Vector) , Data.Vector.Storable. Storable a , Ord a , Num a , Enum a , Random a ) => Data.Vector.Storable. Vector a -> [Test ]
644
+ testNumericStorableVector :: forall a . (CommonContext a Data.Vector.Storable. Vector , Data.Vector.Storable. Storable a , Ord a , Num a , Enum a , Random a ) => Data.Vector.Storable. Vector a -> [Test ]
653
645
testNumericStorableVector dummy = concatMap ($ dummy)
654
646
[
655
647
testGeneralStorableVector
@@ -658,7 +650,7 @@ testNumericStorableVector dummy = concatMap ($ dummy)
658
650
]
659
651
660
652
661
- testGeneralUnboxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Unboxed. Vector) , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
653
+ testGeneralUnboxedVector :: forall a . (CommonContext a Data.Vector.Unboxed. Vector , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
662
654
testGeneralUnboxedVector dummy = concatMap ($ dummy) [
663
655
testSanity,
664
656
testPolymorphicFunctions,
@@ -677,15 +669,15 @@ testBoolUnboxedVector dummy = concatMap ($ dummy)
677
669
, testBoolFunctions
678
670
]
679
671
680
- testNumericUnboxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Unboxed. Vector) , Data.Vector.Unboxed. Unbox a , Ord a , Num a , Enum a , Random a ) => Data.Vector.Unboxed. Vector a -> [Test ]
672
+ testNumericUnboxedVector :: forall a . (CommonContext a Data.Vector.Unboxed. Vector , Data.Vector.Unboxed. Unbox a , Ord a , Num a , Enum a , Random a ) => Data.Vector.Unboxed. Vector a -> [Test ]
681
673
testNumericUnboxedVector dummy = concatMap ($ dummy)
682
674
[
683
675
testGeneralUnboxedVector
684
676
, testNumFunctions
685
677
, testEnumFunctions
686
678
]
687
679
688
- testTupleUnboxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Unboxed. Vector) , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
680
+ testTupleUnboxedVector :: forall a . (CommonContext a Data.Vector.Unboxed. Vector , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
689
681
testTupleUnboxedVector dummy = concatMap ($ dummy)
690
682
[
691
683
testGeneralUnboxedVector
0 commit comments