with Integer_Sets;  use Integer_Sets;
with Ada.Numerics.Discrete_Random;  use Ada.Numerics;
with Ada.Text_IO;          use Ada.Text_IO;
with Ada.Integer_Text_IO;  use Ada.Integer_Text_IO;

procedure Test_Ceiling is

   function Roof (S : Set; I : Integer) return Cursor is
      C : Cursor := Floor (S, I);
   begin
      if Has_Element (C) then
         return Next (C);
      end if;

      return First (S);
   end Roof;

   subtype Integer_Subtype is Integer range 0 .. 9999;

   package Random_Integers is
      new Discrete_Random (Integer_Subtype);

   use Random_Integers;

   G : Generator;

   S : Set;

   C, C2 : Cursor;
   I, I2 : Integer;

   B : Boolean;

begin

   Reset (G);

   for Index in Integer range 0 .. 9 loop
      Insert (S, Index * 1000, C, B);
   end loop;

   for Index in 1 .. 50 loop

      Insert (S, Random (G), C, B);

      New_Line;
      Put ("New sequence with item=");
      Put (Element (C), Width => 0);
      New_Line;

      C := First (S);
      I := 0;

      loop

         Put (I, Width => 4);
         Put (": ");

         I2 := I + 1000;
         --C2 := Ceiling (S, I2);
         C2 := Roof (S, I2);

         while C /= C2 loop
            Put (Element (C), Width => 4);
            Put (' ');
            Next (C);
         end loop;

         New_Line;

         exit when not Has_Element (C2);

         I := I2;

      end loop;

   end loop;


end Test_Ceiling;
