
#!echo

###################################################################
#								  #
#   This file provide some tests on Irisplot command interpreter. #
#								  #
###################################################################


#------------------------------------------------------------------
#
#                    loop test
#
#------------------------------------------------------------------


for(i=0; i < 10; i=i+1) { j = i**2; g$(i)(x)= sin($i *x);};
i = 0;
j = 0;
do{ j = i** 3; i=i+1;
	sur$j = surface{ [ sin($j*x)*cos($i*y)]};
	}  while( i < 15);

i = 0; 
j = 0;
while( i < 10) {
	j = i**3;
	obj$i = object{ mat default sur$j };
	i = i+1;
	}


!echo "        Loop test passed."

#------------------------------------------------------------------
#
#             Definition test
#	
#------------------------------------------------------------------

				# define stuff together
define materials {
	mat1 = material{ diff 1 1 0};
	mat2 = material{ spec 1 0 1};
	mat3 = material { emi 0.2 0.5,0.0};
	};
define graphs{
	g1 = sur{[x**x + y**y]};
	g2 = cur{[sin(x),cos(x),0.2*x][x=-10,10]}
	};
define objects{
	o1 = obj{ mat mat1; push scale 2,2,2, g1, pop};
	o2 = obj{ mat mat2; transp push trans 2,0,-2, g1, pop oblique};
	};
define functions{
	f1(x) = x;
	f2(x) = x**abs(x);
	f3(x,y,z,w) = x*y + y*w+z;
	};

				  	# define  things  one by one
m4 = mat { diff 1 1 0, spec 0 0 1};
g3 = sur{[sin(x)*cos(y)]};
o3 = obj{ g3 };
ww(z) = sqrt(sqrt(z));
sur{[x**x - y**y][x=-2:2][y=-2:2]};

AA=" sur{[x*y]}"
g4 = $(AA);

light1 = light{ color: 1,1,1; position: 0,0,1,0};
light2 = light{ color: 0,0,1; position: 0,1,0,0};
lmodel1 = lmodel{ ambient: 0.1, 0.2, 0.2; attenuation: 1,0}

OO = object { material mat1, push scale 2,2,2, g3, push xrot 100,
		o3,pop,pop, material mat2 transp push trans
		-1,-1,-1,  g1, pop, obli};
OO1 = obj{ push scale: 2,2,2 OO , pop};


!echo "        Definition test passed."



#------------------------------------------------------------------
# 
#                   test set commands
#
#------------------------------------------------------------------

set dummy  s t u v 
set dummy:  x y z w

set window position 200, 800, 200, 800;
set view { lookat 0,0,1,0,0,0,0; perspective 600, 2, 0.1, 100.0};
set object size  10.0;

view =  { lookat 0,0,1,0,0,0,0; perspective 600, 2, 0.1, 100.0};
window_position: 200, 800, 200, 800;
object_size:  10.0;
apply light:  light1,light2;
apply lmodel: lmodel1;
use light:  light1,light2;
center; center obj; 

			# ---  some not very useful stuff
zbuffer off; doublebuffer off; lights off; depthcue on; box on;
slice on; save image; save_image; save image for cine;
light bulbs on; light_bulbs on; axes on; frame on; base on;
wire on; wire_frame on; normal on; reset;


!echo "        Command test passed."

#------------------------------------------------------------------
#
#   		     test math functions:
#
#------------------------------------------------------------------

  f1(x) = sin(log(1+exp(cosh(-1+ sqrt(2.0)/3 +abs(x)**0.006))*120 *x**7));
  f2(x) = floor(x)+ceil(x) + atan(x)  + asin( abs(x)> 1 ? x/abs(x): x);
  f3(x) = f2(x**2 + sin(x)) + log10 (abs( x-5) + 0.2);
  I = sqrt(-1.0);
  f4(x) = int(x) + real(sqrt(x)) + imag(sqrt(-x))*I ;
  f5(x) = arg(x+I*x**2) + gamma(x);
  f6(x) = (x > 8 ? x: 8) ;  


test_code = 0;
if( (!1!=0 || !0!=1 || 7%5!=2 || 7&3!=3 || ~(-5)!=4 || (1|4)!=5
	|| int(3!)!=6 || (3^4)!=7 || int(f6(6))!=8)) {
      !echo "  "
      !echo "        INTERNAL ERROR: Incorrect Math operation"
      test_code = 1;
    };

if(      (abs(f1(2) - (-0.9711477252894326))> 0.0000001)  ||
	 (abs(f2(3) -  8.8198420991931510 ) > 0.0000001 ) ||
	 (abs(f3(4) -  34.1552647368257500) > 0.0000001 ) ||
	 (abs(f4(5) - (7.2360679774997898+2.2360679774997898*I))
		>0.0000001) ||
	 (abs(f5(6) -  121.405647649380240)> 0.0000001))  {
      !echo "  "
      !echo "        INTERNAL ERROR: Incorrect Math operation"
      test_code = 1;
	};

if( !test_code) {
	!echo "        Math test passed.";
	}
test_code = 0;

!echo " "
!echo "        Test completed. The command interpreter is OK"
!echo " "

#-------------------------------------------------------------
quit;
#-------------------------------------------------------------
