with Ada.Text_IO; use Ada.Text_IO;
with Matrices; use Matrices;

procedure Main
  with SPARK_Mode
is
   procedure Show (M : Matrix) is
   begin
      for I in M'Range (1) loop
         for J in M'Range (2) loop
            Put (Integer'Image (M (I, J)));
         end loop;
         New_Line;
      end loop;
   end Show;

   procedure Show_Wide (M : Wide) is
   begin
      for I in M'Range (1) loop
         for J in M'Range (2) loop
            Put (Integer'Image (M (I, J)));
         end loop;
      end loop;
      New_Line;
   end Show_Wide;

   procedure Show_Totals (T : Totals) is
   begin
      for E of T loop
         Put (Integer'Image (E));
      end loop;
      New_Line;
   end Show_Totals;

   A : constant Matrix := ((1, 2, 3), (4, 5, 6));
   B : constant Matrix := ((7, 8), (9, 10), (11, 12));
   C : constant Matrix (2 .. 3, 5 .. 6) := ((2, -1), (-3, 4));
   T : constant Matrix := Transpose (A);
   I3 : constant Matrix := Identity (3);
   Z : constant Matrix (1 .. 0, 1 .. 4) := (others => (others => 0));
begin
   Put_Line ("A is" & Integer'Image (A'Length (1)) & " by" & Integer'Image (A'Length (2)));
   Show (A);
   Put_Line ("transpose:");
   Show (T);
   Put_Line ("bounds" & Integer'Image (T'First (1)) & Integer'Image (T'Last (1)) & Integer'Image (T'First (2)) & Integer'Image (T'Last (2)));
   Put ("A times B:");
   Show_Wide (Product (A, B));
   Put ("row totals:");
   Show_Totals (Row_Totals (A));
   Put ("column totals:");
   Show_Totals (Column_Totals (A));
   Put_Line ("trace of C" & Integer'Image (Trace (C)) & ", of I3" & Integer'Image (Trace (I3)));
   Put_Line ("C's bounds" & Integer'Image (C'First (1)) & Integer'Image (C'Last (2)));
   Put_Line ("above 3 in A:" & Integer'Image (Count_Above (A, 3)));
   Put_Line ("A = A:" & Boolean'Image (A = Transpose (T)) & ", A = B: " & Boolean'Image (A = B));
   Put_Line ("Z is empty:" & Boolean'Image (Z'Length (1) = 0) & Integer'Image (Z'Length (2)) & ", rows of Z" & Integer'Image (Row_Totals (Z)'Length));
   Put_Line ("all of I3 in 0 .. 1: " & Boolean'Image ((for all I in I3'Range (1) => (for all J in I3'Range (2) => I3 (I, J) in 0 .. 1))));
end Main;
