Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /charles/src/testdir/

charles
Discussion topic

Back to topic list

CVS update: /charles/src/testdir/

Reply

Author matthewjheaney
Full name Matthew Heaney
Date 2004-03-04 21:14:58 PST
Message User: matthewjheaney
Date: 04/03/04 21:14:58

Added:
 /charles/src/testdir/
  test_sorted_string_m​ultimaps.adb

Log:
 driver to test string-key sorted multimap

File Changes:

Directory: /charles/src/testdir/
====================​============

File [added]: test_sorted_string_m​ultimaps.adb
Url: http://charles.tigri​s.org/source/browse/​charles/src/testdir/​test_sorted_string_m​ultimaps.adb?rev=1.1​&content-type=te​xt/vnd.viewcvs-marku​p
Added lines: 180
----------------
with String_Integer_Sorte​d_Multimaps; use String_Integer_Sorte​d_Multimaps;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Test_Sorted_String_Multimaps is

   procedure Check_Sorted (C : Container_Type) is
      procedure Process (I : Iterator_Type) is
      begin
         pragma Assert (I = First (C) or else
                        (Key (Pred (I)) <= Key (I)));
         null;
      end;

      procedure Iterate is
         new String_Integer_Sorte​d_Multimaps.Generic_​Iteration;
   begin
      Iterate (C);
   end;

   subtype Integer_Subtype is Integer range 1 .. 1000;

   package Random_Elements is
       new Ada.Numerics.Discrete_Random (Integer_Subtype);

   GE : Random_Elements.Generator;
   use Random_Elements;

   subtype Character_Subtype is
     Character range Character'Succ (' ') .. '~';

   package Random_Characters is
      new Ada.Numerics.Discrete_Random (Character_Subtype);

   GK : Random_Characters.Generator;
   use Random_Characters;

   function Random_Key return String is

      N : constant Positive := 1 + Random (GE) mod 8;
      K : String (1 .. N);
   begin
      for I in K'Range loop
         K (I) := Random (GK);
      end loop;

      return K;
   end;

   M, M2 : Container_Type;

   K : Unbounded_String;
   E : Integer;

   I, J : Iterator_Type;

   N : Natural;

begin

   Reset (GK);
   Reset (GE);

   pragma Assert (First (M) = Back (M));
   pragma Assert (Succ (First (M)) = First (M));
   pragma Assert (Pred (First (M)) = First (M));
   pragma Assert (Succ (Back (M)) = Back (M));
   pragma Assert (Pred (Back (M)) = Back (M));
   pragma Assert (Length (M) = 0);

   pragma Assert (M = M2);

   M2 := M;
   pragma Assert (M = M2);

   Assign (Target => M2, Source => M);
   pragma Assert (M = M2);

   E := Random (GE);

   K := To_Unbounded_String (Random_Key);

   Insert (M, To_String (K), E, I);
   pragma Assert (Length (M) = 1);
   pragma Assert (Key (I) = To_String (K));
   pragma Assert (Element (I) = E);
   pragma Assert (I = First (M));
   pragma Assert (I = Last (M));
   pragma Assert (Pred (I) = Back (M));
   pragma Assert (Succ (I) = Back (M));

   M2 := M;
   pragma Assert (M = M2);

   Assign (Target => M2, Source => M);
   pragma Assert (M = M2);

   J := Find (M, Key => To_String (K));
   pragma Assert (J /= Back (M));
   pragma Assert (Key (J) = To_String (K));
   pragma Assert (Element (J) = E);

   M2 := M;
   pragma Assert (M = M2);

   Assign (Target => M2, Source => M);
   pragma Assert (M = M2);

   Put_Line ("inserting");

   loop

      Check_Sorted (M);

      N := Length (M);

      exit when N > 900;

      K := To_Unbounded_String (Random_Key);
      E := Random (GE);

      Insert (M, To_String (K), E, I);

      pragma Assert (Pred (First (M)) = Back (M));
      pragma Assert (Succ (Back (M)) = First (M));
      pragma Assert (Key (I) = To_String (K));

      J := Find (M, Key => To_String (K));
      pragma Assert (J /= Back (M));
      pragma Assert (Key (J) = To_String (K));

      if I = First (M) then
         pragma Assert (Key (I) <= Key (Succ (I)));
         null;
      elsif I = Last (M) then
         pragma Assert (Key (I) >= Key (Pred (I)));
         null;
      else
         pragma Assert (Key (I) >= Key (Pred (I)));
         pragma Assert (Key (I) <= Key (Succ (I)));
         null;
      end if;

      pragma Assert (Length (M) = N + 1);

      M2 := M;
      pragma Assert (M = M2);

      Assign (Target => M2, Source => M);
      pragma Assert (M = M2);

   end loop;

   Put_Line ("deleting");

   while not Is_Empty (M) loop

      I := Succ (First (M), Offset => Random (GE) mod Length (M));
      K := To_Unbounded_String (Key (I));

      Delete (M, I);

      pragma Assert (Pred (First (M)) = Back (M));
      pragma Assert (Succ (Back (M)) = First (M));

      Check_Sorted (M);

      M2 := M;
      pragma Assert (M = M2);

      Assign (Target => M2, Source => M);
      pragma Assert (M = M2);

   end loop;

end Test_Sorted_String_Multimaps;







--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@char​les.tigris.org
For additional commands, e-mail: cvs-help at charles dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /charles/src/testdir/ matthewjheaney Matthew Heaney 2004-03-04 21:14:58 PST
Messages per page: