Index: Binary.d =================================================================== --- Binary.d (revision 56) +++ Binary.d (working copy) @@ -56,7 +56,7 @@ slice of A to be searched. */ size_t bsearch(T)(T[] A, T x, size_t lo=0, size_t hi=size_t.max) -in { assert(is_sorted(A)); } +in { assert(is_sorted(A[lo..(hi==size_t.max)?$:hi])); } body { size_t ret = A.bisect_left(x,lo,hi); @@ -86,6 +86,9 @@ assert(bar.bsearch(4) == NOT_FOUND); assert(bar.bsearch(8) == 5); assert(bar.bsearch(9) == NOT_FOUND); + bar ~= 2; + assert(bar.bsearch(0, 0u,7u) == NOT_FOUND); + assert(bar.bsearch(1, 0u,7u) == 0); UTest.end; } @@ -98,7 +101,7 @@ slice of A to be searched. */ size_t bsearch_right(T)(T[] A, T x, size_t lo=0, size_t hi=size_t.max) -in { assert(is_sorted(A)); } +in { assert(is_sorted(A[lo..(hi==size_t.max)?$:hi])); } body { size_t ret = A.bisect(x,lo,hi); @@ -129,6 +132,9 @@ assert(bar.bsearch_right(4) == NOT_FOUND); assert(bar.bsearch_right(8) == 6); assert(bar.bsearch_right(9) == NOT_FOUND); + bar ~= 2; + assert(bar.bsearch_right(0, 0u,7u) == NOT_FOUND); + assert(bar.bsearch_right(1, 0u,7u) == 1); UTest.end; } @@ -142,7 +148,7 @@ slice of A to be searched. */ size_t bisect(T)(T[] A, T x, size_t lo=0, size_t hi=size_t.max) -in { assert(is_sorted(A)); } +in { assert(is_sorted(A[lo..(hi==size_t.max)?$:hi])); } body { if (hi == size_t.max) hi = A.length; @@ -176,6 +182,9 @@ assert(bar.bisect(7) == 6); assert(bar.bisect(8) == 8); assert(bar.bisect(9) == 8); + bar ~= 2; + assert(bar.bisect(0, 0u,8u) == 0); + assert(bar.bisect(1, 0u,8u) == 2); UTest.end; } @@ -189,7 +198,7 @@ slice of a to be searched. */ size_t bisect_left(T)(T[] A, T x, size_t lo=0, size_t hi=size_t.max) -in { assert(is_sorted(A)); } +in { assert(is_sorted(A[lo..(hi==size_t.max)?$:hi])); } body { if (hi==size_t.max) hi = A.length; @@ -223,6 +232,9 @@ assert(bar.bisect_left(7) == 6); assert(bar.bisect_left(8) == 6); assert(bar.bisect_left(9) == 8); + bar ~= 2; + assert(bar.bisect_left(0, 0u,8u) == 0); + assert(bar.bisect_left(1, 0u,8u) == 0); UTest.end; }