bag_test.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- test_bag.sa: Test class for bags
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: bag_test.sa,v 1.3 1996/04/09 10:04:48 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_BAG

class TEST_BAG is include TEST; main is rnd: RND; count,i,limit: INT; a,b,c,d: $BAG{INT}; s: STR; class_name("BAG"); a := #H_BAG{INT}; loop a.insert(0.step!(6,2)) end; a2 ::= #H_BAG{INT}; loop a2.insert(0.step!(6,2)) end; #OUT+"a="+a+"\n a2="+a2+"\n"; test("equals",a.equals(a2),true); b := #H_BAG{INT}; loop b.insert(5.upto!(15)) end; -- a = 0,2,4, 6 -- b = 5,6,7,8,9,10,11,12,13,14,15 c := a.union(b); #OUT+"c="+c.str+"\n"; -- c = 0,2,4,6,5,6,7,8,9,10,11,12,13,14,15 d := #H_BAG{INT}; loop d.insert(10.upto!(13)); d.insert(10.upto!(13)) end; #OUT+"d="+d.str+"\n"; -- d = 10 10 11 11 12 12 13 13 resde: BAG{INT} := #BAG{INT}(#ARRAY{INT}(|10,10,11,11,12,12,13,13|)); test("insert",d.str,resde); resc: BAG{INT} := #BAG{INT}(#ARRAY{INT}(|0,2,4,5,6,6,7,8,8,9,10,10,11,12,13,14,15|)); -- test("union:"+c, c.equals(resc),true); resd: BAG{INT} := #BAG{INT}(#ARRAY{INT}(|10,10,11,12,13|)); cind ::= c.intersection(d); test("intersect:"+cind, cind.equals(resd), true); test("is_subset", c.intersection(d).is_subset(d), true); test("is_subset 2", c.is_subset(d), false); test("size",c.n_unique,14); test("total_size",c.size,17); b.insert( -123 ); test( "insert", b.has(-123), true ); test( "count 1", b.count(-123), 1); b.insert( -123 ); test( "count 2", b.count(-123),2 ); b.delete( -123 ); test( "delete 1", b.has(-123), true ); b.delete( -123 ); test( "delete 2", b.has(-123), false ); c.delete_all( 10 ); #OUT+"C after delete 10"+c.str+"\n"; c.delete_all( 8 ); #OUT+"C after delete 8"+c.str+"\n"; rescdel ::= #BAG{INT}(#ARRAY{INT}(|0,2,4,5,6,6,7,9,11,12,13,14,15|)); test("delete_all",c,rescdel); finish end; end; -- TEST_BAG