chp-1.4.0: An implementation of concurrency ideas from Communicating Sequential ProcessesSource codeContentsIndex
Control.Concurrent.CHP.Test
Description

A module containing some useful functions for testing CHP programs, both in the QuickCheck 2 framework and using HUnit.

This whole module was added in version 1.4.0.

Synopsis
propCHP :: CHP Bool -> Property
propCHPInOut :: Show a => (a -> b -> Bool) -> (Chanin a -> Chanout b -> CHP ()) -> Gen a -> Property
testCHP :: CHP Bool -> Test
testCHPInOut :: (a -> b -> Bool) -> (Chanin a -> Chanout b -> CHP ()) -> a -> Test
Documentation
propCHP :: CHP Bool -> PropertySource

Takes a CHP program that returns a Bool (True = test passed, False = test failed) and forms it into a Property that QuickCheck can test.

Note that if the program exits with poison, this is counted as a test failure.

propCHPInOut :: Show a => (a -> b -> Bool) -> (Chanin a -> Chanout b -> CHP ()) -> Gen a -> PropertySource

Tests a process that takes a single input and produces a single output, using QuickCheck.

The first parameter is a pure function that takes the input to the process, the output the process gave back, and indicates whether this is okay (True = test pass, False = test fail). The second parameter is the process to test, and the third parameter is the thing to use to generate the inputs (passing arbitrary is the simplest thing to do).

Here are a couple of example uses:

 propCHPInOut (==) Common.id (arbitrary :: Gen Int)
 propCHPInOut (const $ (< 0)) (Common.map (negate . abs)) (arbitrary :: Gen Int)

The test starts the process afresh each time, and shuts it down after the single output has been produced (by poisoning both its channels). Any poison from the process being tested after it has produced its output is consequently ignored, but poison instead of producing an output will cause a test failure. If the process does not produce an output or poison (for example if you test something like the Common.filter process), the test will deadlock.

testCHP :: CHP Bool -> TestSource

Takes a CHP program that returns a Bool (True = test passed, False = test failed) and forms it into an HUnit test.

Note that if the program exits with poison, this is counted as a test failure.

testCHPInOut :: (a -> b -> Bool) -> (Chanin a -> Chanout b -> CHP ()) -> a -> TestSource

Tests a process that takes a single input and produces a single output, using HUnit.

The first parameter is a pure function that takes the input to the process, the output the process gave back, and indicates whether this is okay (True = test pass, False = test fail). The second parameter is the process to test, and the third parameter is the input to send to the process.

The intention is that you will either create several tests with the same first two parameters or use a const function as the first parameter. So for example, here is how you might test the identity process with several tests:

 let check = testCHPInOut (==) Common.id
 in TestList [check 0, check 3, check undefined]

Whereas here is how you could test a slightly different process:

 let check = testCHPInOut (const $ (< 0)) (Common.map (negate . abs))
 in TestList $ map check [-5..5]

The test starts the process afresh each time, and shuts it down after the single output has been produced (by poisoning both its channels). Any poison from the process being tested after it has produced its output is consequently ignored, but poison instead of producing an output will cause a test failure. If the process does not produce an output or poison (for example if you test something like the Common.filter process), the test will deadlock.

Produced by Haddock version 2.4.2