max() test (0)

This is a friendlier version of the example on the Processing web site.



Test written by Matthew Lam

size(300,250);
background(50);

boolean errors=false;

int xcoord=5;
int xoff=10;
int ycoord=35;
int yinc=15;

fill(255,255,255);
text("max(5, 9)",xcoord,ycoord+=yinc);
int a = max(5, 9);            // Sets "a" to 9
int a_exp=9;
if (a_exp==a) {
	fill(0,255,0);
} else {
	fill(255,0,0);
	errors=true;
}
text(""+a,xcoord+xoff,ycoord+=yinc);

ycoord+=yinc;

fill(255,255,255);
text("max(-4, -12)",xcoord,ycoord+=yinc);
int b = max(-4, -12);         // Sets "b" to -4
int b_exp=-4;
if (b_exp==b) {
	fill(0,255,0);
} else {
	fill(255,0,0);
	errors=true;
}
text(""+b,xcoord+xoff,ycoord+=yinc);

ycoord+=yinc;

fill(255,255,255);
text("max(12.3, 230.24)",xcoord,ycoord+=yinc);
float c = max(12.3, 230.24);  // Sets "c" to 230.24
float c_exp=230.24;
if (c_exp==c) {
	fill(0,255,0);
} else {
	fill(255,0,0);
	errors=true;
}
text(""+c,xcoord+xoff,ycoord+=yinc);

ycoord+=yinc;

fill(255,255,255);
text("max({ 9, -4, 230.24 })",xcoord,ycoord+=yinc);
float[] list = { 9, -4, 230.24 };
float h = max(list);            // Sets "h" to 230.24
float h_exp=230.24;
if (h_exp==h) {
	fill(0,255,0);
} else {
	fill(255,0,0);
	errors=true;
}
text(""+h,xcoord+xoff,ycoord+=yinc);

String errMsg="";
if (errors) {
	fill(255,0,0);
	errMsg="Some tests FAILED. See RED results.";
} else {
	fill(0,255,0);
	errMsg="All tests passed.";
}
text(errMsg,5,20);