min() 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("min(5, 9)",xcoord,ycoord+=yinc);
int d = min(5, 9);            // Sets "d" to 5
int d_exp=5;
if (d_exp==d) {
	fill(0,255,0);
} else {
	fill(255,0,0);
	errors=true;
}
text(""+d,xcoord+xoff,ycoord+=yinc);

ycoord+=yinc;

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

ycoord+=yinc;

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

ycoord+=yinc;

fill(255,255,255);
text("min({ 5, 1, 2, -3 })",xcoord,ycoord+=yinc);
int[] list = { 5, 1, 2, -3 };
int h = min(list);            // Sets "h" to -3
int h_exp=-3;
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);