11module collective_subroutines_test
2- use Vegetables, only: Result_t, Test_Item_t, describe, it, succeed, assert_equals
2+ use Vegetables, only: Result_t, Test_Item_t, describe, it, succeed, assert_equals, assert_that, assert_not
3+ use emulated_intrinsics_interface, only : co_sum, co_all
34
45 implicit none
56 private
67
7- public :: test_collective_subroutines
8+ public :: test_co_sum, test_co_all
89contains
9- function test_collective_subroutines () result(tests)
10+ function test_co_sum () result(tests)
1011 type (Test_Item_t) :: tests
1112
12- tests = describe(&
13+ tests = describe( &
1314 " co_sum" , &
1415 [it( &
15- " gives the correct answer with result_image present" , &
16+ " gives sums with result_image present" , &
1617 check_co_sum_with_result_image), &
1718 it( &
18- " gives the correct answer without result_image present" , &
19+ " gives sums without result_image present" , &
1920 check_co_sum_without_result_image)])
2021 end function
2122
23+ function test_co_all () result(tests)
24+ type (Test_Item_t) :: tests
25+
26+ tests = describe( &
27+ " co_all" , &
28+ [it( &
29+ " sets all arguments to .true. when previously .true. on all images" , &
30+ check_co_all_with_all_true), &
31+ it( &
32+ " sets all arguments to .false. when previously .false. on image 1" , &
33+ check_co_all_with_one_false)])
34+ end function
35+
2236 function check_co_sum_with_result_image () result(result_)
23- use emulated_intrinsics_interface, only : co_sum
2437 type (Result_t) :: result_
2538
2639 integer i, j
@@ -38,7 +51,6 @@ function check_co_sum_with_result_image() result(result_)
3851 end function
3952
4053 function check_co_sum_without_result_image () result(result_)
41- use emulated_intrinsics_interface, only : co_sum
4254 type (Result_t) :: result_
4355
4456 integer i, j
@@ -51,4 +63,23 @@ function check_co_sum_without_result_image() result(result_)
5163 end associate
5264 end function
5365
66+ function check_co_all_with_all_true () result(result_)
67+ type (Result_t) :: result_
68+ logical all_true
69+
70+ all_true= .true.
71+
72+ call co_all(all_true)
73+ result_ = assert_that(all_true, " co_all argument remains .true. after call with all arguments true" )
74+ end function
75+
76+ function check_co_all_with_one_false () result(result_)
77+ type (Result_t) :: result_
78+ logical all_true
79+
80+ all_true = merge (.false. , .true. , this_image()==1 )
81+ call co_all(all_true)
82+ result_ = assert_not(all_true, " co_all argument is .false. after call with one argument false" )
83+ end function
84+
5485end module
0 commit comments