uses "console", "math", "test", "sys";

class MathTest extends Test 
{
    function atan() { 
        if( Math.atan(1) != 0.785398 )
            return 1;
        iferr {
            if( Math.atan(90) )
                return 2;
        } fix {
        } else {
            return 2;
        }
        if( Math.atan(0.5) != 0.463647 )
            return 3;
        if( Math.atan(0) != 0 )
            return 4;
        return Test.SUCCESS;
    }    
    function tan() { 
        if( Math.tan(1) != 1.557407 )
            return 1;
        if( Math.tan(.5) != 0.546302 )
            return 2;
        if( Math.tan(0) != 0 )
            return 3;
        return Test.SUCCESS;
    }
    function acos() { 
        if( Math.acos(1) != 0 )
            return 1;
        iferr {
            if( Math.acos(90) )
                return 2;
        } fix {
        } else {
            return 2;
        }
        if( Math.acos(0.5) != 1.047197 )
            return 3;
        if( Math.acos(0) != 1.570796 )
            return 4;
        return Test.SUCCESS;
    }
    function cos() { 
        if( Math.cos(1) != 0.540302 )
            return 1;
        if( Math.cos(.5) != 0.877582 )
            return 2;
        if( Math.cos(0) != 1 )
            return 3;
        return Test.SUCCESS;
    }    
    function atan2() {
        if( Math.atan2(0,0) != 0 )
            return 1;
        if( Math.atan2(1,0) != 1.570796 )
            return 2;
        if( Math.atan2(0,1) != 0 )
            return 3;
        if( Math.atan2(1,1) != 0.785398 )
            return 4;
        return Test.SUCCESS;
    }
    function asin() { 
        if( Math.asin(1) != 1.570796 )
            return 1;
        iferr {
            if( Math.asin(90) )
                return 2;
        } fix {
        } else {
            return 2;
        }
        if( Math.asin(0.5) != 0.523598 )
            return 3;
        if( Math.asin(0) != 0 )
            return 4;
        return Test.SUCCESS;
    }
    function sin() { 
        if( Math.sin(1) != 0.841471 )
            return 1;
        if( Math.sin(.5) != 0.479425 )
            return 2;
        if( Math.sin(0) != 0 )
            return 3;
        return Test.SUCCESS;
    }
    function rand() { 
        number a = Math.rand();
        number b = Math.rand();
        if( a == b )
            return 1;
        return Test.SUCCESS; 
    }
    function sqrt() { 
        iferr {
            Math.sqrt(-1);
        } fix {
        } else {            
            return 1; 
        }
        if( Math.sqrt(4.0) != 2.0 )
            return 2;
        if( Math.sqrt(9.0) != 3.0 )
            return 3;
        return Test.SUCCESS;
    }
    function max() { 
        if( Math.max( 10, 11 ) == 10 )
            return 1;
        if( Math.max( 11, 10 ) == 10 )
            return 2;
        if( Math.max( 11, 11 ) != 11 )
            return 3;
        return Test.SUCCESS; 
    }
    function isLong() { 
        if( !Math.isLong(10) )
            return 1;
        if( Math.isLong(10.1) )
            return 2;
        return Test.SUCCESS; 
    }
    function getRandMax() { return Test.IGNORE; }
    function floor() { 
        if( Math.floor(10.5) != 10 )
            return 1;
        if( Math.floor(9.9) != 9 )
            return 2;
        if( Math.floor(10.9) != 10 )
            return 3;
        return Test.SUCCESS;
    }
    function ceil() { 
        if( Math.ceil(10.5) != 11 )
            return 1;
        if( Math.ceil(9.9) != 10 )
            return 2;
        if( Math.ceil(10.9) != 11 )
            return 3;
        return Test.SUCCESS;
    }
    function round() { 
        if( Math.round(10.5) != 11 )
            return 1;
        if( Math.round(9.9) != 10 )
            return 2;
        if( Math.round(10.9) != 11 )
            return 3;
        return Test.SUCCESS;        
    }
    function min() { 
        if( Math.min( 10, 11 ) == 11 )
            return 1;
        if( Math.min( 11, 10 ) == 11 )
            return 2;
        if( Math.min( 11, 11 ) != 11 )
            return 3;
        return Test.SUCCESS; 
    }
    function abs() { 
        if( 10.5 != Math.abs(10.5) )
            return 1;
        if( 10.5 != Math.abs(-10.5) )
            return 2;
        if( 11 == Math.abs(10.5) )
            return 3;
        return Test.SUCCESS; 
    }
    function srand() { return Test.IGNORE; }
    function pow() { 
        if( Math.pow(2,2) != 4.0 )
            return 1;
        if( Math.pow(3,2) != 9.0 )
            return 2;
        return Test.SUCCESS; 
    }
    function pi() { 
        if( (Math.pi() - 3.14) > 0.01 )
            return 1;
        return Test.SUCCESS;
    }
    function isDouble() { 
        if( Math.isDouble(10) )
            return 1;
        if( !Math.isDouble(10.1) )
            return 2;
        return Test.SUCCESS; 
    }
    function exp() { 
        if( Math.floor(Math.exp(1)) != 2.0 )
            return 1;
        if( Math.floor(Math.exp(5)) != 148.0 )
            return 2;
        if( Math.floor(Math.exp(10)) != 22026.0 )        
            return 3;
        return Test.SUCCESS; 
    }    
    function log10() { 
        if( Math.floor(Math.log10(1)) != 0.0 )
            return 1;
        if( Math.floor(Math.log10(5)) != 0.0 )
            return 2;
        if( Math.floor(Math.log10(10)) != 1.0 )        
            return 3;
        return Test.SUCCESS; 
    }
    function log() { 
        if( Math.floor(Math.log(1)) != 0.0 )
            return 1;
        if( Math.floor(Math.log(5)) != 1.0 )
            return 2;
        if( Math.floor(Math.log(10)) != 2.0 )        
            return 3;
        return Test.SUCCESS; 
    }
}
class MathComplexTest extends Test
{
    function sqrt() 
    {
        object a = new Math.Complex(4, 4);
        a.sqrt(a);
        if( a.real != 2.197368 )
            return 1;
        if( a.imaginary != 1.315197 )
            return 2;
        return Test.SUCCESS;
    }
    function mult()
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        object c = new Math.Complex(0.0, 0.0);
        c.mult(a,b);
        if( c.real != 1.98 )
            return 1;
        if( c.imaginary != 2.42 )
            return 2;        
        return Test.SUCCESS;
    }
    function sub()
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        object c = new Math.Complex(0.0, 0.0);
        c.sub(b,a);
        if( c.real != 1.2 )
            return 1;
        if( c.imaginary != 2.1 )
            return 2;        
        return Test.SUCCESS;
    }
    function div()
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        object c = new Math.Complex(0.0, 0.0);
        c.div(a,b);
        if( c.real != 0.25 )
            return 1;
        if( c.imaginary != -0.204545 )
            return 2;        
        return Test.SUCCESS;
    }
    function add() 
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        object c = new Math.Complex(0.0, 0.0);
        c.add(a,b);
        if( c.real != 3.2 )
            return 1;
        if( c.imaginary != 2.3 )
            return 2;
        return Test.SUCCESS;
    }
    function copy() 
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        a.copy(b);
        if( a.real != 2.2 )
            return 1;
        if( a.imaginary != 2.2 )
            return 2;
        return Test.SUCCESS;
    }
    function modulus() 
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        if( a.modulus() != 1.004988 )
            return 1;
        if( b.modulus() == 1.004988 )
            return 2;
        return Test.SUCCESS;
    }
    function conjugate() 
    {
        object a = new Math.Complex(1.0, 0.1);
        object b = new Math.Complex(2.2, 2.2);
        b.conjugate(a);
        if( b.real != 1.0 )
            return 1;
        if( b.imaginary != -0.1)
            return 2;
        return Test.SUCCESS;
    }
    function toString() 
    {
        object a = new Math.Complex(1.0, 0.1);
        if( a.toString() != "1.000000+0.100000i" )
            return 1;
        return Test.SUCCESS;
    }
}

object o = new MathTest();
object p = new MathComplexTest();
return o.run('Math') + p.run('Math.Complex');
