------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>

class ARRAY2_TEST is
   include TEST;
   
-- INT and its iters should be tested before this class is tested.
   main is
      -- Note: Some operations are tested in the matrix class
      -- (transpose, to_portion_of).
      -- More convenient to do the tests there??
      class_name("ARRAY2");
      a ::= #ARRAY2{INT}(3,4);
      test("create1 and nr",a.nr.str,"3");
      test("create1 and nc",a.nc.str,"4");
      test("create1 and size1",a.size1.str,"3");
      test("create1 and size2",a.size2.str,"4");
      ainit: ARRAY{ARRAY{INT}} := ||0,1,2,3|,|10,11,12,13|,|20,21,22,23||;
      a2 ::= #ARRAY2{INT}(ainit);
      test("create2 and nr",a2.nr.str,"3");
      test("create2 and nc",a2.nc.str,"4");
      test("create2 and size1",a2.size1.str,"3");
      test("create2 and size2",a2.size2.str,"4");
      test("aget",a2[0,2].str,"2");
      test("aget",a2[0,2].str,"2");
      test("aget",a2[1,3].str,"13");
      test("aget[2,3]",a2[2,3].str,"23");
      a2[0,2] := 3; test("aset",a2[0,2].str,"3");
      a2[0,2] := 2; test("aset",a2[0,2].str,"2");
      a2[1,1] := 99; test("aset",a2[1,1].str,"99");
      a2[1,1] := 11; test("aset",a2[1,1].str,"11");
      
      res::="";   loop res := res+" "+a.ind1! end;
      test("index 1",res," 0 1 2");
      res:="";  loop res := res+" "+a.ind2! end;
      test("index 2",res," 0 1 2 3");
      res:=""; 

      res:="";   loop res := res+" "+a.row_ind! end;
      test("row",res," 0 1 2");
      res:="";  loop res := res+" "+a.col_ind! end;
      test("col",res," 0 1 2 3");
      res:=""; 
      loop 
	 res := res+" "+a.inds!.t1+","+a.inds!.t2 end;
      test("inds",res," 0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 2,0 2,1 2,2 2,3");

          -- The 1th column of a2
      res:="";  loop res := res+" "+a2.col_elt!(1) end;
      test("col 1",res," 1 11 21");

      res:="";  loop res := res+" "+a2.elt2!(1) end;
      test("elt2 1",res," 1 11 21");
      
	 -- The 2 column of a2
      res:="";  loop res := res+" "+a2.col_elt!(2) end;
      test("col_elt 2",res," 2 12 22");

      res:="";  loop res := res+" "+a2.elt2!(2) end;
      test("elt2 2",res," 2 12 22");
      
	 -- The 1th row of a2
      res:="";  loop res := res+" "+a2.row_elt!(1) end;
      test("row 1",res," 10 11 12 13");

      res:="";  loop res := res+" "+a2.elt1!(1) end;
      test("elt1 1",res," 10 11 12 13");

      	 -- The 2 row of a2
      res:="";  loop res := res+" "+a2.row_elt!(2) end;
      test("row_elt 2",res," 20 21 22 23");

      res:="";  loop res := res+" "+a2.elt1!(2) end;
      test("elt1 2",res," 20 21 22 23");

	 -- Set column 2 of b to col 1 of a2
      b::=a.copy;		
      loop b.set_col!(2,a2.col_elt!(1)) end;
      res:="";  loop res := res+" "+b.col_elt!(2) end;
      test("set col 2 1 ",res," 1 11 21");

      b:=a.copy;		
      loop b.set2!(2,a2.elt2!(1)) end;
      res:="";  loop res := res+" "+b.elt2!(2) end;
      test("set2 2 1 ",res," 1 11 21");
      
      	 -- Set column 3 of b to col 2 of a2
      b:=a.copy;		
      loop b.set_col!(3,a2.col_elt!(2)) end;
      res:="";  loop res := res+" "+b.col_elt!(3) end;
      test("set_col 3 2 ",res," 2 12 22");

      b:=a.copy;		
      loop b.set2!(3,a2.elt2!(2)) end;
      res:="";  loop res := res+" "+b.elt2!(3) end;
      test("set2 3 2 ",res," 2 12 22");

	 -- Set row 0 of c  to row 1 of a2
      c::=a.copy;  loop c.set_row!(0,a2.row_elt!(1)) end;
      res:="";  loop res := res+" "+c.row_elt!(0) end;
      test("set_row 0 1",res," 10 11 12 13");

      c:=a.copy;  loop c.set1!(0,a2.elt1!(1)) end;
      res:="";  loop res := res+" "+c.elt1!(0) end;
      test("set1 0 1",res," 10 11 12 13");
      
	 -- Set row 1 of c  to row 0 of a2
      c:=a.copy;  loop c.set_row!(1,a2.row_elt!(0)) end;
      res:="";  loop res := res+" "+c.row_elt!(1) end;
      test("set_row 1 0",res," 0 1 2 3");

      c:=a.copy;  loop c.set1!(1,a2.elt1!(0)) end;
      res:="";  loop res := res+" "+c.elt1!(1) end;
      test("set1 1 0",res," 0 1 2 3");
      finish;
      end;
   
end;
