Skip to content

Commit 15747b8

Browse files
committed
refac(bin_test_m): simplify
1 parent 830dad6 commit 15747b8

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

test/bin_test.f90

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module bin_test_m
22
!! verify data partitioning across bins
33
use sourcery_m, only : bin_t, test_t, test_result_t
4+
use assert_m, only : assert
45
implicit none
56

67
private
@@ -12,8 +13,6 @@ module bin_test_m
1213
procedure, nopass :: results
1314
end type
1415

15-
integer, parameter :: num_items=31, gatherer=1, num_steps=9, dummy=0
16-
1716
contains
1817

1918
pure function subject() result(specimen)
@@ -23,11 +22,24 @@ pure function subject() result(specimen)
2322

2423
function results() result(test_results)
2524
type(test_result_t), allocatable :: test_results(:)
25+
character(len=*), parameter :: longest_description = &
26+
"partitioning all item across all bins without item loss"
27+
28+
associate( &
29+
descriptions => &
30+
[ character(len=len(longest_description)) :: &
31+
"partitioning items nearly evenly across bins", &
32+
"partitioning all item across all bins without item loss" &
33+
], &
34+
outcomes => &
35+
[ verify_block_partitioning(), &
36+
verify_all_items_partitioned() &
37+
] &
38+
)
39+
call assert(size(descriptions) == size(outcomes), "bin_test_m(results): size(descriptions) == size(outcomes)")
40+
test_results = test_result_t(descriptions, outcomes)
41+
end associate
2642

27-
test_results = [ &
28-
test_result_t("partitioning items nearly evenly across bins", verify_block_partitioning()), &
29-
test_result_t("partitioning all item across all bins without item loss", verify_all_items_partitioned()) &
30-
]
3143
end function
3244

3345
function verify_block_partitioning() result(test_passes)
@@ -40,7 +52,9 @@ function verify_block_partitioning() result(test_passes)
4052

4153
bins = [( bin_t(num_items=n_items, num_bins=n_bins, bin_number=b), b = 1,n_bins )]
4254
associate(in_bin => [(bins(b)%last(b) - bins(b)%first(b) + 1, b = 1, n_bins)])
43-
test_passes = all(in_bin == n_items/n_bins .or. in_bin == n_items/n_bins + 1)
55+
associate(remainder => mod(n_items, n_bins), items_per_bin => n_items/n_bins)
56+
test_passes = all([(in_bin(1:remainder) == items_per_bin + 1)]) .and. all([(in_bin(remainder+1:) == items_per_bin)])
57+
end associate
4458
end associate
4559

4660
end function

0 commit comments

Comments
 (0)