array2_test.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- test_array2.sa: 
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: array2_test.sa,v 1.2 1996/04/09 10:04:42 borisv Exp $
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.


class TEST_ARRAY2

class TEST_ARRAY2 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;