Commit 02fd808c by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] Clean up of GNAT.Lists

------------
-- Source --
------------

--  operations.adb

with Ada.Text_IO; use Ada.Text_IO;
with GNAT;        use GNAT;
with GNAT.Lists;  use GNAT.Lists;

procedure Operations is
   procedure Destroy (Val : in out Integer) is null;

   package Integer_Lists is new Doubly_Linked_Lists
     (Element_Type    => Integer,
      "="             => "=",
      Destroy_Element => Destroy);
   use Integer_Lists;

   procedure Check_Empty
     (Caller    : String;
      L         : Doubly_Linked_List;
      Low_Elem  : Integer;
      High_Elem : Integer);
   --  Ensure that none of the elements in the range Low_Elem .. High_Elem are
   --  present in list L, and that the list's length is 0.

   procedure Check_Locked_Mutations
     (Caller : String;
      L      : in out Doubly_Linked_List);
   --  Ensure that all mutation operations of list L are locked

   procedure Check_Present
     (Caller    : String;
      L         : Doubly_Linked_List;
      Low_Elem  : Integer;
      High_Elem : Integer);
   --  Ensure that all elements in the range Low_Elem .. High_Elem are present
   --  in list L.

   procedure Check_Unlocked_Mutations
     (Caller : String;
      L      : in out Doubly_Linked_List);
   --  Ensure that all mutation operations of list L are unlocked

   procedure Populate_With_Append
     (L         : Doubly_Linked_List;
      Low_Elem  : Integer;
      High_Elem : Integer);
   --  Add elements in the range Low_Elem .. High_Elem in that order in list L

   procedure Test_Append;
   --  Verify that Append properly inserts at the tail of a list

   procedure Test_Contains
     (Low_Elem  : Integer;
      High_Elem : Integer);
   --  Verify that Contains properly identifies that elements in the range
   --  Low_Elem .. High_Elem are within a list.

   procedure Test_Create;
   --  Verify that all list operations fail on a non-created list

   procedure Test_Delete
     (Low_Elem  : Integer;
      High_Elem : Integer);
   --  Verify that Delete properly removes elements in the range Low_Elem ..
   --  High_Elem from a list.

   procedure Test_Delete_First
     (Low_Elem  : Integer;
      High_Elem : Integer);
   --  Verify that Delete properly removes elements in the range Low_Elem ..
   --  High_Elem from the head of a list.

   procedure Test_Delete_Last
     (Low_Elem  : Integer;
      High_Elem : Integer);
   --  Verify that Delete properly removes elements in the range Low_Elem ..
   --  High_Elem from the tail of a list.

   procedure Test_First;
   --  Verify that First properly returns the head of a list

   procedure Test_Insert_After;
   --  Verify that Insert_After properly adds an element after some other
   --  element.

   procedure Test_Insert_Before;
   --  Vefity that Insert_Before properly adds an element before some other
   --  element.

   procedure Test_Is_Empty;
   --  Verify that Is_Empty properly returns this status of a list

   procedure Test_Iterate;
   --  Verify that iterators properly manipulate mutation operations

   procedure Test_Iterate_Empty;
   --  Verify that iterators properly manipulate mutation operations of an
   --  empty list.

   procedure Test_Iterate_Forced
     (Low_Elem  : Integer;
      High_Elem : Integer);
   --  Verify that an iterator that is forcefully advanced by Next properly
   --  unlocks the mutation operations of a list.

   procedure Test_Last;
   --  Verify that Last properly returns the tail of a list

   procedure Test_Prepend;
   --  Verify that Prepend properly inserts at the head of a list

   procedure Test_Present;
   --  Verify that Present properly detects a list

   procedure Test_Replace;
   --  Verify that Replace properly substitutes old elements with new ones

   procedure Test_Size;
   --  Verify that Size returns the correct size of a list

   -----------------
   -- Check_Empty --
   -----------------

   procedure Check_Empty
     (Caller    : String;
      L         : Doubly_Linked_List;
      Low_Elem  : Integer;
      High_Elem : Integer)
   is
      Len : constant Natural := Size (L);

   begin
      for Elem in Low_Elem .. High_Elem loop
         if Contains (L, Elem) then
            Put_Line ("ERROR: " & Caller & ": extra element" & Elem'Img);
         end if;
      end loop;

      if Len /= 0 then
         Put_Line ("ERROR: " & Caller & ": wrong length");
         Put_Line ("expected: 0");
         Put_Line ("got     :" & Len'Img);
      end if;
   end Check_Empty;

   ----------------------------
   -- Check_Locked_Mutations --
   ----------------------------

   procedure Check_Locked_Mutations
     (Caller : String;
      L      : in out Doubly_Linked_List)
   is
   begin
      begin
         Append (L, 1);
         Put_Line ("ERROR: " & Caller & ": Append: no exception raised");
      exception
         when Iterated =>
            null;
         when others =>
            Put_Line ("ERROR: " & Caller & ": Append: unexpected exception");
      end;

      begin
         Delete (L, 1);
         Put_Line ("ERROR: " & Caller & ": Delete: no exception raised");
      exception
         when List_Empty =>
            null;
         when Iterated =>
            null;
         when others =>
            Put_Line ("ERROR: " & Caller & ": Delete: unexpected exception");
      end;

      begin
         Delete_First (L);
         Put_Line ("ERROR: " & Caller & ": Delete_First: no exception raised");
      exception
         when List_Empty =>
            null;
         when Iterated =>
            null;
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Delete_First: unexpected exception");
      end;

      begin
         Delete_Last (L);
         Put_Line ("ERROR: " & Caller & ": Delete_List: no exception raised");
      exception
         when List_Empty =>
            null;
         when Iterated =>
            null;
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Delete_Last: unexpected exception");
      end;

      begin
         Destroy (L);
         Put_Line ("ERROR: " & Caller & ": Destroy: no exception raised");
      exception
         when Iterated =>
            null;
         when others =>
            Put_Line ("ERROR: " & Caller & ": Destroy: unexpected exception");
      end;

      begin
         Insert_After (L, 1, 2);
         Put_Line ("ERROR: " & Caller & ": Insert_After: no exception raised");
      exception
         when Iterated =>
            null;
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Insert_After: unexpected exception");
      end;

      begin
         Insert_Before (L, 1, 2);
         Put_Line
           ("ERROR: " & Caller & ": Insert_Before: no exception raised");
      exception
         when Iterated =>
            null;
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Insert_Before: unexpected exception");
      end;

      begin
         Prepend (L, 1);
         Put_Line ("ERROR: " & Caller & ": Prepend: no exception raised");
      exception
         when Iterated =>
            null;
         when others =>
            Put_Line ("ERROR: " & Caller & ": Prepend: unexpected exception");
      end;

      begin
         Replace (L, 1, 2);
         Put_Line ("ERROR: " & Caller & ": Replace: no exception raised");
      exception
         when Iterated =>
            null;
         when others =>
            Put_Line ("ERROR: " & Caller & ": Replace: unexpected exception");
      end;
   end Check_Locked_Mutations;

   -------------------
   -- Check_Present --
   -------------------

   procedure Check_Present
     (Caller    : String;
      L         : Doubly_Linked_List;
      Low_Elem  : Integer;
      High_Elem : Integer)
   is
      Elem : Integer;
      Iter : Iterator;

   begin
      Iter := Iterate (L);
      for Exp_Elem in Low_Elem .. High_Elem loop
         Next (Iter, Elem);

         if Elem /= Exp_Elem then
            Put_Line ("ERROR: " & Caller & ": Check_Present: wrong element");
            Put_Line ("expected:" & Exp_Elem'Img);
            Put_Line ("got     :" & Elem'Img);
         end if;
      end loop;

      --  At this point all elements should have been accounted for. Check for
      --  extra elements.

      while Has_Next (Iter) loop
         Next (Iter, Elem);
         Put_Line
           ("ERROR: " & Caller & ": Check_Present: extra element" & Elem'Img);
      end loop;

   exception
      when Iterator_Exhausted =>
         Put_Line
           ("ERROR: "
            & Caller
            & "Check_Present: incorrect number of elements");
   end Check_Present;

   ------------------------------
   -- Check_Unlocked_Mutations --
   ------------------------------

   procedure Check_Unlocked_Mutations
     (Caller : String;
      L      : in out Doubly_Linked_List)
   is
   begin
      begin
         Append (L, 1);
         Append (L, 2);
         Append (L, 3);
      exception
         when others =>
            Put_Line ("ERROR: " & Caller & ": Append: unexpected exception");
      end;

      begin
         Delete (L, 1);
      exception
         when others =>
            Put_Line ("ERROR: " & Caller & ": Delete: unexpected exception");
      end;

      begin
         Delete_First (L);
      exception
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Delete_First: unexpected exception");
      end;

      begin
         Delete_Last (L);
      exception
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Delete_Last: unexpected exception");
      end;

      begin
         Insert_After (L, 2, 3);
      exception
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Insert_After: unexpected exception");
      end;

      begin
         Insert_Before (L, 2, 1);
      exception
         when others =>
            Put_Line
              ("ERROR: " & Caller & ": Insert_Before: unexpected exception");
      end;

      begin
         Prepend (L, 0);
      exception
         when others =>
            Put_Line ("ERROR: " & Caller & ": Prepend: unexpected exception");
      end;

      begin
         Replace (L, 3, 4);
      exception
         when others =>
            Put_Line ("ERROR: " & Caller & ": Replace: unexpected exception");
      end;
   end Check_Unlocked_Mutations;

   --------------------------
   -- Populate_With_Append --
   --------------------------

   procedure Populate_With_Append
     (L         : Doubly_Linked_List;
      Low_Elem  : Integer;
      High_Elem : Integer)
   is
   begin
      for Elem in Low_Elem .. High_Elem loop
         Append (L, Elem);
      end loop;
   end Populate_With_Append;

   -----------------
   -- Test_Append --
   -----------------

   procedure Test_Append is
      L : Doubly_Linked_List := Create;

   begin
      Append (L, 1);
      Append (L, 2);
      Append (L, 3);
      Append (L, 4);
      Append (L, 5);

      Check_Present
        (Caller    => "Test_Append",
         L         => L,
         Low_Elem  => 1,
         High_Elem => 5);

      Destroy (L);
   end Test_Append;

   -------------------
   -- Test_Contains --
   -------------------

   procedure Test_Contains
     (Low_Elem  : Integer;
      High_Elem : Integer)
   is
      Low_Bogus  : constant Integer := Low_Elem  - 1;
      High_Bogus : constant Integer := High_Elem + 1;

      L : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, Low_Elem, High_Elem);

      --  Ensure that the elements are contained in the list

      for Elem in Low_Elem .. High_Elem loop
         if not Contains (L, Elem) then
            Put_Line
              ("ERROR: Test_Contains: element" & Elem'Img & " not in list");
         end if;
      end loop;

      --  Ensure that arbitrary elements which were not inserted in the list
      --  are not contained in the list.

      if Contains (L, Low_Bogus) then
         Put_Line
           ("ERROR: Test_Contains: element" & Low_Bogus'Img & " in list");
      end if;

      if Contains (L, High_Bogus) then
         Put_Line
           ("ERROR: Test_Contains: element" & High_Bogus'Img & " in list");
      end if;

      Destroy (L);
   end Test_Contains;

   -----------------
   -- Test_Create --
   -----------------

   procedure Test_Create is
      Count : Natural;
      Flag  : Boolean;
      Iter  : Iterator;
      L     : Doubly_Linked_List;
      Val   : Integer;

   begin
      --  Ensure that every routine defined in the API fails on a list which
      --  has not been created yet.

      begin
         Append (L, 1);
         Put_Line ("ERROR: Test_Create: Append: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Append: unexpected exception");
      end;

      begin
         Flag := Contains (L, 1);
         Put_Line ("ERROR: Test_Create: Contains: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Contains: unexpected exception");
      end;

      begin
         Delete (L, 1);
         Put_Line ("ERROR: Test_Create: Delete: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Delete: unexpected exception");
      end;

      begin
         Delete_First (L);
         Put_Line ("ERROR: Test_Create: Delete_First: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line
              ("ERROR: Test_Create: Delete_First: unexpected exception");
      end;

      begin
         Delete_Last (L);
         Put_Line ("ERROR: Test_Create: Delete_Last: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Delete_Last: unexpected exception");
      end;

      begin
         Val := First (L);
         Put_Line ("ERROR: Test_Create: First: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: First: unexpected exception");
      end;

      begin
         Insert_After (L, 1, 2);
         Put_Line ("ERROR: Test_Create: Insert_After: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line
              ("ERROR: Test_Create: Insert_After: unexpected exception");
      end;

      begin
         Insert_Before (L, 1, 2);
         Put_Line ("ERROR: Test_Create: Insert_Before: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line
              ("ERROR: Test_Create: Insert_Before: unexpected exception");
      end;

      begin
         Flag := Is_Empty (L);
         Put_Line ("ERROR: Test_Create: Is_Empty: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Is_Empty: unexpected exception");
      end;

      begin
         Iter := Iterate (L);
         Put_Line ("ERROR: Test_Create: Iterate: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Iterate: unexpected exception");
      end;

      begin
         Val := Last (L);
         Put_Line ("ERROR: Test_Create: Last: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Last: unexpected exception");
      end;

      begin
         Prepend (L, 1);
         Put_Line ("ERROR: Test_Create: Prepend: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Prepend: unexpected exception");
      end;

      begin
         Replace (L, 1, 2);
         Put_Line ("ERROR: Test_Create: Replace: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Replace: unexpected exception");
      end;

      begin
         Count := Size (L);
         Put_Line ("ERROR: Test_Create: Size: no exception raised");
      exception
         when Not_Created =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Create: Size: unexpected exception");
      end;
   end Test_Create;

   -----------------
   -- Test_Delete --
   -----------------

   procedure Test_Delete
     (Low_Elem  : Integer;
      High_Elem : Integer)
   is
      L : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, Low_Elem, High_Elem);

      --  Delete the first element, which is technically the head

      Delete (L, Low_Elem);

      --  Ensure that all remaining elements except for the head are present in
      --  the list.

      Check_Present
        (Caller    => "Test_Delete",
         L         => L,
         Low_Elem  => Low_Elem + 1,
         High_Elem => High_Elem);

      --  Delete the last element, which is technically the tail

      Delete (L, High_Elem);

      --  Ensure that all remaining elements except for the head and tail are
      --  present in the list.

      Check_Present
        (Caller    => "Test_Delete",
         L         => L,
         Low_Elem  => Low_Elem  + 1,
         High_Elem => High_Elem - 1);

      --  Delete all even elements

      for Elem in Low_Elem + 1 .. High_Elem - 1 loop
         if Elem mod 2 = 0 then
            Delete (L, Elem);
         end if;
      end loop;

      --  Ensure that all remaining elements except the head, tail, and even
      --  elements are present in the list.

      for Elem in Low_Elem + 1 .. High_Elem - 1 loop
         if Elem mod 2 /= 0 and then not Contains (L, Elem) then
            Put_Line ("ERROR: Test_Delete: missing element" & Elem'Img);
         end if;
      end loop;

      --  Delete all odd elements

      for Elem in Low_Elem + 1 .. High_Elem - 1 loop
         if Elem mod 2 /= 0 then
            Delete (L, Elem);
         end if;
      end loop;

      --  At this point the list should be completely empty

      Check_Empty
        (Caller    => "Test_Delete",
         L         => L,
         Low_Elem  => Low_Elem,
         High_Elem => High_Elem);

      --  Try to delete an element. This operation should raise List_Empty.

      begin
         Delete (L, Low_Elem);
         Put_Line ("ERROR: Test_Delete: List_Empty not raised");
      exception
         when List_Empty =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Delete: unexpected exception");
      end;

      Destroy (L);
   end Test_Delete;

   -----------------------
   -- Test_Delete_First --
   -----------------------

   procedure Test_Delete_First
     (Low_Elem  : Integer;
      High_Elem : Integer)
   is
      L : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, Low_Elem, High_Elem);

      --  Delete the head of the list, and verify that the remaining elements
      --  are still present in the list.

      for Elem in Low_Elem .. High_Elem loop
         Delete_First (L);

         Check_Present
           (Caller    => "Test_Delete_First",
            L         => L,
            Low_Elem  => Elem + 1,
            High_Elem => High_Elem);
      end loop;

      --  At this point the list should be completely empty

      Check_Empty
        (Caller    => "Test_Delete_First",
         L         => L,
         Low_Elem  => Low_Elem,
         High_Elem => High_Elem);

      --  Try to delete an element. This operation should raise List_Empty.

      begin
         Delete_First (L);
         Put_Line ("ERROR: Test_Delete_First: List_Empty not raised");
      exception
         when List_Empty =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Delete_First: unexpected exception");
      end;

      Destroy (L);
   end Test_Delete_First;

   ----------------------
   -- Test_Delete_Last --
   ----------------------

   procedure Test_Delete_Last
     (Low_Elem  : Integer;
      High_Elem : Integer)
   is
      L : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, Low_Elem, High_Elem);

      --  Delete the tail of the list, and verify that the remaining elements
      --  are still present in the list.

      for Elem in reverse Low_Elem .. High_Elem loop
         Delete_Last (L);

         Check_Present
           (Caller    => "Test_Delete_Last",
            L         => L,
            Low_Elem  => Low_Elem,
            High_Elem => Elem - 1);
      end loop;

      --  At this point the list should be completely empty

      Check_Empty
        (Caller    => "Test_Delete_Last",
         L         => L,
         Low_Elem  => Low_Elem,
         High_Elem => High_Elem);

      --  Try to delete an element. This operation should raise List_Empty.

      begin
         Delete_Last (L);
         Put_Line ("ERROR: Test_Delete_Last: List_Empty not raised");
      exception
         when List_Empty =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Delete_First: unexpected exception");
      end;

      Destroy (L);
   end Test_Delete_Last;

   ----------------
   -- Test_First --
   ----------------

   procedure Test_First is
      Elem : Integer;
      L    : Doubly_Linked_List := Create;

   begin
      --  Try to obtain the head. This operation should raise List_Empty.

      begin
         Elem := First (L);
         Put_Line ("ERROR: Test_First: List_Empty not raised");
      exception
         when List_Empty =>
            null;
         when others =>
            Put_Line ("ERROR: Test_First: unexpected exception");
      end;

      Populate_With_Append (L, 1, 2);

      --  Obtain the head

      Elem := First (L);

      if Elem /= 1 then
         Put_Line ("ERROR: Test_First: wrong element");
         Put_Line ("expected: 1");
         Put_Line ("got     :" & Elem'Img);
      end if;

      Destroy (L);
   end Test_First;

   -----------------------
   -- Test_Insert_After --
   -----------------------

   procedure Test_Insert_After is
      L : Doubly_Linked_List := Create;

   begin
      --  Try to insert after a non-inserted element, in an empty list

      Insert_After (L, 1, 2);

      --  At this point the list should be completely empty

      Check_Empty
        (Caller    => "Test_Insert_After",
         L         => L,
         Low_Elem  => 0,
         High_Elem => -1);

      Append (L, 1);           --  1

      Insert_After (L, 1, 3);  --  1, 3
      Insert_After (L, 1, 2);  --  1, 2, 3
      Insert_After (L, 3, 4);  --  1, 2, 3, 4

      --  Try to insert after a non-inserted element, in a full list

      Insert_After (L, 10, 11);

      Check_Present
        (Caller    => "Test_Insert_After",
         L         => L,
         Low_Elem  => 1,
         High_Elem => 4);

      Destroy (L);
   end Test_Insert_After;

   ------------------------
   -- Test_Insert_Before --
   ------------------------

   procedure Test_Insert_Before is
      L : Doubly_Linked_List := Create;

   begin
      --  Try to insert before a non-inserted element, in an empty list

      Insert_Before (L, 1, 2);

      --  At this point the list should be completely empty

      Check_Empty
        (Caller    => "Test_Insert_Before",
         L         => L,
         Low_Elem  => 0,
         High_Elem => -1);

      Append (L, 4);            --  4

      Insert_Before (L, 4, 2);  --  2, 4
      Insert_Before (L, 2, 1);  --  1, 2, 4
      Insert_Before (L, 4, 3);  --  1, 2, 3, 4

      --  Try to insert before a non-inserted element, in a full list

      Insert_Before (L, 10, 11);

      Check_Present
        (Caller    => "Test_Insert_Before",
         L         => L,
         Low_Elem  => 1,
         High_Elem => 4);

      Destroy (L);
   end Test_Insert_Before;

   -------------------
   -- Test_Is_Empty --
   -------------------

   procedure Test_Is_Empty is
      L : Doubly_Linked_List := Create;

   begin
      if not Is_Empty (L) then
         Put_Line ("ERROR: Test_Is_Empty: list is not empty");
      end if;

      Append (L, 1);

      if Is_Empty (L) then
         Put_Line ("ERROR: Test_Is_Empty: list is empty");
      end if;

      Delete_First (L);

      if not Is_Empty (L) then
         Put_Line ("ERROR: Test_Is_Empty: list is not empty");
      end if;

      Destroy (L);
   end Test_Is_Empty;

   ------------------
   -- Test_Iterate --
   ------------------

   procedure Test_Iterate is
      Elem   : Integer;
      Iter_1 : Iterator;
      Iter_2 : Iterator;
      L      : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, 1, 5);

      --  Obtain an iterator. This action must lock all mutation operations of
      --  the list.

      Iter_1 := Iterate (L);

      --  Ensure that every mutation routine defined in the API fails on a list
      --  with at least one outstanding iterator.

      Check_Locked_Mutations
        (Caller => "Test_Iterate",
         L      => L);

      --  Obtain another iterator

      Iter_2 := Iterate (L);

      --  Ensure that every mutation is still locked

      Check_Locked_Mutations
        (Caller => "Test_Iterate",
         L      => L);

      --  Exhaust the first itertor

      while Has_Next (Iter_1) loop
         Next (Iter_1, Elem);
      end loop;

      --  Ensure that every mutation is still locked

      Check_Locked_Mutations
        (Caller => "Test_Iterate",
         L      => L);

      --  Exhaust the second itertor

      while Has_Next (Iter_2) loop
         Next (Iter_2, Elem);
      end loop;

      --  Ensure that all mutation operations are once again callable

      Check_Unlocked_Mutations
        (Caller => "Test_Iterate",
         L      => L);

      Destroy (L);
   end Test_Iterate;

   ------------------------
   -- Test_Iterate_Empty --
   ------------------------

   procedure Test_Iterate_Empty is
      Elem : Integer;
      Iter : Iterator;
      L    : Doubly_Linked_List := Create;

   begin
      --  Obtain an iterator. This action must lock all mutation operations of
      --  the list.

      Iter := Iterate (L);

      --  Ensure that every mutation routine defined in the API fails on a list
      --  with at least one outstanding iterator.

      Check_Locked_Mutations
        (Caller => "Test_Iterate_Empty",
         L      => L);

      --  Attempt to iterate over the elements

      while Has_Next (Iter) loop
         Next (Iter, Elem);

         Put_Line
           ("ERROR: Test_Iterate_Empty: element" & Elem'Img & " exists");
      end loop;

      --  Ensure that all mutation operations are once again callable

      Check_Unlocked_Mutations
        (Caller => "Test_Iterate_Empty",
         L      => L);

      Destroy (L);
   end Test_Iterate_Empty;

   -------------------------
   -- Test_Iterate_Forced --
   -------------------------

   procedure Test_Iterate_Forced
     (Low_Elem  : Integer;
      High_Elem : Integer)
   is
      Elem : Integer;
      Iter : Iterator;
      L    : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, Low_Elem, High_Elem);

      --  Obtain an iterator. This action must lock all mutation operations of
      --  the list.

      Iter := Iterate (L);

      --  Ensure that every mutation routine defined in the API fails on a list
      --  with at least one outstanding iterator.

      Check_Locked_Mutations
        (Caller => "Test_Iterate_Forced",
         L      => L);

      --  Forcibly advance the iterator until it raises an exception

      begin
         for Guard in Low_Elem .. High_Elem + 1 loop
            Next (Iter, Elem);
         end loop;

         Put_Line
           ("ERROR: Test_Iterate_Forced: Iterator_Exhausted not raised");
      exception
         when Iterator_Exhausted =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Iterate_Forced: unexpected exception");
      end;

      --  Ensure that all mutation operations are once again callable

      Check_Unlocked_Mutations
        (Caller => "Test_Iterate_Forced",
         L      => L);

      Destroy (L);
   end Test_Iterate_Forced;

   ---------------
   -- Test_Last --
   ---------------

   procedure Test_Last is
      Elem : Integer;
      L    : Doubly_Linked_List := Create;

   begin
      --  Try to obtain the tail. This operation should raise List_Empty.

      begin
         Elem := First (L);
         Put_Line ("ERROR: Test_Last: List_Empty not raised");
      exception
         when List_Empty =>
            null;
         when others =>
            Put_Line ("ERROR: Test_Last: unexpected exception");
      end;

      Populate_With_Append (L, 1, 2);

      --  Obtain the tail

      Elem := Last (L);

      if Elem /= 2 then
         Put_Line ("ERROR: Test_Last: wrong element");
         Put_Line ("expected: 2");
         Put_Line ("got     :" & Elem'Img);
      end if;

      Destroy (L);
   end Test_Last;

   ------------------
   -- Test_Prepend --
   ------------------

   procedure Test_Prepend is
      L : Doubly_Linked_List := Create;

   begin
      Prepend (L, 5);
      Prepend (L, 4);
      Prepend (L, 3);
      Prepend (L, 2);
      Prepend (L, 1);

      Check_Present
        (Caller    => "Test_Prepend",
         L         => L,
         Low_Elem  => 1,
         High_Elem => 5);

      Destroy (L);
   end Test_Prepend;

   ------------------
   -- Test_Present --
   ------------------

   procedure Test_Present is
      L : Doubly_Linked_List;

   begin
      if Present (L) then
         Put_Line ("ERROR: Test_Present: list does not exist");
      end if;

      L := Create;

      if not Present (L) then
         Put_Line ("ERROR: Test_Present: list exists");
      end if;

      Destroy (L);
   end Test_Present;

   ------------------
   -- Test_Replace --
   ------------------

   procedure Test_Replace is
      L : Doubly_Linked_List := Create;

   begin
      Populate_With_Append (L, 1, 5);

      Replace (L, 3, 8);
      Replace (L, 1, 6);
      Replace (L, 4, 9);
      Replace (L, 5, 10);
      Replace (L, 2, 7);

      Replace (L, 11, 12);

      Check_Present
        (Caller    => "Test_Replace",
         L         => L,
         Low_Elem  => 6,
         High_Elem => 10);

      Destroy (L);
   end Test_Replace;

   ---------------
   -- Test_Size --
   ---------------

   procedure Test_Size is
      L : Doubly_Linked_List := Create;
      S : Natural;

   begin
      S := Size (L);

      if S /= 0 then
         Put_Line ("ERROR: Test_Size: wrong size");
         Put_Line ("expected: 0");
         Put_Line ("got     :" & S'Img);
      end if;

      Populate_With_Append (L, 1, 2);
      S := Size (L);

      if S /= 2 then
         Put_Line ("ERROR: Test_Size: wrong size");
         Put_Line ("expected: 2");
         Put_Line ("got     :" & S'Img);
      end if;

      Populate_With_Append (L, 3, 6);
      S := Size (L);

      if S /= 6 then
         Put_Line ("ERROR: Test_Size: wrong size");
         Put_Line ("expected: 6");
         Put_Line ("got     :" & S'Img);
      end if;

      Destroy (L);
   end Test_Size;

--  Start of processing for Operations

begin
   Test_Append;

   Test_Contains
     (Low_Elem  => 1,
      High_Elem => 5);

   Test_Create;

   Test_Delete
     (Low_Elem  => 1,
      High_Elem => 10);

   Test_Delete_First
     (Low_Elem  => 1,
      High_Elem => 5);

   Test_Delete_Last
     (Low_Elem  => 1,
      High_Elem => 5);

   Test_First;
   Test_Insert_After;
   Test_Insert_Before;
   Test_Is_Empty;
   Test_Iterate;
   Test_Iterate_Empty;

   Test_Iterate_Forced
     (Low_Elem  => 1,
      High_Elem => 5);

   Test_Last;
   Test_Prepend;
   Test_Present;
   Test_Replace;
   Test_Size;
end Operations;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q operations.adb -largs -lgmem
$ ./operations
$ gnatmem operations > leaks.txt
$ grep -c "non freed allocations" leaks.txt
0

2019-07-01  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* libgnat/g-lists.adb: Use type Doubly_Linked_List rather than
	Instance in various routines.
	* libgnat/g-lists.ads: Change type Instance to
	Doubly_Linked_List. Update various routines that mention the
	type.

gcc/testsuite/

	* gnat.dg/linkedlist.adb: Update.

From-SVN: r272861
parent 7f070fc4
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> 2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
* libgnat/g-lists.adb: Use type Doubly_Linked_List rather than
Instance in various routines.
* libgnat/g-lists.ads: Change type Instance to
Doubly_Linked_List. Update various routines that mention the
type.
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
* libgnat/g-dynhta.adb: Use type Dynamic_Hash_Table rather than * libgnat/g-dynhta.adb: Use type Dynamic_Hash_Table rather than
Instance in various routines. Instance in various routines.
* libgnat/g-dynhta.ads: Change type Instance to * libgnat/g-dynhta.ads: Change type Instance to
......
...@@ -45,7 +45,7 @@ package GNAT.Lists is ...@@ -45,7 +45,7 @@ package GNAT.Lists is
-- --
-- The following use pattern must be employed with this list: -- The following use pattern must be employed with this list:
-- --
-- List : Instance := Create; -- List : Doubly_Linked_List := Create;
-- --
-- <various operations> -- <various operations>
-- --
...@@ -63,60 +63,66 @@ package GNAT.Lists is ...@@ -63,60 +63,66 @@ package GNAT.Lists is
with procedure Destroy_Element (Elem : in out Element_Type); with procedure Destroy_Element (Elem : in out Element_Type);
-- Element destructor -- Element destructor
package Doubly_Linked_List is package Doubly_Linked_Lists is
--------------------- ---------------------
-- List operations -- -- List operations --
--------------------- ---------------------
type Instance is private; type Doubly_Linked_List is private;
Nil : constant Instance; Nil : constant Doubly_Linked_List;
-- The following exception is raised when the list is empty, and an -- The following exception is raised when the list is empty, and an
-- attempt is made to delete an element from it. -- attempt is made to delete an element from it.
List_Empty : exception; List_Empty : exception;
procedure Append (L : Instance; Elem : Element_Type); procedure Append
(L : Doubly_Linked_List;
Elem : Element_Type);
-- Insert element Elem at the end of list L. This action will raise -- Insert element Elem at the end of list L. This action will raise
-- Iterated if the list has outstanding iterators. -- Iterated if the list has outstanding iterators.
function Contains (L : Instance; Elem : Element_Type) return Boolean; function Contains
(L : Doubly_Linked_List;
Elem : Element_Type) return Boolean;
-- Determine whether list L contains element Elem -- Determine whether list L contains element Elem
function Create return Instance; function Create return Doubly_Linked_List;
-- Create a new list -- Create a new list
procedure Delete (L : Instance; Elem : Element_Type); procedure Delete
(L : Doubly_Linked_List;
Elem : Element_Type);
-- Delete element Elem from list L. The routine has no effect if Elem is -- Delete element Elem from list L. The routine has no effect if Elem is
-- not present. This action will raise -- not present. This action will raise
-- --
-- * List_Empty if the list is empty. -- * List_Empty if the list is empty.
-- * Iterated if the list has outstanding iterators. -- * Iterated if the list has outstanding iterators.
procedure Delete_First (L : Instance); procedure Delete_First (L : Doubly_Linked_List);
-- Delete an element from the start of list L. This action will raise -- Delete an element from the start of list L. This action will raise
-- --
-- * List_Empty if the list is empty. -- * List_Empty if the list is empty.
-- * Iterated if the list has outstanding iterators. -- * Iterated if the list has outstanding iterators.
procedure Delete_Last (L : Instance); procedure Delete_Last (L : Doubly_Linked_List);
-- Delete an element from the end of list L. This action will raise -- Delete an element from the end of list L. This action will raise
-- --
-- * List_Empty if the list is empty. -- * List_Empty if the list is empty.
-- * Iterated if the list has outstanding iterators. -- * Iterated if the list has outstanding iterators.
procedure Destroy (L : in out Instance); procedure Destroy (L : in out Doubly_Linked_List);
-- Destroy the contents of list L. This routine must be called at the -- Destroy the contents of list L. This routine must be called at the
-- end of a list's lifetime. This action will raise Iterated if the -- end of a list's lifetime. This action will raise Iterated if the
-- list has outstanding iterators. -- list has outstanding iterators.
function First (L : Instance) return Element_Type; function First (L : Doubly_Linked_List) return Element_Type;
-- Obtain an element from the start of list L. This action will raise -- Obtain an element from the start of list L. This action will raise
-- List_Empty if the list is empty. -- List_Empty if the list is empty.
procedure Insert_After procedure Insert_After
(L : Instance; (L : Doubly_Linked_List;
After : Element_Type; After : Element_Type;
Elem : Element_Type); Elem : Element_Type);
-- Insert new element Elem after element After in list L. The routine -- Insert new element Elem after element After in list L. The routine
...@@ -124,36 +130,38 @@ package GNAT.Lists is ...@@ -124,36 +130,38 @@ package GNAT.Lists is
-- Iterated if the list has outstanding iterators. -- Iterated if the list has outstanding iterators.
procedure Insert_Before procedure Insert_Before
(L : Instance; (L : Doubly_Linked_List;
Before : Element_Type; Before : Element_Type;
Elem : Element_Type); Elem : Element_Type);
-- Insert new element Elem before element Before in list L. The routine -- Insert new element Elem before element Before in list L. The routine
-- has no effect if After is not present. This action will raise -- has no effect if After is not present. This action will raise
-- Iterated if the list has outstanding iterators. -- Iterated if the list has outstanding iterators.
function Is_Empty (L : Instance) return Boolean; function Is_Empty (L : Doubly_Linked_List) return Boolean;
-- Determine whether list L is empty -- Determine whether list L is empty
function Last (L : Instance) return Element_Type; function Last (L : Doubly_Linked_List) return Element_Type;
-- Obtain an element from the end of list L. This action will raise -- Obtain an element from the end of list L. This action will raise
-- List_Empty if the list is empty. -- List_Empty if the list is empty.
procedure Prepend (L : Instance; Elem : Element_Type); procedure Prepend
(L : Doubly_Linked_List;
Elem : Element_Type);
-- Insert element Elem at the start of list L. This action will raise -- Insert element Elem at the start of list L. This action will raise
-- Iterated if the list has outstanding iterators. -- Iterated if the list has outstanding iterators.
function Present (L : Instance) return Boolean; function Present (L : Doubly_Linked_List) return Boolean;
-- Determine whether list L exists -- Determine whether list L exists
procedure Replace procedure Replace
(L : Instance; (L : Doubly_Linked_List;
Old_Elem : Element_Type; Old_Elem : Element_Type;
New_Elem : Element_Type); New_Elem : Element_Type);
-- Replace old element Old_Elem with new element New_Elem in list L. The -- Replace old element Old_Elem with new element New_Elem in list L. The
-- routine has no effect if Old_Elem is not present. This action will -- routine has no effect if Old_Elem is not present. This action will
-- raise Iterated if the list has outstanding iterators. -- raise Iterated if the list has outstanding iterators.
function Size (L : Instance) return Natural; function Size (L : Doubly_Linked_List) return Natural;
-- Obtain the number of elements in list L -- Obtain the number of elements in list L
------------------------- -------------------------
...@@ -179,11 +187,13 @@ package GNAT.Lists is ...@@ -179,11 +187,13 @@ package GNAT.Lists is
-- iterator has been exhausted, restore all mutation functionality of -- iterator has been exhausted, restore all mutation functionality of
-- the associated list. -- the associated list.
function Iterate (L : Instance) return Iterator; function Iterate (L : Doubly_Linked_List) return Iterator;
-- Obtain an iterator over the elements of list L. This action locks all -- Obtain an iterator over the elements of list L. This action locks all
-- mutation functionality of the associated list. -- mutation functionality of the associated list.
procedure Next (Iter : in out Iterator; Elem : out Element_Type); procedure Next
(Iter : in out Iterator;
Elem : out Element_Type);
-- Return the current element referenced by iterator Iter and advance -- Return the current element referenced by iterator Iter and advance
-- to the next available element. If the iterator has been exhausted -- to the next available element. If the iterator has been exhausted
-- and further attempts are made to advance it, this routine restores -- and further attempts are made to advance it, this routine restores
...@@ -204,7 +214,7 @@ package GNAT.Lists is ...@@ -204,7 +214,7 @@ package GNAT.Lists is
-- The following type represents a list -- The following type represents a list
type Linked_List is record type Doubly_Linked_List_Attributes is record
Elements : Natural := 0; Elements : Natural := 0;
-- The number of elements in the list -- The number of elements in the list
...@@ -215,8 +225,8 @@ package GNAT.Lists is ...@@ -215,8 +225,8 @@ package GNAT.Lists is
-- The dummy head of the list -- The dummy head of the list
end record; end record;
type Instance is access all Linked_List; type Doubly_Linked_List is access all Doubly_Linked_List_Attributes;
Nil : constant Instance := null; Nil : constant Doubly_Linked_List := null;
-- The following type represents an element iterator -- The following type represents an element iterator
...@@ -226,9 +236,9 @@ package GNAT.Lists is ...@@ -226,9 +236,9 @@ package GNAT.Lists is
-- iterator requires that this field always points to a valid node. A -- iterator requires that this field always points to a valid node. A
-- value of null indicates that the iterator is exhausted. -- value of null indicates that the iterator is exhausted.
List : Instance := null; List : Doubly_Linked_List := null;
-- Reference to the associated list -- Reference to the associated list
end record; end record;
end Doubly_Linked_List; end Doubly_Linked_Lists;
end GNAT.Lists; end GNAT.Lists;
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> 2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
* gnat.dg/linkedlist.adb: Update.
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
* gnat.dg/dynhash.adb, gnat.dg/dynhash1.adb: Update. * gnat.dg/dynhash.adb, gnat.dg/dynhash1.adb: Update.
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> 2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
......
...@@ -5,35 +5,42 @@ with GNAT; use GNAT; ...@@ -5,35 +5,42 @@ with GNAT; use GNAT;
with GNAT.Lists; use GNAT.Lists; with GNAT.Lists; use GNAT.Lists;
procedure Linkedlist is procedure Linkedlist is
package Integer_Lists is new Doubly_Linked_List procedure Destroy (Val : in out Integer) is null;
(Element_Type => Integer,
"=" => "="); package Integer_Lists is new Doubly_Linked_Lists
(Element_Type => Integer,
"=" => "=",
Destroy_Element => Destroy);
use Integer_Lists; use Integer_Lists;
procedure Check_Empty procedure Check_Empty
(Caller : String; (Caller : String;
L : Instance; L : Doubly_Linked_List;
Low_Elem : Integer; Low_Elem : Integer;
High_Elem : Integer); High_Elem : Integer);
-- Ensure that none of the elements in the range Low_Elem .. High_Elem are -- Ensure that none of the elements in the range Low_Elem .. High_Elem are
-- present in list L, and that the list's length is 0. -- present in list L, and that the list's length is 0.
procedure Check_Locked_Mutations (Caller : String; L : in out Instance); procedure Check_Locked_Mutations
(Caller : String;
L : in out Doubly_Linked_List);
-- Ensure that all mutation operations of list L are locked -- Ensure that all mutation operations of list L are locked
procedure Check_Present procedure Check_Present
(Caller : String; (Caller : String;
L : Instance; L : Doubly_Linked_List;
Low_Elem : Integer; Low_Elem : Integer;
High_Elem : Integer); High_Elem : Integer);
-- Ensure that all elements in the range Low_Elem .. High_Elem are present -- Ensure that all elements in the range Low_Elem .. High_Elem are present
-- in list L. -- in list L.
procedure Check_Unlocked_Mutations (Caller : String; L : in out Instance); procedure Check_Unlocked_Mutations
(Caller : String;
L : in out Doubly_Linked_List);
-- Ensure that all mutation operations of list L are unlocked -- Ensure that all mutation operations of list L are unlocked
procedure Populate_With_Append procedure Populate_With_Append
(L : Instance; (L : Doubly_Linked_List;
Low_Elem : Integer; Low_Elem : Integer;
High_Elem : Integer); High_Elem : Integer);
-- Add elements in the range Low_Elem .. High_Elem in that order in list L -- Add elements in the range Low_Elem .. High_Elem in that order in list L
...@@ -113,7 +120,7 @@ procedure Linkedlist is ...@@ -113,7 +120,7 @@ procedure Linkedlist is
procedure Check_Empty procedure Check_Empty
(Caller : String; (Caller : String;
L : Instance; L : Doubly_Linked_List;
Low_Elem : Integer; Low_Elem : Integer;
High_Elem : Integer) High_Elem : Integer)
is is
...@@ -137,7 +144,9 @@ procedure Linkedlist is ...@@ -137,7 +144,9 @@ procedure Linkedlist is
-- Check_Locked_Mutations -- -- Check_Locked_Mutations --
---------------------------- ----------------------------
procedure Check_Locked_Mutations (Caller : String; L : in out Instance) is procedure Check_Locked_Mutations
(Caller : String;
L : in out Doubly_Linked_List) is
begin begin
begin begin
Append (L, 1); Append (L, 1);
...@@ -247,7 +256,7 @@ procedure Linkedlist is ...@@ -247,7 +256,7 @@ procedure Linkedlist is
procedure Check_Present procedure Check_Present
(Caller : String; (Caller : String;
L : Instance; L : Doubly_Linked_List;
Low_Elem : Integer; Low_Elem : Integer;
High_Elem : Integer) High_Elem : Integer)
is is
...@@ -287,7 +296,10 @@ procedure Linkedlist is ...@@ -287,7 +296,10 @@ procedure Linkedlist is
-- Check_Unlocked_Mutations -- -- Check_Unlocked_Mutations --
------------------------------ ------------------------------
procedure Check_Unlocked_Mutations (Caller : String; L : in out Instance) is procedure Check_Unlocked_Mutations
(Caller : String;
L : in out Doubly_Linked_List)
is
begin begin
Append (L, 1); Append (L, 1);
Append (L, 2); Append (L, 2);
...@@ -306,7 +318,7 @@ procedure Linkedlist is ...@@ -306,7 +318,7 @@ procedure Linkedlist is
-------------------------- --------------------------
procedure Populate_With_Append procedure Populate_With_Append
(L : Instance; (L : Doubly_Linked_List;
Low_Elem : Integer; Low_Elem : Integer;
High_Elem : Integer) High_Elem : Integer)
is is
...@@ -321,7 +333,7 @@ procedure Linkedlist is ...@@ -321,7 +333,7 @@ procedure Linkedlist is
----------------- -----------------
procedure Test_Append is procedure Test_Append is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Append (L, 1); Append (L, 1);
...@@ -350,7 +362,7 @@ procedure Linkedlist is ...@@ -350,7 +362,7 @@ procedure Linkedlist is
Low_Bogus : constant Integer := Low_Elem - 1; Low_Bogus : constant Integer := Low_Elem - 1;
High_Bogus : constant Integer := High_Elem + 1; High_Bogus : constant Integer := High_Elem + 1;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, Low_Elem, High_Elem); Populate_With_Append (L, Low_Elem, High_Elem);
...@@ -388,7 +400,7 @@ procedure Linkedlist is ...@@ -388,7 +400,7 @@ procedure Linkedlist is
Count : Natural; Count : Natural;
Flag : Boolean; Flag : Boolean;
Iter : Iterator; Iter : Iterator;
L : Instance; L : Doubly_Linked_List;
Val : Integer; Val : Integer;
begin begin
...@@ -548,7 +560,7 @@ procedure Linkedlist is ...@@ -548,7 +560,7 @@ procedure Linkedlist is
High_Elem : Integer) High_Elem : Integer)
is is
Iter : Iterator; Iter : Iterator;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, Low_Elem, High_Elem); Populate_With_Append (L, Low_Elem, High_Elem);
...@@ -635,7 +647,7 @@ procedure Linkedlist is ...@@ -635,7 +647,7 @@ procedure Linkedlist is
(Low_Elem : Integer; (Low_Elem : Integer;
High_Elem : Integer) High_Elem : Integer)
is is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, Low_Elem, High_Elem); Populate_With_Append (L, Low_Elem, High_Elem);
...@@ -684,7 +696,7 @@ procedure Linkedlist is ...@@ -684,7 +696,7 @@ procedure Linkedlist is
(Low_Elem : Integer; (Low_Elem : Integer;
High_Elem : Integer) High_Elem : Integer)
is is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, Low_Elem, High_Elem); Populate_With_Append (L, Low_Elem, High_Elem);
...@@ -731,7 +743,7 @@ procedure Linkedlist is ...@@ -731,7 +743,7 @@ procedure Linkedlist is
procedure Test_First is procedure Test_First is
Elem : Integer; Elem : Integer;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
-- Try to obtain the head. This operation should raise List_Empty. -- Try to obtain the head. This operation should raise List_Empty.
...@@ -766,7 +778,7 @@ procedure Linkedlist is ...@@ -766,7 +778,7 @@ procedure Linkedlist is
----------------------- -----------------------
procedure Test_Insert_After is procedure Test_Insert_After is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
-- Try to insert after a non-inserted element, in an empty list -- Try to insert after a non-inserted element, in an empty list
...@@ -805,7 +817,7 @@ procedure Linkedlist is ...@@ -805,7 +817,7 @@ procedure Linkedlist is
------------------------ ------------------------
procedure Test_Insert_Before is procedure Test_Insert_Before is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
-- Try to insert before a non-inserted element, in an empty list -- Try to insert before a non-inserted element, in an empty list
...@@ -844,7 +856,7 @@ procedure Linkedlist is ...@@ -844,7 +856,7 @@ procedure Linkedlist is
------------------- -------------------
procedure Test_Is_Empty is procedure Test_Is_Empty is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
if not Is_Empty (L) then if not Is_Empty (L) then
...@@ -874,7 +886,7 @@ procedure Linkedlist is ...@@ -874,7 +886,7 @@ procedure Linkedlist is
Elem : Integer; Elem : Integer;
Iter_1 : Iterator; Iter_1 : Iterator;
Iter_2 : Iterator; Iter_2 : Iterator;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, 1, 5); Populate_With_Append (L, 1, 5);
...@@ -935,7 +947,7 @@ procedure Linkedlist is ...@@ -935,7 +947,7 @@ procedure Linkedlist is
procedure Test_Iterate_Empty is procedure Test_Iterate_Empty is
Elem : Integer; Elem : Integer;
Iter : Iterator; Iter : Iterator;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
-- Obtain an iterator. This action must lock all mutation operations of -- Obtain an iterator. This action must lock all mutation operations of
...@@ -978,7 +990,7 @@ procedure Linkedlist is ...@@ -978,7 +990,7 @@ procedure Linkedlist is
is is
Elem : Integer; Elem : Integer;
Iter : Iterator; Iter : Iterator;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, Low_Elem, High_Elem); Populate_With_Append (L, Low_Elem, High_Elem);
...@@ -1026,7 +1038,7 @@ procedure Linkedlist is ...@@ -1026,7 +1038,7 @@ procedure Linkedlist is
procedure Test_Last is procedure Test_Last is
Elem : Integer; Elem : Integer;
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
-- Try to obtain the tail. This operation should raise List_Empty. -- Try to obtain the tail. This operation should raise List_Empty.
...@@ -1061,7 +1073,7 @@ procedure Linkedlist is ...@@ -1061,7 +1073,7 @@ procedure Linkedlist is
------------------ ------------------
procedure Test_Prepend is procedure Test_Prepend is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Prepend (L, 5); Prepend (L, 5);
...@@ -1084,7 +1096,7 @@ procedure Linkedlist is ...@@ -1084,7 +1096,7 @@ procedure Linkedlist is
------------------ ------------------
procedure Test_Replace is procedure Test_Replace is
L : Instance := Create; L : Doubly_Linked_List := Create;
begin begin
Populate_With_Append (L, 1, 5); Populate_With_Append (L, 1, 5);
...@@ -1111,7 +1123,7 @@ procedure Linkedlist is ...@@ -1111,7 +1123,7 @@ procedure Linkedlist is
--------------- ---------------
procedure Test_Size is procedure Test_Size is
L : Instance := Create; L : Doubly_Linked_List := Create;
S : Natural; S : Natural;
begin begin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment