// Macro language regression tests n = 1; // Iterations t0 = getTime; for (i=1; i<=n; i++) { runMacro("RegressionTests.js"); // run JavaScript regression tests if (i==1) runMacro("FilterTester"); // run Michael Schmid's filter tests test = "null"; roiManagerTest(true); roiManagerTest(false); measure(); binary(); logic("Logic"); math("Math"); functionCalls("FunctionCall"); images("Image"); setBatchMode(true); images("BatchImage"); setBatchMode(false); benchmarks("Benchmark"); analyzeParticles(); duplication(false); duplication(true); imageActivation(false); imageActivation(true); tableTests(false); tableTests(true); metadata(false); metadata(true); particleAnalyzer(); roiTests(false); roiTests(true); } beep; time = d2s((getTime-t0)/1000,2); showStatus("Regression tests done ("+time+" seconds)"); wait(4000); exit(); // Logic tests function logic(thisTest) { test = thisTest; if (1>2) fail(1); if (2>1) ; else fail(2); if (1+2*3!=7||2/3+1!=1+(2/3)) fail(3); s = "ImageJ has a very nice macro language"; if (s=="ImageJ has a very nice macro language2") fail(4); if ("ImageJ has a very nice macro language "==s) fail(5); a = newArray(1, 2, 3); if (a[0]+a[0]!=a[1]) fail(6); s = newArray('one', 'two'); if (s[0]+s[1] != 'onetwo') fail(7); if (s[0]>=s[1]) fail(8); } // Math tests function math(thisTest) { test = thisTest; n = 10; if (n++!=10) fail(1); if (++n!=12) fail(2); if (n--!=12) fail(3); if (--n!=10) fail(4); a=newArray(0,1,2,3,4,5,6); for (i=0; i1) fail(2); if (abs(circularity-0.9994)>0.0001) fail(3); // 0.9997 before 1.52m11 if (abs(minor-219.0134)>0.0001) fail(4); run("Duplicate...", "title=temp"); run("Restore Selection"); setAutoThreshold(); run("Convert to Mask"); run("Restore Selection"); getHistogram(values, counts, 256); if (counts[255]!=2115) fail(5); close; selectImage(id); close; selectWindow("Results"); run("Close"); } function binary() { test = "Binary"; binary2(); setBatchMode(true); test = "Binary (batch)"; binary2(); setBatchMode(false); } function binary2() { run("Options...", "iterations=1 count=1 "); run("Blobs (25K)"); run("Convert to Mask"); getHistogram(0, counts, 256); if (counts[255]!= 22243) fail(1); run("Erode"); getHistogram(0, counts, 256); if (counts[255]!= 17256) fail(2); run("Undo"); run("Close-"); getHistogram(0, counts, 256); if (counts[255]!= 21900) fail(3); run("Undo"); run("Open"); getHistogram(0, counts, 256); if (counts[255]!= 22148) fail(4); run("Undo"); run("Skeletonize"); getHistogram(0, counts, 256); if (counts[255]!= 686) fail(5); run("Undo"); run("Options...", "iterations=4 count=4"); run("Open"); getHistogram(0, counts, 256); if (counts[255]!= 19196) fail(6); run("Options...", "iterations=1 count=1 "); close; } function roiManagerTest(batchMode) { if (batchMode) test = "Roi Manager (batch mode)"; else test = "Roi Manager"; setBatchMode(batchMode); newImage("Untitled", "8-bit", 2000, 2000, 1); width = getWidth(); height = getHeight(); if (roiManager("count")>0) roiManager("reset"); n = 250; x = newArray(n); y = newArray(n); w = newArray(n); h = newArray(n); for (i=0; i0; i--) { selectImage(i); if (getTitle!="Stack") close; } if (nImages!=1 || nSlices!=7) fail2(5,""); id3 = getImageID; run("Stack to Images"); n3 = nImages; if (n3!=7) fail2(6,""); for (i=1; i<=n3; i++) { id3 -= 1; selectImage(id3); if (getImageID!=id3) fail2(7,""); } run("Close All"); run("Blobs (25K)"); id = getImageID; run("Duplicate...", " "); selectImage(id); run("FFT"); close; if (getImageID!=id) fail2(8, ""+getImageID+" "+id); run("Close All"); newImage("dummy", "32-bit ramp", 500, 500, 1); id1 = getImageID(); title = "Stack"; newImage(title, "32-bit ramp", 500, 500, 3); id2 = getImageID(); run("Stack to Images"); title2 = getTitle; if (title2!=title+"-0003") fail2(9, title2); run("Close All"); run("Blobs (25K)"); newImage("Untitled", "8-bit random", 2000, 2000, 1); selectWindow("blobs.gif"); run("Duplicate...", "title=copyForMeasuring"); run("Median...", "radius=15"); getStatistics(area, mean, min, max, std); if (abs(std-43.5047)>0.0001) fail2(10,""); close(); if (getTitle!="blobs.gif") fail2(11,getTitle+" blobs.gif"); } function tableTests(batchMode) { saveSettings; if (batchMode) test = "Tables (batch)"; else test = "Tables"; setBatchMode(batchMode); setOption("ExpandableArrays", true); tables = newArray; tableCount = 0; Table.reset("Results"); if (Table.title!="Results") fail(1); for (row=0, n=0; n<=2*PI; row++, n+=0.1) { Table.set("n", row, n); Table.set("sin(n)", row, sin(n)); Table.set("cos(n)", row, cos(n)); } Table.update; if ("Results"!=Table.title) fail(2); tables[tableCount++] = Table.title; // Duplicate table1 = "Sine/Cosine Table"; Table.create(table1); if (table1!=Table.title) fail(3); for (n=0,row=0; n<=2*PI; n+=0.1,row++) { Table.set("n", row, n); Table.set("sin(n)", row, sin(n)); Table.set("cos(n)", row, cos(n)); } Table.update; if (Table.size()!=63) failt(4); tables[tableCount++] = table1; table2 = table1 +" Copy"; Table.create(table2); headings = split(Table.headings(table1)); for (row=0; row