Home Objexx Engineering

ObjexxFTK: Objexx Fortran ToolKit

The ObjexxFTK is a set of Fortran packages that provides support for modern development methodologies with Fortran and that extends some Fortran 95 services.

The ObjexxFTK includes:

UnitTest A unit testing framework
Assert An assertion system
ArrayTools Array utility predicates and functions
StringTools Useful string functions

UnitTest

UnitTest provides a very easy to use unit testing framework for Fortran. Unit tests are subroutines flagged with a !UnitTest comment and containing calls of the form:

CHECK( condition )

where condition is any boolean-valued (LOGICAL) expression. Support for typical condition testing is provided, including functions that compare floating point values within a specified tolerance and the array tests provided by the ArrayTools package.

A Python script automatically collects all the tests in your source subtree into a test so you only have to add a test to have it included in the unit test suite.

A simple example is shown in the sidebar.

Assert

The Assert package provides assertion support for live in-source tests of conditions that are expected to hold unless a programming error is present. Assertion tests are removed from release builds to eliminate any performance impact.

An Assert example is shown in the sidebar.

ArrayTools

The ArrayTools package is a collection of simple macro functions that supplement Fortran 95 whole array support with useful operations such as testing whether two arrays are conformable or have equal shapes or equal index ranges or have equal values as well as equal shapes or ranges. These functions are particularly useful with UnitTest and Assert.

StringTools

The StringTools package provides useful string functions such as searching, lower and upper casing, and left and right justifying.

Licensing

The ObjexxFTK is available for a modest licensing fee and is provided in source form with a perpetual, royalty-free license that allows client modification.

Contact Objexx for current ObjexxFTK pricing information.

 

 

UnitTest Example

A simple routine with some intentionally failing tests:

SUBROUTINE Simple() !UnitTest
   USE UnitTest
   IMPLICIT NONE
   REAL(4) :: a = 5.0, b = 6.0, c = 6.001
   CHECK( a < b )
   CHECK( b < a )
   CHECK( a == a )
   CHECK( a == b )
   CHECK( b == a )
   CHECK( EQ_TOL( b, c, .001 ) ) ! Relative tolerance only
   CHECK( EQ_TOL( b, b, a=.001 ) ) ! Absolute tolerance only
   CHECK( EQ_TOL( b, c, .0001, 1.0 ) )
END SUBROUTINE

Running the test gives:

CHECK( b < a ) failed in Simple.test.f90 at line      11
CHECK( a == b ) failed in Simple.test.f90 at line      13
CHECK( b == a ) failed in Simple.test.f90 at line      14
CHECK( EQ_TOL( b, c, .0001, 1.0 ) ) failed in Simple.test.f90 at line      17

         9  Tests Total
         5  Tests Passed
         4  Tests Failed

 

Assert Example

#include "Assert.fh"

SUBROUTINE SORTED_SEARCH( a )
   REAL, INTENT(IN) :: a(:)
   ASSERT( IS_SORTED( a ) ) ! Precondition: Array is sorted
   ! ...
END