|
| 1 | +! |
| 2 | +! (c) 2019-2020 Guide Star Engineering, LLC |
| 3 | +! This Software was developed for the US Nuclear Regulatory Commission (US NRC) under contract |
| 4 | +! "Multi-Dimensional Physics Implementation into Fuel Analysis under Steady-state and Transients (FAST)", |
| 5 | +! contract # NRC-HQ-60-17-C-0007 |
| 6 | +! |
| 7 | +module single_image_intrinsics_test |
| 8 | + use Vegetables, only: Result_t, Test_Item_t, describe, it, assert_equals |
| 9 | + use emulated_intrinsics_interface, only : findloc |
| 10 | + |
| 11 | + implicit none |
| 12 | + private |
| 13 | + public :: test_findloc |
| 14 | + |
| 15 | +contains |
| 16 | + |
| 17 | + function test_findloc() result(tests) |
| 18 | + type(Test_Item_t) :: tests |
| 19 | + |
| 20 | + tests = describe( & |
| 21 | + "findloc", & |
| 22 | + [it( & |
| 23 | + "handles zero-sized argument", & |
| 24 | + check_zero_sized_argument), & |
| 25 | + it( & |
| 26 | + "handles absent back argument", & |
| 27 | + check_absent_back), & |
| 28 | + it( & |
| 29 | + "handles .false. back argument", & |
| 30 | + check_false_back), & |
| 31 | + it( & |
| 32 | + "handles .true. back argument", & |
| 33 | + check_true_back), & |
| 34 | + it( & |
| 35 | + "handles absent back argument", & |
| 36 | + check_logical_argument), & |
| 37 | + it( & |
| 38 | + "handles character array argument", & |
| 39 | + check_character_array), & |
| 40 | + it( & |
| 41 | + "handles empty character array argument", & |
| 42 | + check_empty_character_array), & |
| 43 | + it( & |
| 44 | + "handles failed search", & |
| 45 | + check_nonexistent_character_value)]) |
| 46 | + end function |
| 47 | + |
| 48 | + function check_zero_sized_argument() result(result_) |
| 49 | + type(Result_t) :: result_ |
| 50 | + integer, parameter :: zero_sized_array(*) = [ integer :: ] |
| 51 | + result_ = assert_equals(0, findloc(zero_sized_array, value=99, dim=1, back=.true.), "findloc handles zero-sized array") |
| 52 | + end function |
| 53 | + |
| 54 | + function check_absent_back() result(result_) |
| 55 | + type(Result_t) :: result_ |
| 56 | + result_ = assert_equals(3, findloc([1,2,3,4], value=3, dim=1), "findloc handles absent 'back' argument") |
| 57 | + end function |
| 58 | + |
| 59 | + function check_false_back() result(result_) |
| 60 | + type(Result_t) :: result_ |
| 61 | + result_ = assert_equals(2, findloc([1,2,3,4], value=2, dim=1, back=.false.), "findloc handles .false. 'back' argument") |
| 62 | + end function |
| 63 | + |
| 64 | + function check_true_back() result(result_) |
| 65 | + type(Result_t) :: result_ |
| 66 | + result_ = assert_equals(1, findloc([1,2,3,4], value=1, dim=1, back=.true.), "findloc handles .true. 'back' argument") |
| 67 | + end function |
| 68 | + |
| 69 | + function check_logical_argument() result(result_) |
| 70 | + type(Result_t) :: result_ |
| 71 | + logical, parameter :: first_true(*) = [.true., .false., .false.] |
| 72 | + result_ = assert_equals(1, findloc(first_true, value=.true., dim=1, back=.true.), "findloc handles logical argument") |
| 73 | + end function |
| 74 | + |
| 75 | + function check_character_array() result(result_) |
| 76 | + type(Result_t) :: result_ |
| 77 | + character(len=*), parameter, dimension(*) :: rgb = ["roy", "gee", "biv"] |
| 78 | + result_ = assert_equals(2, findloc(rgb, value="gee", dim=1), "findloc finds string location") |
| 79 | + end function |
| 80 | + |
| 81 | + function check_empty_character_array() result(result_) |
| 82 | + type(Result_t) :: result_ |
| 83 | + character(len=*), parameter, dimension(*) :: empty = [character(len=len("hello"))::] |
| 84 | + result_ = & |
| 85 | + assert_equals(0, findloc(empty, value="hello", dim=1, back=.false.), "findloc handles empty character array from front") |
| 86 | + end function |
| 87 | + |
| 88 | + function check_nonexistent_character_value() result(result_) |
| 89 | + type(Result_t) :: result_ |
| 90 | + character(len=*), parameter, dimension(*) :: unsuccessful = ["foo", "bar", "too"] |
| 91 | + result_ = assert_equals(0, & |
| 92 | + findloc(unsuccessful, value="foobar", dim=1, back=.false.), "findloc handles character array without search target") |
| 93 | + end function |
| 94 | + |
| 95 | +end module |
| 96 | + |
0 commit comments