package Stock is
   subtype Quantity is Natural range 0 .. 100;
   subtype Bin is Natural range 0 .. 2;
   type Shelf is array (Bin) of Quantity;

   procedure Restock (Items : in out Shelf; Position : Bin; Amount : Quantity)
     with Pre => Amount <= Quantity'Last - Items(Position),
          Post => Items(Position) = Items'Old (Position) + Amount
            and (for all I in Bin => (I = Position or else Items(I) = Items'Old (I)));

   procedure Reserve (Items : in out Shelf; Position : Bin; Amount : Quantity;
                      Accepted : out Boolean)
     with Post => Accepted = (Amount <= Items'Old (Position))
            and Items(Position) = (if Accepted then Items'Old (Position) - Amount else Items'Old (Position))
            and (for all I in Bin => (I = Position or else Items(I) = Items'Old (I)));

   function Total (Items : Shelf) return Natural is
     (Items(0) + Items(1) + Items(2));
end Stock;
