S E S P

FUnit - An example

The Software
Engineering Group

Computational Science & Engineering
CLRC Rutherford Appleton Laboratory


Example

Suppose you have a module in gas_physics.f90 that contains a routine that returns viscosity as a function of temperature,

 module gas_physics
..
contains
..
function viscosity(temperature)
real :: viscosity, temperature
viscosity = 2.0e-3 * temperature**1.5
end function
..
end module

The tests of this module would be contained in gas_physics.fun, and might contain a test like,

 ..
beginTest viscosity_varies_as_temperature
IsRealEqual( 0.0, viscosity(0.0) )
IsEqualWithin( 0.7071, viscosity(50.0), 1e-3 )
endTest
..

This brief fragment is all you need, the framework provides the rest of the trappings to turn this into valid Fortran code.

Before running the tests you need to set the FC environment variable to specifiy your Fortran compiler. Then you would run the tests for the gas_physics module with the command,

 funit gas_physics

which would transform your fragments contained in gas_physics.fun into valid Fortran code, create a test runner program, compile everything, and run the tests. A sample output would look like,

 parsing gas_physics.fun
computing dependencies
locating associated source files and sorting for compilation
g95 -o TestRunner
gas_physics.f90 \
gas_physics_fun.f90 \
TestRunner.f90

gas_physics test suite:
Passed 2 of 2 possible asserts comprising 1 of 1 tests.

Further example Fortran code and unit testing code can be found on the SEG servers in /usr/local/ruby/fUnit-0.1.2/examples/.




SESP Homepage

SEG Homepage