--  Searching, with contracts that say exactly what the result is.
package Searching is
   subtype Index is Integer range 1 .. 100;
   type Table is array (Index) of Integer;

   function Find (T : Table; Key : Integer) return Natural
     with Contract_Cases =>
            ((for some I in Index => T (I) = Key) =>
               Find'Result in Index and then T (Find'Result) = Key
                 and then (for all J in Index'First .. Find'Result - 1 => T (J) /= Key),
             others => Find'Result = 0);

   function Is_Sorted (T : Table) return Boolean is
     (for all I in Index'First .. Index'Last - 1 => T (I) <= T (I + 1));

   function Binary_Search (T : Table; Key : Integer) return Natural
     with Pre => Is_Sorted (T),
          Post => (if Binary_Search'Result /= 0 then Binary_Search'Result in Index and then T (Binary_Search'Result) = Key);
end Searching;
