Skip to content

Commit 3edeb94

Browse files
committed
Replace macros with ConstraintKinds (fixes #48)
1 parent c0308f1 commit 3edeb94

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

tests/Tests/Vector.hs

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE ConstraintKinds #-}
12
module Tests.Vector (tests) where
23

34
import Boilerplater
@@ -24,14 +25,11 @@ import System.Random (Random)
2425
import Data.Functor.Identity
2526
import Control.Monad.Trans.Writer
2627

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)
3533

3634
-- TODO: implement Vector equivalents of list functions for some of the commented out properties
3735

@@ -66,7 +64,7 @@ import Control.Monad.Trans.Writer
6664

6765
-- TODO: test non-IVector stuff?
6866

69-
testSanity :: forall a v. (COMMON_CONTEXT(a, v)) => v a -> [Test]
67+
testSanity :: forall a v. (CommonContext a v) => v a -> [Test]
7068
testSanity _ = [
7169
testProperty "fromList.toList == id" prop_fromList_toList,
7270
testProperty "toList.fromList == id" prop_toList_fromList,
@@ -79,7 +77,7 @@ testSanity _ = [
7977
prop_unstream_stream (v :: v a) = (V.unstream . V.stream) v == v
8078
prop_stream_unstream (s :: S.Bundle v a) = ((V.stream :: v a -> S.Bundle v a) . V.unstream) s == s
8179

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]
8381
testPolymorphicFunctions _ = $(testProperties [
8482
'prop_eq,
8583

@@ -423,15 +421,15 @@ testPolymorphicFunctions _ = $(testProperties [
423421
constructrN xs 0 _ = xs
424422
constructrN xs n f = constructrN (f xs : xs) (n-1) f
425423

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]
427425
testTuplyFunctions _ = $(testProperties ['prop_zip, 'prop_zip3, 'prop_unzip, 'prop_unzip3])
428426
where
429427
prop_zip :: P (v a -> v a -> v (a, a)) = V.zip `eq` zip
430428
prop_zip3 :: P (v a -> v a -> v a -> v (a, a, a)) = V.zip3 `eq` zip3
431429
prop_unzip :: P (v (a, a) -> (v a, v a)) = V.unzip `eq` unzip
432430
prop_unzip3 :: P (v (a, a, a) -> (v a, v a, v a)) = V.unzip3 `eq` unzip3
433431

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]
435433
testOrdFunctions _ = $(testProperties
436434
['prop_compare,
437435
'prop_maximum, 'prop_minimum,
@@ -443,7 +441,7 @@ testOrdFunctions _ = $(testProperties
443441
prop_minIndex :: P (v a -> Int) = not . V.null ===> V.minIndex `eq` minIndex
444442
prop_maxIndex :: P (v a -> Int) = not . V.null ===> V.maxIndex `eq` maxIndex
445443

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]
447445
testEnumFunctions _ = $(testProperties
448446
[ 'prop_enumFromN, 'prop_enumFromThenN,
449447
'prop_enumFromTo, 'prop_enumFromThenTo])
@@ -474,28 +472,28 @@ testEnumFunctions _ = $(testProperties
474472
where
475473
d = abs (j-i)
476474

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]
478476
testMonoidFunctions _ = $(testProperties
479477
[ 'prop_mempty, 'prop_mappend, 'prop_mconcat ])
480478
where
481479
prop_mempty :: P (v a) = mempty `eq` mempty
482480
prop_mappend :: P (v a -> v a -> v a) = mappend `eq` mappend
483481
prop_mconcat :: P ([v a] -> v a) = mconcat `eq` mconcat
484482

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]
486484
testFunctorFunctions _ = $(testProperties
487485
[ 'prop_fmap ])
488486
where
489487
prop_fmap :: P ((a -> a) -> v a -> v a) = fmap `eq` fmap
490488

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]
492490
testMonadFunctions _ = $(testProperties
493491
[ 'prop_return, 'prop_bind ])
494492
where
495493
prop_return :: P (a -> v a) = return `eq` return
496494
prop_bind :: P (v a -> (a -> v a) -> v a) = (>>=) `eq` (>>=)
497495

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]
499497
testApplicativeFunctions _ = $(testProperties
500498
[ 'prop_applicative_pure, 'prop_applicative_appl ])
501499
where
@@ -504,27 +502,27 @@ testApplicativeFunctions _ = $(testProperties
504502
prop_applicative_appl :: [a -> a] -> P (v a -> v a)
505503
= \fs -> (Applicative.<*>) (V.fromList fs) `eq` (Applicative.<*>) fs
506504

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]
508506
testAlternativeFunctions _ = $(testProperties
509507
[ 'prop_alternative_empty, 'prop_alternative_or ])
510508
where
511509
prop_alternative_empty :: P (v a) = Applicative.empty `eq` Applicative.empty
512510
prop_alternative_or :: P (v a -> v a -> v a)
513511
= (Applicative.<|>) `eq` (Applicative.<|>)
514512

515-
testBoolFunctions :: forall v. (COMMON_CONTEXT(Bool, v)) => v Bool -> [Test]
513+
testBoolFunctions :: forall v. (CommonContext Bool v) => v Bool -> [Test]
516514
testBoolFunctions _ = $(testProperties ['prop_and, 'prop_or])
517515
where
518516
prop_and :: P (v Bool -> Bool) = V.and `eq` and
519517
prop_or :: P (v Bool -> Bool) = V.or `eq` or
520518

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]
522520
testNumFunctions _ = $(testProperties ['prop_sum, 'prop_product])
523521
where
524522
prop_sum :: P (v a -> a) = V.sum `eq` sum
525523
prop_product :: P (v a -> a) = V.product `eq` product
526524

527-
testNestedVectorFunctions :: forall a v. (COMMON_CONTEXT(a, v)) => v a -> [Test]
525+
testNestedVectorFunctions :: forall a v. (CommonContext a v) => v a -> [Test]
528526
testNestedVectorFunctions _ = $(testProperties [])
529527
where
530528
-- Prelude
@@ -536,7 +534,7 @@ testNestedVectorFunctions _ = $(testProperties [])
536534
--prop_inits = V.inits `eq1` (inits :: v a -> [v a])
537535
--prop_tails = V.tails `eq1` (tails :: v a -> [v a])
538536

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]
540538
testGeneralBoxedVector dummy = concatMap ($ dummy) [
541539
testSanity,
542540
testPolymorphicFunctions,
@@ -556,7 +554,7 @@ testBoolBoxedVector dummy = concatMap ($ dummy)
556554
, testBoolFunctions
557555
]
558556

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]
560558
testNumericBoxedVector dummy = concatMap ($ dummy)
561559
[
562560
testGeneralBoxedVector
@@ -565,15 +563,15 @@ testNumericBoxedVector dummy = concatMap ($ dummy)
565563
]
566564

567565

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]
569567
testGeneralPrimitiveVector dummy = concatMap ($ dummy) [
570568
testSanity,
571569
testPolymorphicFunctions,
572570
testOrdFunctions,
573571
testMonoidFunctions
574572
]
575573

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]
577575
testNumericPrimitiveVector dummy = concatMap ($ dummy)
578576
[
579577
testGeneralPrimitiveVector
@@ -582,15 +580,15 @@ testNumericPrimitiveVector dummy = concatMap ($ dummy)
582580
]
583581

584582

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]
586584
testGeneralStorableVector dummy = concatMap ($ dummy) [
587585
testSanity,
588586
testPolymorphicFunctions,
589587
testOrdFunctions,
590588
testMonoidFunctions
591589
]
592590

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]
594592
testNumericStorableVector dummy = concatMap ($ dummy)
595593
[
596594
testGeneralStorableVector
@@ -599,7 +597,7 @@ testNumericStorableVector dummy = concatMap ($ dummy)
599597
]
600598

601599

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]
603601
testGeneralUnboxedVector dummy = concatMap ($ dummy) [
604602
testSanity,
605603
testPolymorphicFunctions,
@@ -618,15 +616,15 @@ testBoolUnboxedVector dummy = concatMap ($ dummy)
618616
, testBoolFunctions
619617
]
620618

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]
622620
testNumericUnboxedVector dummy = concatMap ($ dummy)
623621
[
624622
testGeneralUnboxedVector
625623
, testNumFunctions
626624
, testEnumFunctions
627625
]
628626

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]
630628
testTupleUnboxedVector dummy = concatMap ($ dummy)
631629
[
632630
testGeneralUnboxedVector

0 commit comments

Comments
 (0)