singlemap.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
class TEST_MAP
class TEST_MAP is
-- This is a program class to test the implementation of single maps.
--
-- WARNING This class is not portable and can only be guaranteed to run on
-- the machine on which it was compiled.
-- Version 1.1 Nov 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 29 Oct 97 kh Original from Sather 1.1 distribution
-- 19 Nov 98 kh Complete rewrite for 1.2
include TEST ;
eq(
map1,
map2 : $RO_MULTIMAP{CHAR,CARD}
) : BOOL is
-- This predicate returns true if and only if map1 and map2 are equal.
-- It is a suitable place to insert debugging write calls if needed.
return map1.equals(map2)
end ;
test_map_readonly(
map0,
map1,
map2 : $RO_MAP{CHAR,CARD}
) is
-- This routine test the readonly functions of maps. Initially the
-- values should be
--
-- map0 is empty
-- map1 is (a,1),(b,2),(c,3)
-- map2 is (a,1)(c,3),(d,4)
test("map0.size",map0.size.str,0.str) ;
test("map1.size",map1.size.str,3.str) ;
test("map1.aget(a)",map1.aget('a').str,1.str) ;
test("map1.insert(d,4) equals map2.insert(b,2)",eq(map1.insert('d',4),
map2.insert(TUP{CHAR,CARD}::create('b',2))).str,true.str) ;
test("map1 = map2",map1.equals(map2).str,false.str) ;
test("map1.delete(b,2) equals map2.delete(d,4)",eq(map1.delete('b',2),
map2.delete(TUP{CHAR,CARD}::create('d',4))).str,true.str) ;
test("map1.has_ind(a)",map1.has_ind('a').str,true.str) ;
test("map1.delete_ind(a).has_ind(a)",
map1.delete_ind('a').has_ind('a').str,false.str) ;
test("map1.n_targets(a)",map1.n_targets('a').str,1.str) ;
test("map1.delete(a,1).n_targets(a)",
map1.delete('a',1).n_targets('a').str,0.str) ;
sind : ARRAY{CHAR} := ARRAY{CHAR}::create(map1.size) ;
loop
sind.set!(map1.ind!)
end ;
sind.sort ;
test("map1.ind!",sind.str,ARRAY{CHAR}::create(|'a','b','c'|).str) ;
target : CARD ;
loop
target := map1.target!('a')
end ;
test("map1.target!",target.str,1.str) ;
test("map1.delete(b,2).is_subset_of(map2)",
map1.delete('b',2).is_subset_of(map2).str,true.str) ;
test("map1.is_subset_of(map2)",map1.is_subset_of(map2).str,false.str) ;
test("map1.add(d,4).add(d,4) equals map2.add(b,2).add(d,4)",
eq(map1.add('d',4).add('d',4),
map2.add('b',2).add('d',4)).str,true.str) ;
test("map1.union(map2)=map2.insert(b,2)",eq(map1.union(map2),
map2.insert('b',2)).str,true.str) ;
test("map1.intersection(map2)=map1.delete(b,2)",
eq(map1.intersection(map2), map1.delete('b',2)).str,true.str) ;
test("map1.diff(map2)=map1.delete(a,1).delete(c,3)",eq(map1.diff(map2),
map1.delete('a',1).delete('c',3)).str,true.str) ;
test("map1.sym_diff(map2)=map0.insert(b,2).insert(c,3)",
eq(map1.sym_diff(map2),map0.insert('b',2).insert('d',4)).str,true.str) ;
finish
end ;
test_map(
map0,
map1,
map2 : $MAP{CHAR,CARD}
) is
-- This routine test the modification functions on maps. Initial values
-- should be
--
-- map0 is empty
-- map1 is (a,1),(b,2),(c,3)
-- map2 is (a,1)(c,3),(d,4)
map3 : $MAP{CHAR,CARD} := map0.copy ;
map3['b'] := 2 ;
test("map3.insert(b,2)",eq(map3,map0.insert('b',2)).str,true.str) ;
map3.to_union(map2) ;
test("map3.to_union(map2)",eq(map3,map2.insert('b',2)).str,true.str) ;
map3.to_sym_diff(map1) ;
test("map3.to_sym_diff(map1)",eq(map3,map0.insert('d',4)).str,true.str) ;
map3.to_intersection(map2) ;
test("map3.to_intersection(map2)",
eq(map3,map0.insert('d',4)).str,true.str) ;
map3.to_diff(map2) ;
test("map3.to_diff(map2)",eq(map3,map0).str, true.str) ;
finish
end ;
vmap is
-- This routine provides all of the readonly tests on value maps by
-- first setting up the map values and then calling the read only test
-- routine with those arguments..
class_name("VMAP") ;
map0 : VMAP{CHAR,CARD} := VMAP{CHAR,CARD}::create ;
map1 : VMAP{CHAR,CARD} := map0.insert('a',1).insert('b',2).insert('c',3) ;
map2 : VMAP{CHAR,CARD} := map0.insert('a',1).insert('c',3).insert('d',4) ;
test_map_readonly(map0,map1,map2)
end ;
map is
-- This routine provides both readonly and modification tests on maps.
class_name("MAP readonly");
map0 : MAP{CHAR,CARD} := MAP{CHAR,CARD}::create ;
map1 : MAP{CHAR,CARD} := map0.insert('a',1).insert('b',2).insert('c',3) ;
map2 : MAP{CHAR,CARD} := map0.insert('a',1).insert('c',3).insert('d',4) ;
test_map_readonly(map0,map1,map2) ;
class_name("MAP modifying") ;
test_map(map0,map1,map2)
end ;
main is
vmap ;
map
end ;
end ; -- TEST_MAP