|
| 1 | +module TestInputOutput |
| 2 | + use testdrive, only: error_type, unittest_type, new_unittest, check |
| 3 | + use ConstantsModule, only: LINELENGTH |
| 4 | + use InputOutputModule, only: get_node, get_ijk |
| 5 | + implicit none |
| 6 | + private |
| 7 | + public :: collect_inputoutput |
| 8 | + |
| 9 | +contains |
| 10 | + |
| 11 | + subroutine collect_inputoutput(testsuite) |
| 12 | + type(unittest_type), allocatable, intent(out) :: testsuite(:) |
| 13 | + testsuite = [ & |
| 14 | + new_unittest("get_node_get_ijk", test_get_node_get_ijk) & |
| 15 | + ] |
| 16 | + end subroutine collect_inputoutput |
| 17 | + |
| 18 | + subroutine test_get_node_get_ijk(error) |
| 19 | + type(error_type), allocatable, intent(out) :: error |
| 20 | + integer :: ilay |
| 21 | + integer :: irow |
| 22 | + integer :: icol |
| 23 | + integer :: nlay |
| 24 | + integer :: nrow |
| 25 | + integer :: ncol |
| 26 | + integer :: nnum |
| 27 | + integer :: ncls |
| 28 | + integer :: k, i, j |
| 29 | + |
| 30 | + ! trivial grid with 1 cell |
| 31 | + nnum = get_node(1, 1, 1, 1, 1, 1) |
| 32 | + call get_ijk(nnum, 1, 1, 1, ilay, irow, icol) |
| 33 | + call check(error, nnum == 1) |
| 34 | + call check(error, ilay == 1) |
| 35 | + call check(error, irow == 1) |
| 36 | + call check(error, icol == 1) |
| 37 | + if (allocated(error)) return |
| 38 | + |
| 39 | + ! small grid, 3x4x5 |
| 40 | + nlay = 3 |
| 41 | + nrow = 4 |
| 42 | + ncol = 5 |
| 43 | + ncls = nlay * nrow * ncol |
| 44 | + do k = 1, nlay |
| 45 | + do i = 1, nrow |
| 46 | + do j = 1, ncol |
| 47 | + ! node number from ijk |
| 48 | + nnum = get_node(k, i, j, nlay, nrow, ncol) |
| 49 | + call check(error, nnum == (k - 1) * nrow * ncol + (i - 1) * ncol + j) |
| 50 | + if (allocated(error)) return |
| 51 | + |
| 52 | + ! ijk from node number |
| 53 | + call get_ijk(nnum, nrow, ncol, nlay, irow, icol, ilay) |
| 54 | + call check(error, ilay == k) |
| 55 | + call check(error, irow == i) |
| 56 | + call check(error, icol == j) |
| 57 | + if (allocated(error)) return |
| 58 | + end do |
| 59 | + end do |
| 60 | + end do |
| 61 | + end subroutine test_get_node_get_ijk |
| 62 | + |
| 63 | +end module TestInputOutput |
0 commit comments