@@ -29,11 +29,15 @@ function results() result(test_results)
2929 descriptions = > &
3030 [ character (len= len (longest_description)) :: &
3131 " partitioning items nearly evenly across bins" , &
32- " partitioning all item across all bins without item loss" &
32+ " partitioning all item across all bins without item loss" , &
33+ " partitioning items such that each bin only has one works" , &
34+ " partitioning items such that some bins only have one works" &
3335 ], &
3436 outcomes = > &
3537 [ verify_block_partitioning(), &
36- verify_all_items_partitioned() &
38+ verify_all_items_partitioned(), &
39+ verify_all_singleton_bins_are_ok(), &
40+ verify_some_singleton_bins_are_ok() &
3741 ] &
3842 )
3943 call assert(size (descriptions) == size (outcomes), " bin_test_m(results): size(descriptions) == size(outcomes)" )
@@ -73,4 +77,39 @@ function verify_all_items_partitioned() result(test_passes)
7377
7478 end function
7579
80+ function verify_all_singleton_bins_are_ok () result(test_passes)
81+ ! ! Verify that all singleton bins can be created and that the number of items equals the number of bins
82+ type (bin_t) partition
83+ logical test_passes
84+
85+ type (bin_t), allocatable :: bins(:)
86+ integer , parameter :: n_items= 11 , n_bins= 11
87+ integer b
88+
89+ bins = [( bin_t(num_items= n_items, num_bins= n_bins, bin_number= b), b = 1 ,n_bins )]
90+ test_passes = sum ([(bins(b)% last() - bins(b)% first() + 1 , b = 1 , n_bins)]) == n_items
91+
92+ end function
93+
94+ function verify_some_singleton_bins_are_ok () result(test_passes)
95+ ! ! Verify that some singleton bins can be created and that the number of items equals the number of bins
96+ type (bin_t) partition
97+ logical test_passes
98+
99+ type (bin_t), allocatable :: bins(:), more_bins(:)
100+ integer , parameter :: n_bins= 11 , n_items= (n_bins + (n_bins/ 2 ))
101+ integer b
102+
103+ bins = [( bin_t(num_items= n_items, num_bins= n_bins, bin_number= b), b = 1 ,n_bins )]
104+ test_passes = sum ([(bins(b)% last() - bins(b)% first() + 1 , b = 1 , n_bins)]) == n_items
105+
106+ more_bins = [( bin_t(num_items= n_items, num_bins= n_bins, bin_number= b), b = 1 ,n_bins )]
107+ associate(in_bin = > [(more_bins(b)% last() - more_bins(b)% first() + 1 , b = 1 , n_bins)])
108+ associate(remainder = > mod (n_items, n_bins), items_per_bin = > n_items/ n_bins)
109+ test_passes = test_passes .and. &
110+ all ([(in_bin(1 :remainder) == items_per_bin + 1 )]) .and. all ([(in_bin(remainder+1 :) == items_per_bin)])
111+ end associate
112+ end associate
113+
114+ end function
76115end module bin_test_m
0 commit comments