54 ms·
Java has this too. assert isSorted(array, start, end) : "The input array for binary search is expected to be sorted"; That said, I think in many cases asser
by marginalia_nu 4y ago
Java has this too.
assert isSorted(array, start, end) : "The input array for binary search is expected to be sorted";
That said, I think in many cases asserts tend to be fairly self-evident, they typically just list the invariants, e.g.
assert start <= end;
assert (end - start) % stepSize == 0;
// some logic
assert pos - start >= 0;
assert pos - end < 0;
assert (pos-start) % stepSize == 0;
return pos;