fitspec-0.2.2: refining property sets for testing Haskell programs

Safe HaskellNone
LanguageHaskell2010

FitSpec.Mutable

Description

Enumeration of function mutations

Synopsis

Documentation

class Mutable a where Source #

This typeclass is similar to Listable.

A type is Mutable when there exists a function that is able to list mutations of a value. Ideally: list all possible values without repetitions.

Instances are usually defined by a mutiers function that given a value, returns tiers of mutants of that value: the first tier contains the equivalent mutant, of size 0, the second tier contains mutants of size 1, the third tier contains mutants of size 2, and so on.

The equivalent mutant is the actual function without mutations.

The size of a mutant is given by the sum of: the number of mutated points (relations) and the sizes of mutated arguments and results.

To get only inequivalent mutants, just take the tail of either mutants or mutiers:

tail mutants
tail mutiers

Given that the underlying Listable enumeration has no repetitions parametric instances defined in this file will have no repeated mutants.

Minimal complete definition

mutants | mutiers

Methods

mutiers :: a -> [[a]] Source #

mutants :: a -> [a] Source #

Instances

Mutable Bool Source #
mutants True = [True,False]

Methods

mutiers :: Bool -> [[Bool]] Source #

mutants :: Bool -> [Bool] Source #

Mutable Char Source # 

Methods

mutiers :: Char -> [[Char]] Source #

mutants :: Char -> [Char] Source #

Mutable Int Source #
mutants 3 = [3,0,1,2,4,5,6,7,8,9,...

Methods

mutiers :: Int -> [[Int]] Source #

mutants :: Int -> [Int] Source #

Mutable () Source #
mutants () = [()]

Methods

mutiers :: () -> [[()]] Source #

mutants :: () -> [()] Source #

(Eq a, Listable a) => Mutable [a] Source #
mutants [0] = [ [0], [], [0,0], [1], ...

Methods

mutiers :: [a] -> [[[a]]] Source #

mutants :: [a] -> [[a]] Source #

(Eq a, Listable a) => Mutable (Maybe a) Source #
mutants (Just 0) = [Just 0, Nothing, ...

Methods

mutiers :: Maybe a -> [[Maybe a]] Source #

mutants :: Maybe a -> [Maybe a] Source #

(Eq a, Listable a, Mutable b) => Mutable (a -> b) Source #
mutants not =
  [ not
  , \p -> case p of False -> False; _ -> not p
  , \p -> case p of True  -> True;  _ -> not p
  , \p -> case p of False -> False; True -> True
  ]

Methods

mutiers :: (a -> b) -> [[a -> b]] Source #

mutants :: (a -> b) -> [a -> b] Source #

(Mutable a, Mutable b) => Mutable (a, b) Source #
mutants (0,1) = [(0,1),(0,0),(1,1),(0,-1),...]

Methods

mutiers :: (a, b) -> [[(a, b)]] Source #

mutants :: (a, b) -> [(a, b)] Source #

(Mutable a, Mutable b, Mutable c) => Mutable (a, b, c) Source # 

Methods

mutiers :: (a, b, c) -> [[(a, b, c)]] Source #

mutants :: (a, b, c) -> [(a, b, c)] Source #

(Mutable a, Mutable b, Mutable c, Mutable d) => Mutable (a, b, c, d) Source # 

Methods

mutiers :: (a, b, c, d) -> [[(a, b, c, d)]] Source #

mutants :: (a, b, c, d) -> [(a, b, c, d)] Source #

(Mutable a, Mutable b, Mutable c, Mutable d, Mutable e) => Mutable (a, b, c, d, e) Source # 

Methods

mutiers :: (a, b, c, d, e) -> [[(a, b, c, d, e)]] Source #

mutants :: (a, b, c, d, e) -> [(a, b, c, d, e)] Source #

(Mutable a, Mutable b, Mutable c, Mutable d, Mutable e, Mutable f) => Mutable (a, b, c, d, e, f) Source #

For Mutable tuple instances greater than sixtuples, see Tuples. Despite being hidden in this Haddock documentation, 7-tuples up to 12-tuples are exported by FitSpec.

Methods

mutiers :: (a, b, c, d, e, f) -> [[(a, b, c, d, e, f)]] Source #

mutants :: (a, b, c, d, e, f) -> [(a, b, c, d, e, f)] Source #

mutiersEq :: (Listable a, Eq a) => a -> [[a]] Source #

Implementation of mutiers for non-functional data types. Use this to create instances for user-defined data types, e.g.:

instance MyData
  where mutiers = mutiersEq

and for parametric datatypes:

instance (Eq a, Eq b) => MyDt a b
  where mutiers = mutiersEq

Examples:

mutiersEq True = [[True], [False]]
mutiersEq 2   = [[2], [0], [1], [], [3], [4], [5], [6], [7], [8], [9], ...]
mutiersEq [1] = [[[1]], [[]], [[0]], [[0,0]], [[0,0,0],[0,1],[1,0],[-1]], ...]