Skip to content

Feature: support comparison expressions that evaluate to test diagnoses#55

Merged
rouson merged 16 commits into
mainfrom
test-diagnosis-expressions
May 5, 2025
Merged

Feature: support comparison expressions that evaluate to test diagnoses#55
rouson merged 16 commits into
mainfrom
test-diagnosis-expressions

Conversation

@rouson
Copy link
Copy Markdown
Contributor

@rouson rouson commented Apr 27, 2025

This pull request adds user-defined operators and corresponding unit tests. The primary benefit of using these operators is that they eliminate some of the tedium of forming one's own diagnostics_string arguments when invoking test_diagnosis_t constructors.

For real or double precision values x, y, and tolerance and for integer values i and j, expressions of the following forms now evaluate to test_diagnosis_t objects constructed with descriptive diagnostic_string arguments tailored to the operators involved in the expressions:

x .approximates. y .within. tolerance
x .lessThan. y
x .greaterThan. y

i .equalsExpected. j
i .lessThan. j
i .greaterThan. j
i .lessThanOrEqualTo. j
i .greaterThanOrEqualTo. j

where all of the above operators are elemental and accept conformable arguments, i.e., same-shaped array operands or array/scalar operand combinations.

When the operands are arrays, the expressions evaluate to test_diagnosis_t arrays, which could be used as the result of a vector test function satisfying Julienne's vector_diagnosis_function_i abstract interface. Alternatively, array results can be aggregated into one test_diagnosis_t object using the .all. operator that this pull request also provides. For example,

.all. ([i,j] .lessThan. k)   ! test passes if i < k .and. j < k
.all. (i .greaterThan. [j,k]) ! test passes if i > j .and. i > k 
.all. ([i,j] .equalsExpected. [m,n]) ! test passes if i == m .and. j == n

where expressions operated on by .all. will result in diagnostic strings displaying only for the elements corresponding to test failures. See test/test_diagnosis_test_m.F90 for examples of the use of the above operators.

Equivalently, if pairwise aggregation suffices, then the user-defined .and. operator in this PR can be used as follows:

(2 .greaterThanOrEqualTo. expected_min) .and. (1 .equalsExpected. 1)

which is currently implemented using .all. with a size-2 array:

.all. ([lhs,rhs])

where lhs = 2 .greaterThanOrEqualTo. expected_min and rhs = 1 .equalsExpected. 1.

To Do

  • In the expression x .approximates. y .within. tolerance, switch the internal logic from using < tolerance to using <= tolerance in order to handle the (not necessarily recommended) case of tolerance==0..

rouson added 3 commits April 27, 2025 16:26
This commit adds user-defined operators and corresponding unit
tests.  The operators that support statements of the form

  type(test_diagnosis_t) test_diagnosis
  test_diagnosis = x .approximates. y .within. tolerance

for real and double-precsision operands x, y, and tolerance and

  test_diagnosis = i .equalsExpected. j

for integer operand i and j. The right-hand side expressions above
evaluate to test_diagnostics_t objects with diagnostics_string_
components formed with the assumption that x and i are actual
computed values y and j corresponding expected values, respectively.
@rouson rouson requested a review from ktras April 28, 2025 05:14
@rouson rouson changed the title feat(test_diagnosis): add comparison operators Feature: support comparison expressions that evaluate to test diagnoses Apr 28, 2025
rouson added 9 commits April 28, 2025 13:53
This commit adds support and corresponding unit tests for constructing
a test_diagnosis_t object from real, double precision, and integer
expressions of the above form.
This commit adds support and corresponding unit tests for constructing
a test_diagnosis_t object from integer expressions of the forms

i .lessThanOrEqualTo. j
i .greaterThanOrEqualTo. j
This commit adds support and corresponding unit tests for constructing
a test_diagnosis_t object from real expressions of the forms

  .all. ([0,3] .lessThanOrEqualTo. 1)
  .all. ([1,2] .greaterThanOrEqualTo. 0)

where diagnostic information is printed only for specific cases that fail
such as in the case of the element equal to 3 above.
This sets up the test suite to skip th test .greaterThanOrEqualTo. and
.lessThanOrEqualTo. tests with gfortran because they crash.
This commit adds support and a corresponding unit test for
constructing a test_diagnosis_t object from a test_diagnosis_t
expression of the form

  (0 .lessThanOrEqualTo. 1) .and. (2 .equalsExpected. 2)

where the two .and. operands are test_diagnosis_t objects, which in
the above case happen to be the result expression evaluations.
Copy link
Copy Markdown
Member

@bonachea bonachea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not reviewed the implementation, but based on the examples in the PR description these look like great improvements!

Where is the corresponding in-repo documentation?
Is test/test_diagnosis_test_m.F90 intended to be a client-facing example that should be linked from the README?

rouson and others added 4 commits April 30, 2025 22:02
This commit adds support and a corresponding unit test for
constructing a test_diagnosis_t object from expressions that
evaluate to vector test_diagnosis_t objects:

  .all. ((2 .equalsExpected. [2,2,2]) .and. ([0,1,2] .equalsExpected. [0,1,2]))

where the two .and. operands are one-dimensional test_diagnosis_t arrays.
Copy link
Copy Markdown
Collaborator

@ktras ktras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Ready to merge after my brief commits on this branch are looked at.

Copy link
Copy Markdown
Contributor Author

@rouson rouson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor Author

@rouson rouson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rouson
Copy link
Copy Markdown
Contributor Author

rouson commented May 5, 2025

@ktras thanks for the review! I reviewed and approved your commits and will merge now.

@rouson rouson merged commit 45d2881 into main May 5, 2025
8 checks passed
@rouson rouson deleted the test-diagnosis-expressions branch May 5, 2025 20:49
rouson added a commit that referenced this pull request May 6, 2025
rouson added a commit that referenced this pull request May 8, 2025
fix(test_diagnosis): finish To Do item from PR #55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants