multimap_test.sa


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

-- Added test for when key and index are different types (gomes Nov21/95)

class TEST_MULTIMAP

class TEST_MULTIMAP is include TEST; str(a:ARRAY{STR}): STR is b ::= a.copy; b.insertion_sort_range(0,a.size-1); res ::= ""; loop res := res + " ".separate!(b.elt!) end; return res end; str(t:TUP{STR,STR}): STR is return "(" + t.t1 + "," + t.t2 + ")" end; main is d: $MULTIMAP{STR,STR}; class_name("MULTIMAP"); d := #H_MULTIMAP{STR,STR}; g2 ::= #MULTIMAP{STR,STR}; d["foo"] := "bar"; d["foo"] := "baz"; d["black"] := "white"; d["day"] := "night"; d["black"] := "purple"; test( "n_inds", d.n_inds, 3 ); test( "total_size", d.size, 5 ); sz ::= #SET{STR}; loop sz.insert(d.ind!) end; reskey ::= #SET{STR}(#ARRAY{STR}(|"black","day","foo"|)); test("ind!"+sz,sz.equals(reskey),true); total ::= #SET{STR}; loop total.insert(d.elt!) end; reselt ::= #SET{STR}(#ARRAY{STR}(|"bar","baz","night","purple","white"|)); test("elt!:"+total,total.equals(reselt),true); bindings ::= #SET{TUP{STR,STR}}; loop bindings.insert(d.pair!) end; t1 ::= #TUP{STR,STR}("black","purple"); t2 ::= #TUP{STR,STR}("black","white"); t3 ::= #TUP{STR,STR}("day","night"); t4 ::= #TUP{STR,STR}("foo","bar"); t5 ::= #TUP{STR,STR}("foo","baz"); resbind ::= #SET{TUP{STR,STR}}(#ARRAY{TUP{STR,STR}}(|t1,t2,t3,t4,t5|)); test("binding!:"+bindings,bindings.equals(resbind),true); count ::= 0; loop dummy ::= d.target!("black"); count := count + 1 end; test("target!",count,2); d.delete("black"); test("delete(k)",d.size,3); d.delete("foo","bar"); test("delete(k,e)",d.size,2); -- Just to make sure things works ok when the key and index are different g ::= #H_MULTIMAP{INT,STR}; g[1] := "this"; g[1] := "is"; g[2] := "a"; g[2] := "test"; test("n_inds",g.n_inds,2); finish; end; end; -- TEST_MULTIMAP