pq_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: pq_test.sa,v 1.4 1996/04/09 10:05:21 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_PQ

class TEST_PQ is -- Test of PQ{INT} include TEST; main is -- Test of PQ{INT}. test_max_pq; test_min_pq; end; test_max_pq is class_name("A_PQ{INT}(max)"); p:A_PQ{INT}:=#; loop p.insert(50.downto!(40)); end; loop p.insert(10.upto!(20)); end; p.insert(-1); p.insert(90); test("check_heap", p.check_heap, true); test("top", p.top, 90); test("pop 1", p.pop, 90); test("pop 2", p.pop, 50); test("pop 3", p.pop, 49); test("pop 4", p.pop, 48); test("pop 5", p.pop, 47); test("is_empty 1",p.is_empty, false); p.clear; test("is_empty 2", p.is_empty, true); p:=A_PQ{INT}::create_sized(10); p.insert(1); p.insert(10); p.insert(5); p.insert(3); pl: FLIST{INT}; loop pl := pl.push(p.elt!) end; plres ::= #FLIST{INT}(#ARRAY{INT}(|10,3,5,1|)); test("elt! Elements (any order)",pl.str,plres.str); pl.clear; loop pl := pl.push(p.pop!) end; plres2 ::= #FLIST{INT}(#ARRAY{INT}(|10,5,3,1|)); test("pop! ",pl.str,plres2.str); p4 ::= #A_PQ{INT}; loop p4.bounded_insert(50.downto!(40),5); end; loop p4.bounded_insert(10.upto!(20),5); end; loop p4.bounded_insert(70.downto!(30),5); end; pl.clear; loop pl := pl.push(p4.pop!) end; popres ::= #FLIST{INT}(#ARRAY{INT}(|14,13,12,11,10|)); test("pop 1",pl.str,popres.str); finish; end; test_min_pq is class_name("A_PQ{PQMIN{INT}}"); mw: PQMIN{INT}; p:A_PQ{PQMIN{INT}}:=#; loop p.insert(#PQMIN{INT}(50.downto!(40))); end; loop p.insert(#PQMIN{INT}(10.upto!(20))); end; p.insert(#PQMIN{INT}(-1)); p.insert(#PQMIN{INT}(90)); test("check_heap", p.check_heap, true); test("top", p.top.element, -1); test("pop 1", p.pop.element, -1); test("pop 2", p.pop.element, 10); test("pop 3", p.pop.element, 11); test("pop 4", p.pop.element, 12); test("pop 5", p.pop.element, 13); test("is_empty 1",p.is_empty, false); p.clear; test("is_empty 2", p.is_empty, true); p:=A_PQ{PQMIN{INT}}::create_sized(10); p.insert(#PQMIN{INT}(1)); p.insert(#PQMIN{INT}(10)); p.insert(#(5)); p.insert(#(3)); pl: FLIST{INT}; loop pl := pl.push(p.elt!.element) end; plres ::= #FLIST{INT}(#ARRAY{INT}(|1,3,5,10|)); test("elt! Elements (any order)",pl.str,plres.str); pl.clear; loop pl := pl.push(p.pop!.element) end; popres ::= #FLIST{INT}(#ARRAY{INT}(|1,3,5,10|)); test("pop! ",pl.str,popres.str); finish; end; -- main end; -- class PQ_TEST