-- | Some functions and generators suitable for writing QuickCheck-- properties.moduleAgda.Utils.TestHelpers(-- * Algebraic propertiesassociative,commutative,isZero,identity,leftDistributive,rightDistributive-- * Generators,natural,positive,maybeGen,maybeCoGen,listOfElements,two,three-- * Test driver.,runTests)whereimportControl.MonadimportData.ListimportAgda.Utils.QuickCheckimportqualifiedAgda.Utils.IO.LocaleasLocIO-------------------------------------------------------------------------- Algebraic properties-- | Is the operator associative?associative::(Arbitrarya,Eqa,Showa)=>(a->a->a)->a->a->a->Boolassociative(+)=\xyz->x+(y+z)==(x+y)+z-- | Is the operator commutative?commutative::(Arbitrarya,Eqa,Showa)=>(a->a->a)->a->a->Boolcommutative(+)=\xy->x+y==y+x-- | Is the element a zero for the operator?isZero::(Arbitrarya,Eqa,Showa)=>a->(a->a->a)->a->BoolisZerozer(*)=\x->(zer*x==zer)&&(x*zer==zer)-- | Is the element a unit for the operator?identity::(Arbitrarya,Eqa,Showa)=>a->(a->a->a)->a->Boolidentityone(*)=\x->(one*x==x)&&(x*one==x)-- | Does the first operator distribute (from the left) over the-- second one?leftDistributive::(Arbitrarya,Eqa,Showa)=>(a->a->a)->(a->a->a)->a->a->a->BoolleftDistributive(*)(+)=\xyz->x*(y+z)==(x*y)+(x*z)-- | Does the first operator distribute (from the right) over the-- second one?rightDistributive::(Arbitrarya,Eqa,Showa)=>(a->a->a)->(a->a->a)->a->a->a->BoolrightDistributive(*)(+)=\xyz->(x+y)*z==(x*z)+(y*z)-------------------------------------------------------------------------- Generators-- | Generates natural numbers.natural::(Integrali)=>Geninatural=fmap(fromInteger.abs)arbitrary-- | Generates positive numbers.positive::(Integrali)=>Genipositive=fmap((+1).abs.fromInteger)arbitrary-- | Generates a list of elements picked from a given list.listOfElements::[a]->Gen[a]listOfElements[]=return[]listOfElementsxs=listOf$elementsxs-- | Generates values of 'Maybe' type, using the given generator to-- generate the contents of the 'Just' constructor.maybeGen::Gena->Gen(Maybea)maybeGengen=frequency[(1,returnNothing),(9,fmapJustgen)]-- | 'Coarbitrary' \"generator\" for 'Maybe'.maybeCoGen::(a->Genb->Genb)->(Maybea->Genb->Genb)maybeCoGenfNothing=variant0maybeCoGenf(Justx)=variant1.fx-- | Generates two elements.two::Gena->Gen(a,a)twogen=liftM2(,)gengen-- | Generates three elements.three::Gena->Gen(a,a,a)threegen=liftM3(,,)gengengen-------------------------------------------------------------------------- Test driver-- | Runs the tests, and returns 'True' if all tests were successful.runTests::String-- ^ A label for the tests. Used for-- informational purposes.->[IOBool]->IOBoolrunTestsnametests=doLocIO.putStrLnnamefmapand$sequencetests