------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>

class INT_TEST is
    include TEST;
    
   main is
      class_name("INT");
      a ::= 5;
      b ::= 7;
      tp: FSTR := #;
      restp ::= 1101.str_in(tp,10,8,'#');
      test("1101.str_in",restp,"######2115");
      tp2: FSTR := #;
      restp2 ::= 1101.str_in(tp2,10,16,'#');
      test("1101.str_in(hex)",restp2,"#######44D");
      tp3: FSTR := #;
      restp3 ::= INT::nil.str_in(tp3,12,10,'#');
      test("nil.str_in(10)",restp3,"#-2147483648");
      
      tp4: FSTR := #;
      restp4 ::= INT::nil.str_in(tp4,12,16,'#');
      test("nil.str_in(16)",restp4,"###-80000000");
      tp5: FSTR := #;
      restp5 ::= INT::nil.str_in(tp5,16,8,'#');
      test("nil.str_in(16)",restp5,"####-20000000000");
      
      val ::= a.plus(b);
      test("plus",val.str,"12");
      test("plus",(a+b).str,"12");
      test("minus",(a-b).str,"-2");
      test("negate",(-a).str,"-5");
      test("times",(a*b).str,"35");
      test("div",(b/a).str,"1");
      test("mod",(b.mod(a)).str,"2");
      test("is_eq",(b=a).str,"false");
      test("is_eq",(a=a).str,"true");
      -- neq --- missing routines...
      -- ...
      -- Iter routines
      i::=0; loop 9.times!; i:= i+1; end;
      test("times!",i.str,"9");
      res::="";  loop res := res+5.times!+" "; end;
      test("times!:SAME",res,"0 1 2 3 4 ");
      res:="";  loop res := res+5.for!(4)+" "; end;
      test("for!",res,"5 6 7 8 ");
      res:="";  loop res := res+5.upto!(10)+" "; end;
      test("upto!",res,"5 6 7 8 9 10 ");
      res:="";  loop res := res+5.downto!(1)+" "; end;
      test("downto",res,"5 4 3 2 1 ");
      res:="";  loop res := res+5.step!(3,4)+" "; end;
      test("step",res,"5 9 13 ");
      i:=0; loop i := 0.sum!(5.step!(3,4)); end;
      test("sum!",i.str,"27");
      i:=0; loop i := 0.product!(5.step!(3,4)); end;
      test("product!",i.str,"585");
      res:=""; loop res := res+1.stepto!(10,2)+" "; end;
      test("stepto!",res.str,"1 3 5 7 9 ");
      res:=""; loop res := res+0.stepto!(10,2)+" "; end;
      test("stepto!",res.str,"0 2 4 6 8 10 ");      
      res:=""; loop res := res+10.stepto!(0,-2)+" "; end;
      test("step(down)to!",res.str,"10 8 6 4 2 0 ");
	
      test("pow 2^8",2.pow(8).str,256.str);
      cur ::= 0;
      cur_pow ::= 1;
      loop
	 30.times!;
	 test("pow 2^"+cur,2.pow(cur).str,cur_pow.str);
	 cur := cur + 1;
	 cur_pow := cur_pow*2;
      end;
	
      finish;
   end;
    
end; 

-------------------------------------------------------------------
