Makefile simply fortran3/10/2023 Passed 7 of 8 possible asserts comprising 2 of 3 tests.įUnit tells us which test failed ( area_varies_with_radius), whichĪssertion failed ( Assert_Equal_Within), and which line the offendingįinally, although fUnit creates several temporary files To see what happens when a testįails, suppose we change the tolerance in the assert_equal_withinĪssertion from 1e-3 to 1e-6: % funit circle_class Note that we have used different approximations for π in the module and Passed 8 of 8 possible asserts comprising 3 of 3 tests. Gfortran -o TestRunner circle_class.o circle_class_fun.o TestRunner.o Locating associated source files and sorting for compilation Runing these tests is just a matter of running funit with the moduleĮxpanding test suite: circle_class.done. Now, we will write a simple unit test fileĬircle_class.fun which illustrates all sixĪssertions as well as the setup and teardown routines: test_suite circle_class ! Global variables can be declared here real, parameter :: radius = 1.5d0 real, parameter :: pi = 3.14159d0 type ( circle ) :: c setup ! Place code here that should run before each test c = circle ( radius ) end setup teardown ! This code runs immediately after each test end teardown ! Example test using all six assertions test funit_assertions integer, dimension ( 2 ) :: a = (/ 1, 2 /) integer, dimension ( 2 ) :: b = (/ 1, 2 /) assert_array_equal ( a, b ) assert_real_equal ( 0.9999999e0, 1.0e0 ) assert_equal_within ( 1e-7, 0.0, 1e-6 ) assert_equal ( 1, 5 - 4 ) assert_false ( 5 < 4 ) assert_true ( 4 = 4 ) end test test radius_is_stored_properly assert_real_equal ( radius, 1.5d0 ) end test test area_varies_with_radius real :: area area = circle_area ( c ) assert_equal_within ( area, pi *( radius ** 2 ), 1e-3 ) end test end test_suite Testing the Example Here is circle_class.f90: module circle_class implicit none private public :: circle, circle_area real :: pi = 4.d0 * atan ( 1.d0 ) type circle real :: radius end type circle contains function circle_area ( this ) result ( area ) type ( circle ), intent ( in ) :: this real :: area area = pi * this % radius ** 2 end function circle_area end module circle_class An Example Test Suite Both files must reside in the same directory. The class will be stored in circle_class.f90 and the unit tests inĬircle_class.fun. Tests may make six types of assertions:Īs an example, we will write a simple module called circle_class. Each unit test file can contain multiple testsĪs well as setup and teardown commands that are executed once forĮach test. Tests are simple Fortran fragments stored in a. Variable set to your Fortran compiler: export FC="gfortran" If you have rubygems installed, simply running sudo gem install funit fUnit is written in RubyĪnd is distributed as a Ruby Gem at RubyForge. It requires a Fortran 95 compiler and it is designedįor testing routines contained in modules. FUnit is a Fortran unit testing framework developed by engineersĪt NASA.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |