-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add minimal unit tests for some utilities
- Loading branch information
Showing
5 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module TestDevFeature | ||
use testdrive, only: error_type, unittest_type, new_unittest, check | ||
use DevFeatureModule, only: dev_feature | ||
use ConstantsModule, only: LINELENGTH | ||
use VersionModule, only: IDEVELOPMODE | ||
|
||
implicit none | ||
private | ||
public :: collect_dev_feature | ||
|
||
contains | ||
|
||
subroutine collect_dev_feature(testsuite) | ||
type(unittest_type), allocatable, intent(out) :: testsuite(:) | ||
testsuite = [ & | ||
! expect failure if in release mode, otherwise pass | ||
new_unittest("dev_feature", test_dev_feature, & | ||
should_fail=(IDEVELOPMODE == 0)) & | ||
] | ||
end subroutine collect_dev_feature | ||
|
||
subroutine test_dev_feature(error) | ||
type(error_type), allocatable, intent(out) :: error | ||
character(len=LINELENGTH) :: errmsg | ||
call dev_feature(errmsg) | ||
end subroutine test_dev_feature | ||
|
||
end module TestDevFeature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module TestInputOutput | ||
use testdrive, only: error_type, unittest_type, new_unittest, check | ||
use ConstantsModule, only: LINELENGTH | ||
use InputOutputModule, only: get_node, get_ijk | ||
implicit none | ||
private | ||
public :: collect_inputoutput | ||
|
||
contains | ||
|
||
subroutine collect_inputoutput(testsuite) | ||
type(unittest_type), allocatable, intent(out) :: testsuite(:) | ||
testsuite = [ & | ||
new_unittest("get_node_get_ijk", test_get_node_get_ijk) & | ||
] | ||
end subroutine collect_inputoutput | ||
|
||
subroutine test_get_node_get_ijk(error) | ||
type(error_type), allocatable, intent(out) :: error | ||
integer :: ilay | ||
integer :: irow | ||
integer :: icol | ||
integer :: nlay | ||
integer :: nrow | ||
integer :: ncol | ||
integer :: nnum | ||
integer :: ncls | ||
integer :: k, i, j | ||
|
||
! trivial grid with 1 cell | ||
nnum = get_node(1, 1, 1, 1, 1, 1) | ||
call get_ijk(nnum, 1, 1, 1, ilay, irow, icol) | ||
call check(error, nnum == 1) | ||
call check(error, ilay == 1) | ||
call check(error, irow == 1) | ||
call check(error, icol == 1) | ||
if (allocated(error)) return | ||
|
||
! small grid, 3x4x5 | ||
nlay = 3 | ||
nrow = 4 | ||
ncol = 5 | ||
ncls = nlay * nrow * ncol | ||
do k = 1, nlay | ||
do i = 1, nrow | ||
do j = 1, ncol | ||
! node number from ijk | ||
nnum = get_node(k, i, j, nlay, nrow, ncol) | ||
call check(error, nnum == (k - 1) * nrow * ncol + (i - 1) * ncol + j) | ||
if (allocated(error)) return | ||
|
||
! ijk from node number | ||
call get_ijk(nnum, nrow, ncol, nlay, irow, icol, ilay) | ||
call check(error, ilay == k) | ||
call check(error, irow == i) | ||
call check(error, icol == j) | ||
if (allocated(error)) return | ||
end do | ||
end do | ||
end do | ||
end subroutine test_get_node_get_ijk | ||
|
||
end module TestInputOutput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module TestSim | ||
use testdrive, only: error_type, unittest_type, new_unittest, check | ||
use SimModule, only: store_error, store_warning, store_note, & | ||
initial_message, count_errors, count_notes, & | ||
count_warnings | ||
use ConstantsModule, only: LINELENGTH | ||
|
||
implicit none | ||
private | ||
public :: collect_sim | ||
|
||
contains | ||
|
||
subroutine collect_sim(testsuite) | ||
type(unittest_type), allocatable, intent(out) :: testsuite(:) | ||
testsuite = [ & | ||
new_unittest("store_and_count", test_store_and_count) & | ||
] | ||
end subroutine collect_sim | ||
|
||
subroutine test_store_and_count(error) | ||
type(error_type), allocatable, intent(out) :: error | ||
character(len=LINELENGTH) :: ntemsg | ||
character(len=LINELENGTH) :: wrnmsg | ||
character(len=LINELENGTH) :: errmsg | ||
|
||
! define messages | ||
ntemsg = "NOTE" | ||
wrnmsg = "WARNING" | ||
errmsg = "ERROR" | ||
|
||
! initialize message arrays | ||
call initial_message() | ||
|
||
! check no messages stored | ||
call check(error, count_errors() == 0) | ||
call check(error, count_warnings() == 0) | ||
call check(error, count_notes() == 0) | ||
if (allocated(error)) return | ||
|
||
! todo store a note and check that it's stored | ||
call store_note(ntemsg) | ||
call check(error, count_notes() == 1) | ||
if (allocated(error)) return | ||
|
||
! todo store a warning and check that it's stored | ||
call store_warning(wrnmsg) | ||
call check(error, count_warnings() == 1) | ||
if (allocated(error)) return | ||
|
||
! store an error and check that it's stored | ||
call store_error(errmsg, terminate=.false.) | ||
call check(error, count_errors() == 1) | ||
if (allocated(error)) return | ||
|
||
end subroutine test_store_and_count | ||
|
||
end module TestSim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters