arrays.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 

class TEST_ARRAY

class TEST_ARRAY is -- This is a program class to test the implementation of class -- ARRAY. -- -- WARNING This class is not portable and can only be guaranteed to run on -- the machine on which it was compiled. -- NOTE Some operations are tested in the matrix class (transpose, -- to_portion_of) since it is more convenient to do the tests there. -- Version 1.0 Oct 97. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 28 Oct 97 kh Original from Sather 1.1 distribution include TEST ; main is class_name("ARRAY{FLTD} and ARRAY{CARD}") ; arry : ARRAY{CARD} := ARRAY{CARD}::create(5) ; arry[0] := 0 ; arry[1] := 1 ; arry[2] := 2 ; arry[3] := 3 ; arry[4] := 4 ; space : STR := LIBCHARS::default.Space.char.str ; test("size",arry.size.str,5.str) ; test("aset and aget",arry[2].str,2.str) ; res : STR := "" ; loop res := res + space + arry.elt!.str end ; test("elt!",res," 0 1 2 3 4") ; res := "" ; loop res := res + space + arry.elt!(1).str end ; test("elt!(beg)",res," 1 2 3 4") ; res := "" ; loop res := res + space + arry.elt!(1,2).str end ; test("elt!(1,2)",res," 1 2") ; res := "" ; loop res := res + space + arry.elt!(1,2,2.int).str end ; test("elt!(1,2,2)",res," 1 3") ; res := "" ; loop res := res + space + arry.ind!.str end ; test("ind!",res," 0 1 2 3 4") ; res := "" ; loop res := res + space + arry.ind1!.str end ; test("ind1!",res," 0 1 2 3 4") ; void_arry : ARRAY{CARD} := void ; test("void.size",void_arry.size,0.str) ; barry : ARRAY{CARD} := ARRAY{CARD}::create(arry.asize) ; barry.copy(arry) ; res := "" ; loop res := res + space + barry.elt!.str end ; test("copy",res," 0 1 2 3 4") ; carry : ARRAY{CARD} := ARRAY{CARD}::create(3) ; carry.copy(arry) ; res := "" ; loop res := res + space + carry.elt!.str end ; test("copy",res," 0 1 2") ; loop barry.set!(1) end ; res := "" ; loop res := res + space + barry.elt!.str end ; test("set!",res," 1 1 1 1 1") ; barry.copy(arry) ; loop barry.set!(3,1) end ; res := "" ; loop res := res + space + barry.elt!.str end ; test("set!(3,1)",res," 0 1 2 1 1") ; barry.copy(arry) ; loop barry.set!(2,2,7) end ; res := "" ; loop res := res + space + barry.elt!.str end ; test("set!(2,2,7)",res," 0 1 7 7 4") ; barry.copy(arry) ; loop barry.set!(1,2,2.int,9) end ; res := "" ; loop res := res + space + barry.elt!.str end ; test("set!(1,2,2,9)",res," 0 9 2 9 4") ; barry.copy(1,arry) ; res := "" ; loop res := res + space + barry.elt!.str end ; test("copy(1)",res," 0 0 1 2 3") ; barry.copy(1,void_arry) ; res := "" ; loop res := res + space + barry.elt!.str end ; test("copy(1,void)",res," 0 0 1 2 3") ; barry.clear ; res := "" ; loop res := res + space + barry.elt!.str end ; test("clear",res," 0 0 0 0 0") ; barry.copy(2,2,arry) ; res := "" ; loop res := res + space + barry.elt!.str end ; test("copy(2,2)",res," 0 0 0 1 0") ; barry.copy(2,2,2,arry) ; res := "" ; loop res := res + space + barry.elt!.str end ; test("copy(2,2,2)",res," 0 0 2 3 0") ; flt_arry : ARRAY{FLTD} := ARRAY{FLTD}::create(20) ; loop 100.times! ; loop flt_arry.set!(RANDOM::uniform) end ; flt_arry.insertion_sort_range(0,flt_arry.size - 1) -- NOTE The post-condition of the insertion sort will -- fail if the array is not sorted! end ; test("insertion sort",true,true.str) ; -- just to indicate passed flt_arry := ARRAY{FLTD}::create(50) ; loop 100.times! ; loop flt_arry.set!(RANDOM::uniform) end ; flt_arry.quicksort_range(0,flt_arry.asize - 1) -- NOTE The post-condition of the quick sort will -- fail if the array is not sorted! end ; test("quick sort",true.str,true.str) ; finish end ; end ; -- TEST_ARRAY