1 static void test(R)(R x) 2 if (isInputRange!R) 3 { 4 import std.algorithm.searching : count; 5 immutable n = x.count; 6 7 // below 8 foreach (immutable i; 0 .. n) 9 { 10 assert(x.countsAtLeast(i)); 11 assert(!x.countsExactly(i)); 12 assert(!x.countsAtMost(i)); 13 } 14 15 // at 16 assert(x.countsAtLeast(n)); 17 assert(x.countsExactly(n)); 18 assert(x.countsAtMost(n)); 19 20 // above 21 foreach (immutable i; n + 1 .. n + 10) 22 { 23 assert(!x.countsAtLeast(i)); 24 assert(!x.countsExactly(i)); 25 assert(x.countsAtMost(i)); 26 } 27 } 28 29 import std.algorithm.iteration : filter; 30 import std.range : iota; 31 32 test(3.iota.filter!(x => true)); 33 34 int[3] x = [0, 1, 2]; 35 test(x[]);
Check if r counts to at most maxCount elements.