Skip to content

Specific assertions #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Beliavsky opened this issue May 19, 2021 · 0 comments
Open

Specific assertions #412

Beliavsky opened this issue May 19, 2021 · 0 comments
Labels
topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...

Comments

@Beliavsky
Copy link

Beliavsky commented May 19, 2021

In my codes I often want to check whether

(1) variable1 == variable2 (they could be array sizes)
(2) a variable >= value (for example an array index being positive)
(3) a variable <= value (within an array bound)
(4) low <= variable <= high
(5) variable1 <= variable2

Could stdlib have specific assertion subroutines for these common cases? Probably someone has already coded them for their own use. For example for (5) I have

subroutine assert_le(n1,n2,name1,name2,procedure)
! print an error message and stop if n1 > n2
integer          , intent(in) :: n1,n2
character (len=*), intent(in) :: procedure   ! name of program unit where assertion is made
character (len=*), intent(in) :: name1,name2 ! variable names 
if (n1 > n2) then
   write (*,"(a,2(1x,a),' =',2(1x,i0),a)") "in " // trim(procedure) // ",", &
          trim(name1),trim(name2),n1,n2," need " // trim(name1) // " <= " // trim(name2) // ", STOPPING"
   error stop
end if
end subroutine assert_le

invoked with code such as

call assert_le(ntrain,n,"ntrain","n","main")

There is #72 "Implement standard assert subroutine and associated macros", but a general assert subroutine testing a condition will give a less informative message.

@awvwgk awvwgk added the topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... label Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...
Projects
None yet
Development

No branches or pull requests

2 participants