|
| 1 | +module sourcery_vector_test_description_m |
| 2 | + !! Define an abstraction for describing test intentions and array-valued test functions |
| 3 | + use sourcery_string_m, only : string_t |
| 4 | + use sourcery_test_result_m, only : test_result_t |
| 5 | + use assert_m, only : assert |
| 6 | + implicit none |
| 7 | + |
| 8 | + private |
| 9 | + public :: vector_test_description_t |
| 10 | + public :: vector_function_strategy_t |
| 11 | + |
| 12 | + abstract interface |
| 13 | + function vector_function_i() result(passes) |
| 14 | + implicit none |
| 15 | + logical, allocatable :: passes(:) |
| 16 | + end function |
| 17 | + end interface |
| 18 | + |
| 19 | + type, abstract :: vector_function_strategy_t |
| 20 | + contains |
| 21 | + procedure(vector_function_i), deferred, nopass :: vector_function |
| 22 | + end type |
| 23 | + |
| 24 | + type vector_test_description_t |
| 25 | + !! Encapsulate test descriptions and vector-valued test functions |
| 26 | + private |
| 27 | + type(string_t), allocatable :: description_vector_(:) |
| 28 | + class(vector_function_strategy_t), allocatable :: vector_function_strategy_ |
| 29 | + contains |
| 30 | + procedure run |
| 31 | + procedure contains_text |
| 32 | + end type |
| 33 | + |
| 34 | + interface vector_test_description_t |
| 35 | + |
| 36 | + module function construct(description_vector, vector_function_strategy) result(vector_test_description) |
| 37 | + !! The result is a vector_test_description_t object with the components defined by the dummy arguments |
| 38 | + implicit none |
| 39 | + type(string_t), intent(in) :: description_vector(:) |
| 40 | + class(vector_function_strategy_t), intent(in) :: vector_function_strategy |
| 41 | + type(vector_test_description_t) vector_test_description |
| 42 | + end function |
| 43 | + |
| 44 | + end interface |
| 45 | + |
| 46 | + interface |
| 47 | + |
| 48 | + impure module function run(self) result(test_results) |
| 49 | + !! The result encapsulates the test description and test outcome |
| 50 | + implicit none |
| 51 | + class(vector_test_description_t), intent(in) :: self |
| 52 | + type(test_result_t), allocatable :: test_results(:) |
| 53 | + end function |
| 54 | + |
| 55 | + module function contains_text(self, substring) result(match_vector) |
| 56 | + !! The result is .true. if the test description includes the value of substring |
| 57 | + implicit none |
| 58 | + class(vector_test_description_t), intent(in) :: self |
| 59 | + character(len=*), intent(in) :: substring |
| 60 | + logical, allocatable :: match_vector(:) |
| 61 | + end function |
| 62 | + |
| 63 | + end interface |
| 64 | + |
| 65 | +contains |
| 66 | + |
| 67 | + module procedure contains_text |
| 68 | + integer i |
| 69 | + associate(num_descriptions => size(self%description_vector_)) |
| 70 | + allocate(match_vector(num_descriptions)) |
| 71 | + do i = 1, num_descriptions |
| 72 | + match_vector(i) = index(self%description_vector_(i)%string(), substring ) /= 0 |
| 73 | + end do |
| 74 | + end associate |
| 75 | + end procedure |
| 76 | + |
| 77 | + module procedure construct |
| 78 | + vector_test_description%description_vector_ = description_vector |
| 79 | + vector_test_description%vector_function_strategy_ = vector_function_strategy |
| 80 | + end procedure |
| 81 | + |
| 82 | + module procedure run |
| 83 | + associate(vector_result => self%vector_function_strategy_%vector_function()) |
| 84 | + call assert(size(self%description_vector_)==size(vector_result), "sourcery_vector_test_description_s: size match") |
| 85 | + test_results = test_result_t(self%description_vector_, vector_result) |
| 86 | + end associate |
| 87 | + end procedure |
| 88 | + |
| 89 | +end module sourcery_vector_test_description_m |
0 commit comments