test_i_interval.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: test_i_interval.sa,v 1.2 1996/04/09 10:06:20 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_I_INTERVAL

class TEST_I_INTERVAL is -- Test class for integer intervals include TEST; main is class_name("I_INTERVAL"); i1: I_INTERVAL := #(0,5); i2: I_INTERVAL := #(-2,3); test("i1",i1,"[0,5]"); test("i2",i2,"[-2,3]"); test("i1.first",i1.first,0); test("i1.size",i1.size,6); test("i1.last",i1.last,5); test("i2.first",i2.first,-2); test("i2.size",i2.size,6); test("i2.first",i2.first,-2); test("i2.last",i2.last,3); test("i2.is_empty",i2.is_empty,false); test("i2.is_nil",i2.is_nil,false); i3: I_INTERVAL := I_INTERVAL::nil; test("i3.is_nil",i3.is_nil,true); i4: I_INTERVAL := #(-2,3); i5: I_INTERVAL := #(-2,-3); test("i5.is_empty",i5.is_empty,true); test("i4=i2",i4=i2,true); test("i4=i2",i4=i3,false); res:FLIST{INT}; proper: FLIST{INT}; proper := proper.push(-2).push(-1).push(0).push(1).push(2) .push(3); loop res := res.push(i2.elt!) end; test("i2's elts",res.str,proper.str); proper.to_reverse; res := #; loop res := res.push(i2.reverse_elt!) end; test("i2's reverse elts",res.str,proper.str); test("i2.intersection(i1)",i2.intersection(i1),#I_INTERVAL(0,3)); i9: I_INTERVAL := #I_INTERVAL(-5,-1); test("is_intersecting",i9.is_intersecting(i1),false); res := #; p1: I_INTERVAL := #I_INTERVAL(0,102); parts: FLIST{I_INTERVAL} := #; loop next_int: I_INTERVAL := p1.partition_equally!(9); #OUT+"Next even partition:"+next_int+":"+next_int.size+"\n"; parts := parts.push(next_int); end; rese ::= #FLIST{I_INTERVAL}; rese := rese.push(i(0,11)).push(i(12,23)).push(i(24,35)).push(i(36,47)) .push(i(48,58)).push(i(59,69)).push(i(70,80)) .push(i(81,91)).push(i(92,102)); -- Should yield a set of 6 blocks of 11 and the first 3 of 12 test("Even Parts",parts.str,rese.str); parts := #; loop next_int: I_INTERVAL := p1.partition_lump_at_end!(9); #OUT+"Next lumpy partition:"+next_int+":"+next_int.size+"\n"; parts := parts.push(next_int); end; resp ::= #FLIST{I_INTERVAL}; resp := resp.push(i(0,10)).push(i(11,21)).push(i(22,32)).push(i(33,43)) .push(i(44,54)).push(i(55,65)).push(i(66,76)).push(i(77,87)) .push(i(88,102)); -- Should yield a set of 8 blocks of 11 and the last of 14 test("Lumpy Parts",parts.str,resp.str); finish; end; i(s,f: INT): I_INTERVAL is return #I_INTERVAL(s,f) end; end;