-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support vector-valued test functions
- Loading branch information
Showing
8 changed files
with
168 additions
and
11 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module sourcery_vector_test_description_m | ||
!! Define an abstraction for describing test intentions and array-valued test functions | ||
use sourcery_string_m, only : string_t | ||
use sourcery_test_result_m, only : test_result_t | ||
use assert_m, only : assert | ||
implicit none | ||
|
||
private | ||
public :: vector_test_description_t | ||
public :: vector_function_strategy_t | ||
|
||
abstract interface | ||
function vector_function_i() result(passes) | ||
implicit none | ||
logical, allocatable :: passes(:) | ||
end function | ||
end interface | ||
|
||
type, abstract :: vector_function_strategy_t | ||
contains | ||
procedure(vector_function_i), deferred, nopass :: vector_function | ||
end type | ||
|
||
type vector_test_description_t | ||
!! Encapsulate test descriptions and vector-valued test functions | ||
private | ||
type(string_t), allocatable :: description_vector_(:) | ||
class(vector_function_strategy_t), allocatable :: vector_function_strategy_ | ||
contains | ||
procedure run | ||
procedure contains_text | ||
end type | ||
|
||
interface vector_test_description_t | ||
|
||
module function construct(description_vector, vector_function_strategy) result(vector_test_description) | ||
!! The result is a vector_test_description_t object with the components defined by the dummy arguments | ||
implicit none | ||
type(string_t), intent(in) :: description_vector(:) | ||
class(vector_function_strategy_t), intent(in) :: vector_function_strategy | ||
type(vector_test_description_t) vector_test_description | ||
end function | ||
|
||
end interface | ||
|
||
interface | ||
|
||
impure module function run(self) result(test_results) | ||
!! The result encapsulates the test description and test outcome | ||
implicit none | ||
class(vector_test_description_t), intent(in) :: self | ||
type(test_result_t), allocatable :: test_results(:) | ||
end function | ||
|
||
module function contains_text(self, substring) result(match_vector) | ||
!! The result is .true. if the test description includes the value of substring | ||
implicit none | ||
class(vector_test_description_t), intent(in) :: self | ||
character(len=*), intent(in) :: substring | ||
logical, allocatable :: match_vector(:) | ||
end function | ||
|
||
end interface | ||
|
||
contains | ||
|
||
module procedure contains_text | ||
integer i | ||
associate(num_descriptions => size(self%description_vector_)) | ||
allocate(match_vector(num_descriptions)) | ||
do i = 1, num_descriptions | ||
match_vector(i) = index(self%description_vector_(i)%string(), substring ) /= 0 | ||
end do | ||
end associate | ||
end procedure | ||
|
||
module procedure construct | ||
vector_test_description%description_vector_ = description_vector | ||
vector_test_description%vector_function_strategy_ = vector_function_strategy | ||
end procedure | ||
|
||
module procedure run | ||
associate(vector_result => self%vector_function_strategy_%vector_function()) | ||
call assert(size(self%description_vector_)==size(vector_result), "sourcery_vector_test_description_s: size match") | ||
test_results = test_result_t(self%description_vector_, vector_result) | ||
end associate | ||
end procedure | ||
|
||
end module sourcery_vector_test_description_m |
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
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,55 @@ | ||
module vector_test_description_test_m | ||
!! Verify vector_test_description_t object behavior | ||
use sourcery_m, only : & | ||
string_t, test_result_t, vector_test_description_t, test_t, test_description_substring, vector_function_strategy_t | ||
implicit none | ||
|
||
private | ||
public :: vector_test_description_test_t | ||
|
||
type, extends(test_t) :: vector_test_description_test_t | ||
contains | ||
procedure, nopass :: subject | ||
procedure, nopass :: results | ||
end type | ||
|
||
type, extends(vector_function_strategy_t) :: two_vector_tautology_t | ||
contains | ||
procedure, nopass :: vector_function | ||
end type | ||
|
||
contains | ||
|
||
pure function subject() result(specimen) | ||
character(len=:), allocatable :: specimen | ||
specimen = "The vector_test_description_t type" | ||
end function | ||
|
||
function vector_function() result(passed) | ||
logical, allocatable :: passed(:) | ||
passed = [.true., .true.] | ||
end function | ||
|
||
function results() result(test_results) | ||
type(test_result_t), allocatable :: test_results(:) | ||
type(two_vector_tautology_t) two_vector_tautology | ||
|
||
associate( & | ||
vector_test_description => vector_test_description_t([string_t("construction"),string_t("assignment")], two_vector_tautology)& | ||
) | ||
associate(substring_in_subject => index(subject(), test_description_substring) /= 0) | ||
associate(substring_in_description => vector_test_description%contains_text(test_description_substring)) | ||
if (substring_in_subject) then | ||
test_results = vector_test_description%run() | ||
else if (any(substring_in_description)) then | ||
test_results = vector_test_description%run() | ||
test_results = pack(test_results, test_results%description_contains(string_t(test_description_substring))) | ||
else | ||
test_results = [test_result_t::] | ||
end if | ||
end associate | ||
end associate | ||
end associate | ||
end function | ||
|
||
end module vector_test_description_test_m |