Skip to content

Commit 54051a4

Browse files
authored
Merge pull request #151 from bonachea/Dec-10-misc
Misc improvements
2 parents bd9fa9a + 632c2bd commit 54051a4

3 files changed

Lines changed: 65 additions & 5 deletions

File tree

src/julienne/julienne_test_diagnosis_m.F90

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,32 @@ pure module function aggregate_rank15_diagnosis(diagnoses) result(diagnosis)
201201

202202
interface operator(.also.)
203203

204-
elemental module function also(lhs, rhs) result(diagnosis)
204+
elemental module function also_DD(lhs, rhs) result(diagnosis)
205205
implicit none
206206
type(test_diagnosis_t), intent(in) :: lhs, rhs
207207
type(test_diagnosis_t) diagnosis
208208
end function
209209

210+
elemental module function also_DL(lhs, rhs) result(diagnosis)
211+
implicit none
212+
type(test_diagnosis_t), intent(in) :: lhs
213+
logical, intent(in) :: rhs
214+
type(test_diagnosis_t) diagnosis
215+
end function
216+
217+
elemental module function also_LD(lhs, rhs) result(diagnosis)
218+
implicit none
219+
logical, intent(in) :: lhs
220+
type(test_diagnosis_t), intent(in) :: rhs
221+
type(test_diagnosis_t) diagnosis
222+
end function
223+
210224
end interface
211225

212226
interface operator(.and.)
213-
module procedure also
227+
module procedure also_DD
228+
module procedure also_LD
229+
module procedure also_DL
214230
end interface
215231

216232
interface operator(.approximates.)
@@ -245,6 +261,12 @@ elemental module function expect(expected_true) result(test_diagnosis)
245261

246262
interface operator(.equalsExpected.)
247263

264+
elemental module function equals_expected_logical(actual, expected) result(test_diagnosis)
265+
implicit none
266+
logical, intent(in) :: actual, expected
267+
type(test_diagnosis_t) test_diagnosis
268+
end function
269+
248270
elemental module function equals_expected_c_ptr(actual, expected) result(test_diagnosis)
249271
implicit none
250272
type(c_ptr), intent(in) :: actual, expected

src/julienne/julienne_test_diagnosis_s.F90

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@
3737
end if
3838
end procedure
3939

40-
module procedure also
40+
module procedure also_DD
4141
diagnosis = .all. ([lhs,rhs])
4242
end procedure
4343

44+
module procedure also_LD
45+
diagnosis = .all. ([.expect.(lhs),rhs])
46+
end procedure
47+
48+
module procedure also_DL
49+
diagnosis = .all. ([lhs,.expect.(rhs)])
50+
end procedure
51+
4452
#ifndef __GFORTRAN__
4553

4654
module procedure aggregate_diagnosis
@@ -280,18 +288,33 @@ pure function aggregate_vector_diagnosis(diagnoses) result(diagnosis)
280288
else
281289
block
282290
integer(c_intptr_t), parameter :: mold = 0_c_intptr_t
291+
character(len=18) :: str_actual, str_expect
283292

284-
associate(actual_c_loc => transfer(actual, mold), expected_c_loc => transfer(expected, mold))
293+
associate(actual_c_loc => transfer(actual, mold), expect_c_loc => transfer(expected, mold))
294+
write(str_actual, '(A2,Z16.16)') '0x',actual_c_loc
295+
write(str_expect, '(A2,Z16.16)') '0x',expect_c_loc
285296
test_diagnosis = test_diagnosis_t( &
286297
test_passed = .false. &
287-
,diagnostics_string = "expected " // string_t(expected_c_loc) // "; actual value is " // string_t(actual_c_loc) &
298+
,diagnostics_string = "expected " // str_expect // "; actual value is " // str_actual &
288299
)
289300
end associate
290301
end block
291302
end if
292303

293304
end procedure
294305

306+
module procedure equals_expected_logical
307+
308+
if (actual .EQV. expected) then
309+
test_diagnosis = test_diagnosis_t(test_passed=.true., diagnostics_string="")
310+
else
311+
test_diagnosis = test_diagnosis_t(test_passed = .false. &
312+
,diagnostics_string = "expected " // string_t(expected) // "; actual value is " // string_t(actual) &
313+
)
314+
end if
315+
316+
end procedure
317+
295318
module procedure equals_expected_integer
296319

297320
if (actual == expected) then

test/modules/test_diagnosis_test_m.F90

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function results() result(test_results)
7171
,test_description_t("construction from string_t/character expressions 'a .equalsExpected. b'" , usher(check_equals_character_vs_string)) &
7272
,test_description_t("construction from the character expression 'a .equalsExpected. b'" , usher(check_equals_character)) &
7373
,test_description_t("construction from the type(c_ptr) expression 'p .equalsExpected. q'" , usher(check_equals_c_ptr)) &
74+
,test_description_t("construction from the logical expression 't .equalsExpected. t'" , usher(check_equals_logical)) &
7475
,test_description_t("construction from the string_t expression 'a .equalsExpected. b'" , usher(check_equals_string)) &
7576
,test_description_t("construction from the integer expression 'i .equalsExpected. j'" , usher(check_equals_integer)) &
7677
,test_description_t("construction from integer(int64) relational operators" , usher(check_int64_comparisons)) &
@@ -85,6 +86,7 @@ function results() result(test_results)
8586
,test_description_t("construction from (.expects. logical-expression) // 'user-defined message'" , usher(check_expects_logical)) &
8687
,test_description_t("construction from (.expects. logical-expression) // 'user-defined message'" , usher(check_expects_logical)) &
8788
,test_description_t("defining a test_diagnosis_t object by assigning a logical value" , usher(check_assigns_logical)) &
89+
,test_description_t("aggregating a test_diagnosis_t object using .also. with a logical value" , usher(check_also_logical)) &
8890
,test_description_t("hardwiring a test to pass via the passing_test() function" , usher(check_passing_test_function)) &
8991
]
9092
test_results = test_diagnosis_test%run(test_descriptions)
@@ -157,6 +159,12 @@ function check_equals_c_ptr() result(test_diagnosis)
157159
test_diagnosis = t_ptr .equalsExpected. c_loc(t)
158160
end function
159161

162+
function check_equals_logical() result(test_diagnosis)
163+
type(test_diagnosis_t) test_diagnosis
164+
logical, parameter :: t = .true., f = .false.
165+
test_diagnosis = (t .equalsExpected. t) .also. (f .equalsExpected. f)
166+
end function
167+
160168
function check_equals_string() result(test_diagnosis)
161169
type(test_diagnosis_t) test_diagnosis
162170
type(string_t) expected_value
@@ -303,6 +311,13 @@ function check_assigns_logical() result(test_diagnosis)
303311
test_diagnosis = .true.
304312
end function
305313

314+
function check_also_logical() result(test_diagnosis)
315+
type(test_diagnosis_t) test_diagnosis
316+
test_diagnosis = .true.
317+
test_diagnosis = test_diagnosis .also. .true.
318+
test_diagnosis = .true. .also. test_diagnosis
319+
end function
320+
306321
function check_passing_test_function() result(test_diagnosis)
307322
type(test_diagnosis_t) test_diagnosis
308323
test_diagnosis = passing_test()

0 commit comments

Comments
 (0)