Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write code as tests #11

Open
rouson opened this issue Jun 28, 2021 · 0 comments
Open

Write code as tests #11

rouson opened this issue Jun 28, 2021 · 0 comments

Comments

@rouson
Copy link

rouson commented Jun 28, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant