// Max and Min Functions and Unit Tests
float max(float x, float y) {
if( y > x ) return y;
return x;
}
float mix(float x, float y) {
if( y < x ) return y;
return x;
}
// Emilie (Hermit Barber in World)
// Creative Commons: Attribution, Share-alike, Non Commercial
// Copy the above functions to your program - the following code is merely a set of unit tests
say(string f, float x,float y, float z)
{
llOwnerSay("Testing " + f + " with input X: " + (string) x + " Input Y: " + (string) y + "Resulting in: " + (string) z);
}
default
{
state_entry()
{
string test = "MAX";
float ix = 0;
float iy = 0;
float iz = 0;
say(test,ix,iy,max(ix,iy));
ix=100;iy=100;say(test,ix,iy,max(ix,iy));
ix=-100;iy=100;say(test,ix,iy,max(ix,iy));
ix=100;iy=-100;say(test,ix,iy,max(ix,iy));
ix=-100;iy=-100;say(test,ix,iy,max(ix,iy));
ix=-0.001;iy=0.00001;say(test,ix,iy,max(ix,iy));
ix=0.001;iy=0.00001;say(test,ix,iy,max(ix,iy));
ix=-0.001;iy=0.00001;say(test,ix,iy,max(ix,iy));
ix=0.001;iy=-0.00001;say(test,ix,iy,max(ix,iy));
ix=-0.001;iy=-0.00001;say(test,ix,iy,max(ix,iy));
test = "MIN";
say(test,ix,iy,min(ix,iy));
ix=100;iy=100;say(test,ix,iy,min(ix,iy));
ix=-100;iy=100;say(test,ix,iy,min(ix,iy));
ix=100;iy=-100;say(test,ix,iy,min(ix,iy));
ix=-100;iy=-100;say(test,ix,iy,min(ix,iy));
ix=0.001;iy=0.00001;say(test,ix,iy,min(ix,iy));
ix=-0.001;iy=0.00001;say(test,ix,iy,min(ix,iy));
ix=0.001;iy=-0.00001;say(test,ix,iy,min(ix,iy));
ix=-0.001;iy=-0.00001;say(test,ix,iy,min(ix,iy));
}
}
|