File: test_arrays.adb

package info (click to toggle)
gnat-gps 5.3dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 50,360 kB
  • ctags: 11,617
  • sloc: ada: 374,346; ansic: 92,327; python: 15,979; xml: 12,186; sh: 3,277; makefile: 1,113; awk: 154; perl: 128; java: 17
file content (37 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
with Dynamic_Arrays;
with Ada.Text_IO; use Ada.Text_IO;

procedure Test_Arrays is
   type My_Data is new Integer;
   package Data_Arrays is new Dynamic_Arrays
     (Data                    => My_Data,
      Table_Multiplier        => 2,
      Table_Minimum_Increment => 10,
      Table_Initial_Size      => 5);
   use Data_Arrays;

   procedure Assert (Data1 : Index_Type; Data2 : Integer; Msg : String);

   procedure Assert (Data1 : Index_Type; Data2 : Integer; Msg : String) is
   begin
      if Integer (Data1) /= Data2 then
         Put_Line ("--- Failed: " & Msg);
         Put_Line ("Expected:" & Data2'Img);
         Put_Line ("Got:     " & Data1'Img);
      end if;
   end Assert;

   Arr : Instance;
begin
   for J in My_Data'(1) .. 10_000 loop
      Append (Arr, J);
   end loop;

   Assert (Length (Arr), 10_000, "Incorrect number of elements");

   Remove (Arr, Item => 5_000);
   Assert (Length (Arr), 9_999,  "Incorrect size after remove");

   Free (Arr);
   Assert (Length (Arr), 0, "Incorrect size after free");
end Test_Arrays;