map_test.sa


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

class TEST_MAP is include TEST; main is i: INT; t ::= #H_MAP{STR,INT}; test_of_instantiation ::= #MAP{STR,INT}; -- Just to make sure there -- are no SAME problems class_name("MAP"); loop t[1.upto!(9).str] := 9.downto!(1) end; t["Foo"] := 26; t["Bar"] := 27; test("aget 1",t["Foo"].str,"26"); test("has 1",t.has_ind("Foo").str,"true"); test("aget 2",t["Junk"].str,INT::nil.str); test("has 2",t.has_ind("Junk").str,"false"); t["Foo"] := 27; test("overwrite",t["Foo"].str,27); t.delete("Foo"); test("aget 3",t["Foo"].str,INT::nil.str); test("size",t.size.str,"10"); arr ::= #SET{STR}; loop arr.insert(t.ind!) end; arrres ::= #SET{STR}(#ARRAY{STR}(|"1","2","3","4","5","6","7","8","9", "Bar"|)); test("ind!"+arr,arr.equals(arrres),true); arr2 ::= #SET{STR}; loop arr2.insert(t.elt!.str) end; arrres2 ::= #SET{STR}(#ARRAY{STR}(|"1","2","27","3","4","5","6","7","8", "9"|)); test("elt!"+arr2,arr2.equals(arrres2),true); arr3 ::= #SET{STR}; loop p ::= t.pair!; arr3.insert(""+p.t1 + ":" + p.t2.str ) end; arr3res ::= #SET{STR}(#ARRAY{STR}(|"1:9","2:8","3:7","4:6","5:5", "6:4","7:3","8:2","9:1","Bar:27"|)); test("pair!:"+arr3,arr3.equals(arr3res),true); finish end; end;