Skip to content

Write code as tests #11

Open
Open
@rouson

Description

@rouson

It would be a really big time-saver for someone encountering these codes for the first time if every code is written as a test that reports success or failure so that a newcomer doesn't have to digest the entire algorithm and then read verbose output to determine whether a particular run succeeded or failed. End each program with something along the lines of

  block 
    logical, parameter :: testing=.true. 
    if (testing) call verify(calculation_result) ! error terminate if the calculation failed
    print *, "Poisson test passed."
  end block

where making testing a compile-time constant allows an optimizing compiler to completely eliminate the verification code during a dead-code removal phase when you want to do runs to measure performance. You could use a preprocessor macro to switch the value to false when so desired.

Even better would be to adopt a unit-testing framework that automates the execution of all the tests. I recommend Vegetables.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions