1 with ada.text_io;
 2 with ada.integer_text_io;
 3 with Ada.Numerics.Discrete_Random;
 4 
 5 procedure testSort is
 6    subtype number is integer range 1..250;
 7    type theArray is Array (1..15) of number;
 8 
 9    myArray : theArray;
10 
11   procedure TestRandomNumberGenerator (a : out theArray)  is
12    package myValues is new Ada.Numerics.Discrete_Random (number);
13      g         : myValues.generator;
14       begin
15       myValues.reset(g);  
16          for i in 1..15 loop  
17          a(i) := myValues.Random(g);
18         ada.integer_text_io.put (a(i),5);
19    --  ada.text_io.new_line;
20       end loop;
21    end testRandomNumberGenerator;
22    
23  procedure swap (i : in out number; j : in out number) is
24   temp : number; 
25  begin
26  -- ada.text_io.put (" entering swap ");
27     temp := i;
28     i    := j;
29     j    := temp;
30  end swap;
31   
32    
33  PROCEDURE bubbleSort( A : in out theArray )is
34    swapped : boolean;
35 
36  begin
37 -- ada.integer_text_io.put (a'first);  -- DEBUG
38 -- ada.integer_text_io.put (a'last);   -- DEBUG
39    swapped := false; 
40    while not swapped loop
41      swapped := true;
42      for i in a'first..a'last-1  loop
43 --    ada.integer_text_io.put(i);
44       if A(i) > A(i + 1) then
45         swap( A(i), A(i + 1) );
46         swapped := false;
47       end if;
48     end loop;
49   end loop;
50 end bubbleSort;
51 
52  procedure print (a : in theArray) is
53  begin
54     for i in a'first..a'last  loop
55        ada.integer_text_io.put(a(i),5);
56     end loop; 
57   end print;
58   
59   begin
60     testRandomNumberGenerator (myarray);
61     ada.text_io.new_line;
62     print(myArray);
63     ADA.TEXT_IO.NEW_LINE;
64     bubblesort (myArray);   --- testing bubble sort
65     print (myArray);
66     
67     testRandomNumberGenerator (myarray);
68     ada.text_io.new_line;
69     print(myArray);
70     ADA.TEXT_IO.NEW_LINE;
71     INSERTIONSORT (myArray);   --- testing INSERTION SORT
72     print (myArray);
73 
74     testRandomNumberGenerator (myarray);
75     ada.text_io.new_line;
76     print(myArray);
77     ADA.TEXT_IO.NEW_LINE;
78 -- bubblesort (myArray);   --- testing SELECTION sort
79     print (myArray);
80 
81     testRandomNumberGenerator (myarray);
82     ada.text_io.new_line;
83     print(myArray);
84     ADA.TEXT_IO.NEW_LINE;
85 --  bubblesort (myArray);   --- testing QUICKSORT
86     print (myArray);
87     
88     
89   end testSort;