1
+ {-# LANGUAGE ConstraintKinds #-}
1
2
module Tests.Vector (tests ) where
2
3
3
4
import Boilerplater
@@ -24,14 +25,11 @@ import System.Random (Random)
24
25
import Data.Functor.Identity
25
26
import Control.Monad.Trans.Writer
26
27
27
- #define COMMON_CONTEXT(a, v) \
28
- VANILLA_CONTEXT (a, v), VECTOR_CONTEXT (a, v)
29
-
30
- #define VANILLA_CONTEXT(a, v) \
31
- Eq a, Show a, Arbitrary a, CoArbitrary a, TestData a, Model a ~ a, EqTest a ~ Property
32
-
33
- #define VECTOR_CONTEXT(a, v) \
34
- 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
28
+ type CommonContext a v = (VanillaContext a , VectorContext a v )
29
+ type VanillaContext a = ( Eq a , Show a , Arbitrary a , CoArbitrary a
30
+ , TestData a , Model a ~ a , EqTest a ~ Property )
31
+ type VectorContext a v = ( Eq (v a ), Show (v a ), Arbitrary (v a ), CoArbitrary (v a )
32
+ , TestData (v a ), Model (v a ) ~ [a ], EqTest (v a ) ~ Property , V. Vector v a )
35
33
36
34
-- TODO: implement Vector equivalents of list functions for some of the commented out properties
37
35
@@ -66,7 +64,7 @@ import Control.Monad.Trans.Writer
66
64
67
65
-- TODO: test non-IVector stuff?
68
66
69
- testSanity :: forall a v . (COMMON_CONTEXT ( a , v ) ) => v a -> [Test ]
67
+ testSanity :: forall a v . (CommonContext a v ) => v a -> [Test ]
70
68
testSanity _ = [
71
69
testProperty " fromList.toList == id" prop_fromList_toList,
72
70
testProperty " toList.fromList == id" prop_toList_fromList,
@@ -79,7 +77,7 @@ testSanity _ = [
79
77
prop_unstream_stream (v :: v a ) = (V. unstream . V. stream) v == v
80
78
prop_stream_unstream (s :: S. Bundle v a ) = ((V. stream :: v a -> S. Bundle v a ) . V. unstream) s == s
81
79
82
- testPolymorphicFunctions :: forall a v . (COMMON_CONTEXT ( a , v ), VECTOR_CONTEXT ( Int , v ) ) => v a -> [Test ]
80
+ testPolymorphicFunctions :: forall a v . (CommonContext a v , VectorContext Int v ) => v a -> [Test ]
83
81
testPolymorphicFunctions _ = $ (testProperties [
84
82
'prop_eq,
85
83
@@ -423,15 +421,15 @@ testPolymorphicFunctions _ = $(testProperties [
423
421
constructrN xs 0 _ = xs
424
422
constructrN xs n f = constructrN (f xs : xs) (n- 1 ) f
425
423
426
- testTuplyFunctions :: forall a v . (COMMON_CONTEXT ( a , v ), VECTOR_CONTEXT (( a , a ), v ), VECTOR_CONTEXT (( a , a , a ), v ) ) => v a -> [Test ]
424
+ testTuplyFunctions :: forall a v . (CommonContext a v , VectorContext ( a , a ) v , VectorContext ( a , a , a ) v ) => v a -> [Test ]
427
425
testTuplyFunctions _ = $ (testProperties ['prop_zip, 'prop_zip3 , 'prop_unzip, 'prop_unzip3 ])
428
426
where
429
427
prop_zip :: P (v a -> v a -> v (a , a )) = V. zip `eq` zip
430
428
prop_zip3 :: P (v a -> v a -> v a -> v (a , a , a )) = V. zip3 `eq` zip3
431
429
prop_unzip :: P (v (a , a ) -> (v a , v a )) = V. unzip `eq` unzip
432
430
prop_unzip3 :: P (v (a , a , a ) -> (v a , v a , v a )) = V. unzip3 `eq` unzip3
433
431
434
- testOrdFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Ord a , Ord (v a )) => v a -> [Test ]
432
+ testOrdFunctions :: forall a v . (CommonContext a v , Ord a , Ord (v a )) => v a -> [Test ]
435
433
testOrdFunctions _ = $ (testProperties
436
434
['prop_compare,
437
435
'prop_maximum, 'prop_minimum,
@@ -443,7 +441,7 @@ testOrdFunctions _ = $(testProperties
443
441
prop_minIndex :: P (v a -> Int ) = not . V. null ===> V. minIndex `eq` minIndex
444
442
prop_maxIndex :: P (v a -> Int ) = not . V. null ===> V. maxIndex `eq` maxIndex
445
443
446
- testEnumFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Enum a , Ord a , Num a , Random a ) => v a -> [Test ]
444
+ testEnumFunctions :: forall a v . (CommonContext a v , Enum a , Ord a , Num a , Random a ) => v a -> [Test ]
447
445
testEnumFunctions _ = $ (testProperties
448
446
[ 'prop_enumFromN, 'prop_enumFromThenN,
449
447
'prop_enumFromTo, 'prop_enumFromThenTo])
@@ -474,28 +472,28 @@ testEnumFunctions _ = $(testProperties
474
472
where
475
473
d = abs (j- i)
476
474
477
- testMonoidFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Monoid (v a )) => v a -> [Test ]
475
+ testMonoidFunctions :: forall a v . (CommonContext a v , Monoid (v a )) => v a -> [Test ]
478
476
testMonoidFunctions _ = $ (testProperties
479
477
[ 'prop_mempty, 'prop_mappend, 'prop_mconcat ])
480
478
where
481
479
prop_mempty :: P (v a ) = mempty `eq` mempty
482
480
prop_mappend :: P (v a -> v a -> v a ) = mappend `eq` mappend
483
481
prop_mconcat :: P ([v a ] -> v a ) = mconcat `eq` mconcat
484
482
485
- testFunctorFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Functor v ) => v a -> [Test ]
483
+ testFunctorFunctions :: forall a v . (CommonContext a v , Functor v ) => v a -> [Test ]
486
484
testFunctorFunctions _ = $ (testProperties
487
485
[ 'prop_fmap ])
488
486
where
489
487
prop_fmap :: P ((a -> a ) -> v a -> v a ) = fmap `eq` fmap
490
488
491
- testMonadFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Monad v ) => v a -> [Test ]
489
+ testMonadFunctions :: forall a v . (CommonContext a v , Monad v ) => v a -> [Test ]
492
490
testMonadFunctions _ = $ (testProperties
493
491
[ 'prop_return, 'prop_bind ])
494
492
where
495
493
prop_return :: P (a -> v a ) = return `eq` return
496
494
prop_bind :: P (v a -> (a -> v a ) -> v a ) = (>>=) `eq` (>>=)
497
495
498
- testApplicativeFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , V. Vector v (a -> a ), Applicative. Applicative v ) => v a -> [Test ]
496
+ testApplicativeFunctions :: forall a v . (CommonContext a v , V. Vector v (a -> a ), Applicative. Applicative v ) => v a -> [Test ]
499
497
testApplicativeFunctions _ = $ (testProperties
500
498
[ 'prop_applicative_pure, 'prop_applicative_appl ])
501
499
where
@@ -504,27 +502,27 @@ testApplicativeFunctions _ = $(testProperties
504
502
prop_applicative_appl :: [a -> a ] -> P (v a -> v a )
505
503
= \ fs -> (Applicative. <*>) (V. fromList fs) `eq` (Applicative. <*>) fs
506
504
507
- testAlternativeFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Applicative. Alternative v ) => v a -> [Test ]
505
+ testAlternativeFunctions :: forall a v . (CommonContext a v , Applicative. Alternative v ) => v a -> [Test ]
508
506
testAlternativeFunctions _ = $ (testProperties
509
507
[ 'prop_alternative_empty, 'prop_alternative_or ])
510
508
where
511
509
prop_alternative_empty :: P (v a ) = Applicative. empty `eq` Applicative. empty
512
510
prop_alternative_or :: P (v a -> v a -> v a )
513
511
= (Applicative. <|>) `eq` (Applicative. <|>)
514
512
515
- testBoolFunctions :: forall v . (COMMON_CONTEXT ( Bool , v ) ) => v Bool -> [Test ]
513
+ testBoolFunctions :: forall v . (CommonContext Bool v ) => v Bool -> [Test ]
516
514
testBoolFunctions _ = $ (testProperties ['prop_and, 'prop_or])
517
515
where
518
516
prop_and :: P (v Bool -> Bool ) = V. and `eq` and
519
517
prop_or :: P (v Bool -> Bool ) = V. or `eq` or
520
518
521
- testNumFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) , Num a ) => v a -> [Test ]
519
+ testNumFunctions :: forall a v . (CommonContext a v , Num a ) => v a -> [Test ]
522
520
testNumFunctions _ = $ (testProperties ['prop_sum, 'prop_product])
523
521
where
524
522
prop_sum :: P (v a -> a ) = V. sum `eq` sum
525
523
prop_product :: P (v a -> a ) = V. product `eq` product
526
524
527
- testNestedVectorFunctions :: forall a v . (COMMON_CONTEXT ( a , v ) ) => v a -> [Test ]
525
+ testNestedVectorFunctions :: forall a v . (CommonContext a v ) => v a -> [Test ]
528
526
testNestedVectorFunctions _ = $ (testProperties [] )
529
527
where
530
528
-- Prelude
@@ -536,7 +534,7 @@ testNestedVectorFunctions _ = $(testProperties [])
536
534
-- prop_inits = V.inits `eq1` (inits :: v a -> [v a])
537
535
-- prop_tails = V.tails `eq1` (tails :: v a -> [v a])
538
536
539
- testGeneralBoxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector. Vector) , Ord a ) => Data.Vector. Vector a -> [Test ]
537
+ testGeneralBoxedVector :: forall a . (CommonContext a Data.Vector. Vector , Ord a ) => Data.Vector. Vector a -> [Test ]
540
538
testGeneralBoxedVector dummy = concatMap ($ dummy) [
541
539
testSanity,
542
540
testPolymorphicFunctions,
@@ -556,7 +554,7 @@ testBoolBoxedVector dummy = concatMap ($ dummy)
556
554
, testBoolFunctions
557
555
]
558
556
559
- testNumericBoxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector. Vector) , Ord a , Num a , Enum a , Random a ) => Data.Vector. Vector a -> [Test ]
557
+ testNumericBoxedVector :: forall a . (CommonContext a Data.Vector. Vector , Ord a , Num a , Enum a , Random a ) => Data.Vector. Vector a -> [Test ]
560
558
testNumericBoxedVector dummy = concatMap ($ dummy)
561
559
[
562
560
testGeneralBoxedVector
@@ -565,15 +563,15 @@ testNumericBoxedVector dummy = concatMap ($ dummy)
565
563
]
566
564
567
565
568
- testGeneralPrimitiveVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Primitive. Vector) , Data.Vector.Primitive. Prim a , Ord a ) => Data.Vector.Primitive. Vector a -> [Test ]
566
+ testGeneralPrimitiveVector :: forall a . (CommonContext a Data.Vector.Primitive. Vector , Data.Vector.Primitive. Prim a , Ord a ) => Data.Vector.Primitive. Vector a -> [Test ]
569
567
testGeneralPrimitiveVector dummy = concatMap ($ dummy) [
570
568
testSanity,
571
569
testPolymorphicFunctions,
572
570
testOrdFunctions,
573
571
testMonoidFunctions
574
572
]
575
573
576
- 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 ]
574
+ 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 ]
577
575
testNumericPrimitiveVector dummy = concatMap ($ dummy)
578
576
[
579
577
testGeneralPrimitiveVector
@@ -582,15 +580,15 @@ testNumericPrimitiveVector dummy = concatMap ($ dummy)
582
580
]
583
581
584
582
585
- testGeneralStorableVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Storable. Vector) , Data.Vector.Storable. Storable a , Ord a ) => Data.Vector.Storable. Vector a -> [Test ]
583
+ testGeneralStorableVector :: forall a . (CommonContext a Data.Vector.Storable. Vector , Data.Vector.Storable. Storable a , Ord a ) => Data.Vector.Storable. Vector a -> [Test ]
586
584
testGeneralStorableVector dummy = concatMap ($ dummy) [
587
585
testSanity,
588
586
testPolymorphicFunctions,
589
587
testOrdFunctions,
590
588
testMonoidFunctions
591
589
]
592
590
593
- 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 ]
591
+ 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 ]
594
592
testNumericStorableVector dummy = concatMap ($ dummy)
595
593
[
596
594
testGeneralStorableVector
@@ -599,7 +597,7 @@ testNumericStorableVector dummy = concatMap ($ dummy)
599
597
]
600
598
601
599
602
- testGeneralUnboxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Unboxed. Vector) , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
600
+ testGeneralUnboxedVector :: forall a . (CommonContext a Data.Vector.Unboxed. Vector , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
603
601
testGeneralUnboxedVector dummy = concatMap ($ dummy) [
604
602
testSanity,
605
603
testPolymorphicFunctions,
@@ -618,15 +616,15 @@ testBoolUnboxedVector dummy = concatMap ($ dummy)
618
616
, testBoolFunctions
619
617
]
620
618
621
- 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 ]
619
+ 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 ]
622
620
testNumericUnboxedVector dummy = concatMap ($ dummy)
623
621
[
624
622
testGeneralUnboxedVector
625
623
, testNumFunctions
626
624
, testEnumFunctions
627
625
]
628
626
629
- testTupleUnboxedVector :: forall a . (COMMON_CONTEXT ( a , Data.Vector.Unboxed. Vector) , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
627
+ testTupleUnboxedVector :: forall a . (CommonContext a Data.Vector.Unboxed. Vector , Data.Vector.Unboxed. Unbox a , Ord a ) => Data.Vector.Unboxed. Vector a -> [Test ]
630
628
testTupleUnboxedVector dummy = concatMap ($ dummy)
631
629
[
632
630
testGeneralUnboxedVector
0 commit comments