Changeset 6285
 Timestamp:
 05/12/10 11:48:57 (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/components/lociplugins/test/loci/plugins/in/ImporterTest.java
r6283 r6285 14 14 import java.lang.reflect.Field; 15 15 16 import ij.IJ; 16 17 import ij.ImagePlus; 17 18 import ij.ImageStack; … … 38 39 // concatenate  test order of images in stack? 39 40 // swapped dims test needs to test cases other than from default swapping Z & T 40 // lowest priority  record modifications41 41 // output stack order  testing of iIndex? 42 // range  more combos of ztc 42 // range  more combos of ztc, more bad cases 43 43 //  add some tests for combination of options 44 44 … … 201 201 202 202 int procNum = 1; 203 for (int k = tFrom; k <= tTo; k+= tBy)204 for (int j = cFrom; j <= cTo; j+= cBy)205 for (int i = zFrom; i <= zTo; i+= zBy)203 for (int t = tFrom; t <= tTo; t += tBy) 204 for (int c = cFrom; c <= cTo; c += cBy) 205 for (int z = zFrom; z <= zTo; z += zBy) 206 206 { 207 207 ImageProcessor proc = st.getProcessor(procNum); 208 if ((zIndex(proc) != i)  (cIndex(proc) != j)  (tIndex(proc) != k))208 if ((zIndex(proc) != z)  (cIndex(proc) != c)  (tIndex(proc) != t)) 209 209 { 210 System.out.println("seriesInCorrectOrder()  slices out of order: exp i"+i+" j"+j+" k"+k+" != act z"+210 System.out.println("seriesInCorrectOrder()  slices out of order: exp z"+z+" c"+c+" t"+t+" != act z"+ 211 211 zIndex(proc)+" c"+cIndex(proc)+" t"+tIndex(proc)+" for proc number "+procNum); 212 212 return false; … … 245 245 246 246 return i*65536 + i*256 + i; 247 } 248 249 private boolean floatArraysEqual(float[] a, float[] b) 250 { 251 float tolerance = 0.00001f; 252 253 if (a.length != b.length) return false; 254 255 for (int i = 0; i < a.length; i++) 256 if (Math.abs(a[i]b[i]) > tolerance) 257 return false; 258 259 return true; 247 260 } 248 261 … … 314 327 Axis middle = axis(order,1); 315 328 Axis slowest = axis(order,2); 316 int maxI = value( fastest,z,c,t);329 int maxI = value(slowest,z,c,t); 317 330 int maxJ = value(middle,z,c,t); 318 int maxK = value( slowest,z,c,t);319 for (int k = 0; k < maxK; k++)331 int maxK = value(fastest,z,c,t); 332 for (int i = 0; i < maxI; i++) 320 333 for (int j = 0; j < maxJ; j++) 321 for (int i = 0; i < maxI; i++)334 for (int k = 0; k < maxK; k++) 322 335 { 323 336 ImageProcessor proc = st.getProcessor(count+1); … … 331 344 // ((maxJ*maxI*k) + (maxI*j) + i) 332 345 // ); 333 assertEquals(i,index( fastest,proc));346 assertEquals(i,index(slowest,proc)); 334 347 assertEquals(j,index(middle,proc)); 335 assertEquals(k,index( slowest,proc));348 assertEquals(k,index(fastest,proc)); 336 349 count++; 337 350 } … … 476 489 // TODO  do we need to test something regarding order of images in series 477 490 } 491 fail("unfinished implementation"); 478 492 } 479 493 … … 781 795 // i.e. 6 channels can > 123/456 or 12/34/56 or 1/2/3/4/5/6 (last one not merged ???) 782 796 // 5 channels can > 123/45b or 12/34/5b or 1/2/3/4/5 (last one not merged ???) 797 798 fail("unfinished implementation"); 783 799 } 784 800 … … 841 857 System.out.println("setAutoscale(false) results"); 842 858 h = imp.getStatistics().histogram; 859 // or? h = imp.getProcessor().getHistogram(); 843 860 for (int i = 0; i < h.length/8; i++) 844 861 System.out.println(h[i*8+0]+" "+h[i*8+1]+" "+h[i*8+2]+" "+h[i*8+3]+" "+h[i*8+4]+" "+h[i*8+5]+" "+h[i*8+6]+" "+h[i*8+7]); … … 871 888 System.out.println("setAutoscale(true) results"); 872 889 h = imp.getStatistics().histogram; 890 // or? h = imp.getProcessor().getHistogram(); 873 891 for (int i = 0; i < h.length/8; i++) 874 892 System.out.println(h[i*8+0]+" "+h[i*8+1]+" "+h[i*8+2]+" "+h[i*8+3]+" "+h[i*8+4]+" "+h[i*8+5]+" "+h[i*8+6]+" "+h[i*8+7]); 875 893 876 894 // TODO  test histogram values 895 // question on hist testing  do I need to test specific values or just that it changed? 877 896 878 897 // test that image data unchanged by autoscale … … 884 903 assertEquals(st1Size,st2.getSize()); 885 904 for (int i = 0; i < st1Size; i++) 886 assertEquals(st1.getProcessor(i+1).getPixels(), st2.getProcessor(i+1).getPixels()); 887 // TODO  might need assertArrayEquals() and cast the returned pixels to the appropriate array type. 888 // what is the file type for fakefiles when not specified? byte or int? 889 890 fail("to be implemented"); 905 floatArraysEqual((float[])st1.getProcessor(i+1).getPixels(), (float[])st2.getProcessor(i+1).getPixels()); 906 907 fail("unfinished implementation"); 891 908 } 892 909 … … 901 918 public void testMemoryRecordModifications() 902 919 { 903 // TODO  how to test this? lowest priority 904 905 // outline 906 // open as virt stack 907 // run plugin (invert) or macro that changes pixels in currently loaded frame (frame 0) 908 // change curr frame to 1 and test that pixels are different from what we set 909 // change curr frame back to 0 and see if pixel changes remembered 910 911 fail("to be implemented"); 920 int x = 444, y = 387; 921 String path = constructFakeFilename("memRec", FormatTools.UINT8, x, y, 7, 1, 1, 1); 922 ImagePlus[] imps = null; 923 ImagePlus imp = null; 924 925 assertTrue(y > 10); // needed for this test 926 927 // first test the case where RECORD IS FALSE 928 929 // open file 930 try { 931 ImporterOptions options = new ImporterOptions(); 932 options.setId(path); 933 options.setVirtual(true); 934 options.setRecord(false); 935 imps = BF.openImagePlus(options); 936 } 937 catch (IOException e) { 938 fail(e.getMessage()); 939 } 940 catch (FormatException e) { 941 fail(e.getMessage()); 942 } 943 944 // basic tests 945 assertNotNull(imps); 946 assertEquals(1,imps.length); 947 imp = imps[0]; 948 assertNotNull(imp); 949 assertEquals(x,imp.getWidth()); 950 assertEquals(y,imp.getHeight()); 951 952 // change data in slice 1, swap to slice 2, swap back, see that data DOES revert 953 imp.setSlice(1); 954 assertEquals(0,(int)imp.getProcessor().getPixelValue(0,10)); 955 imp.getProcessor().invert(); 956 assertEquals(255,(int)imp.getProcessor().getPixelValue(0,10)); 957 imp.setSlice(2); 958 assertEquals(0,(int)imp.getProcessor().getPixelValue(0,10)); 959 imp.setSlice(1); 960 assertEquals(0,(int)imp.getProcessor().getPixelValue(0,10)); // when record == false changes not remembered 961 962 // then test case where RECORD IS TRUE 963 964 // open file 965 try { 966 ImporterOptions options = new ImporterOptions(); 967 options.setId(path); 968 options.setVirtual(true); 969 options.setRecord(true); 970 imps = BF.openImagePlus(options); 971 } 972 catch (IOException e) { 973 fail(e.getMessage()); 974 } 975 catch (FormatException e) { 976 fail(e.getMessage()); 977 } 978 979 // basic tests 980 assertNotNull(imps); 981 assertEquals(1,imps.length); 982 imp = imps[0]; 983 assertNotNull(imp); 984 assertEquals(x,imp.getWidth()); 985 assertEquals(y,imp.getHeight()); 986 987 // change data in slice 1, swap to slice 2, swap back, see that data DOES NOT revert 988 imp.setSlice(1); 989 assertEquals(0,(int)imp.getProcessor().getPixelValue(0,10)); 990 imp.getProcessor().invert(); 991 assertEquals(255,(int)imp.getProcessor().getPixelValue(0,10)); 992 imp.setSlice(2); 993 assertEquals(0,(int)imp.getProcessor().getPixelValue(0,10)); 994 imp.setSlice(1); 995 assertEquals(255,(int)imp.getProcessor().getPixelValue(0,10)); // when record == true changes remembered 912 996 } 913 997 … … 977 1061 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 978 1062 979 // test bad combination of zct's  choosing beyond end of z's 980 try { 981 z=7; c=7; t=7; zFrom=3; zTo=7; zBy=4; cFrom=0; cTo=6; cBy=1; tFrom=0; tTo=6; tBy=1; 1063 // test bad combination of zct's  choosing beyond ends of ranges 1064 1065 // z index before 0 begin 1066 try { 1067 z=7; c=7; t=7; zFrom=1; zTo=z1; zBy=1; cFrom=0; cTo=c1; cBy=1; tFrom=0; tTo=t1; tBy=1; 982 1068 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 983 1069 fail(); … … 985 1071 assertTrue(true); 986 1072 } 1073 1074 // z index after z1 end 1075 try { 1076 z=7; c=7; t=7; zFrom=0; zTo=z; zBy=1; cFrom=0; cTo=c1; cBy=1; tFrom=0; tTo=t1; tBy=1; 1077 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1078 fail(); 1079 } catch (IllegalArgumentException e) { 1080 assertTrue(true); 1081 } 1082 1083 // z by < 1 1084 try { 1085 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=0; cFrom=0; cTo=c1; cBy=1; tFrom=0; tTo=t1; tBy=1; 1086 // TODO  enable post fix 1087 //memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1088 //fail(); 1089 } catch (IllegalArgumentException e) { 1090 assertTrue(true); 1091 } 1092 1093 // c index before 0 begin 1094 try { 1095 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=1; cFrom=1; cTo=c1; cBy=1; tFrom=0; tTo=t1; tBy=1; 1096 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1097 fail(); 1098 } catch (IllegalArgumentException e) { 1099 assertTrue(true); 1100 } 1101 1102 // c index after c1 end 1103 try { 1104 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=1; cFrom=0; cTo=c; cBy=1; tFrom=0; tTo=t1; tBy=1; 1105 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1106 fail(); 1107 } catch (IllegalArgumentException e) { 1108 assertTrue(true); 1109 } 1110 1111 // c by < 1 1112 try { 1113 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=1; cFrom=0; cTo=c1; cBy=0; tFrom=0; tTo=t1; tBy=1; 1114 // TODO  enable post fix 1115 //memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1116 //fail(); 1117 } catch (IllegalArgumentException e) { 1118 assertTrue(true); 1119 } 1120 1121 // t index before 0 begin 1122 try { 1123 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=1; cFrom=0; cTo=c1; cBy=1; tFrom=1; tTo=t1; tBy=1; 1124 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1125 fail(); 1126 } catch (IllegalArgumentException e) { 1127 assertTrue(true); 1128 } 1129 1130 // t index after t1 end 1131 try { 1132 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=1; cFrom=0; cTo=c1; cBy=1; tFrom=0; tTo=t; tBy=1; 1133 memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1134 fail(); 1135 } catch (IllegalArgumentException e) { 1136 assertTrue(true); 1137 } 1138 1139 // t by < 1 1140 try { 1141 z=7; c=7; t=7; zFrom=0; zTo=z1; zBy=1; cFrom=0; cTo=c1; cBy=1; tFrom=0; tTo=t1; tBy=0; 1142 // TODO  enable post fix 1143 //memorySpecifyRangeTest(z,c,t,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1144 //fail(); 1145 } catch (IllegalArgumentException e) { 1146 assertTrue(true); 1147 } 987 1148 } 988 1149 … … 1019 1180 1020 1181 // TODO  order of for loops correct? 1021 for (int k = 0; k < 5; k++)1022 for (int j = 0; j < 3; j++)1023 for (int i = 0; i < 7; i++)1182 for (int t = 0; t < 5; t++) 1183 for (int c = 0; c < 3; c++) 1184 for (int z = 0; z < 7; z++) 1024 1185 { 1025 1186 // these next three statements called more times than needed but simplifies for loop logic 1026 ImageStack st = imps[ j].getStack();1187 ImageStack st = imps[c].getStack(); 1027 1188 assertEquals(35,st.getSize()); 1028 ImageProcessor proc = st.getProcessor( j+1);1189 ImageProcessor proc = st.getProcessor(c+1); 1029 1190 // test the values 1030 assertEquals( i,zIndex(proc));1191 assertEquals(z,zIndex(proc)); 1031 1192 assertEquals(0,cIndex(proc)); // this one should always be 0 1032 assertEquals( k,tIndex(proc));1193 assertEquals(t,tIndex(proc)); 1033 1194 } 1034 1195 } … … 1057 1218 1058 1219 // TODO  order of for loops correct? 1059 for (int k = 0; k < 5; k++)1060 for (int j = 0; j < 3; j++)1061 for (int i = 0; i < 7; i++)1220 for (int t = 0; t < 5; t++) 1221 for (int c = 0; c < 3; c++) 1222 for (int z = 0; z < 7; z++) 1062 1223 { 1063 1224 // these next three statements called more times than needed but simplifies for loop logic 1064 ImageStack st = imps[ i].getStack();1225 ImageStack st = imps[z].getStack(); 1065 1226 assertEquals(15,st.getSize()); 1066 ImageProcessor proc = st.getProcessor( i+1);1227 ImageProcessor proc = st.getProcessor(z+1); 1067 1228 // test the values 1068 1229 assertEquals(0,zIndex(proc)); // this one should always be 0 1069 assertEquals( j,cIndex(proc));1070 assertEquals( k,tIndex(proc));1230 assertEquals(c,cIndex(proc)); 1231 assertEquals(t,tIndex(proc)); 1071 1232 } 1072 1233 } … … 1095 1256 1096 1257 // TODO  order of for loops correct? 1097 for (int k = 0; k < 5; k++)1098 for (int j = 0; j < 3; j++)1099 for (int i = 0; i < 7; i++)1258 for (int t = 0; t < 5; t++) 1259 for (int c = 0; c < 3; c++) 1260 for (int z = 0; z < 7; z++) 1100 1261 { 1101 1262 // these next three statements called more times than needed but simplifies for loop logic 1102 ImageStack st = imps[ k].getStack();1263 ImageStack st = imps[t].getStack(); 1103 1264 assertEquals(21,st.getSize()); 1104 ImageProcessor proc = st.getProcessor( k+1);1265 ImageProcessor proc = st.getProcessor(t+1); 1105 1266 // test the values 1106 assertEquals( i,zIndex(proc));1107 assertEquals( j,cIndex(proc));1267 assertEquals(z,zIndex(proc)); 1268 assertEquals(c,cIndex(proc)); 1108 1269 assertEquals(0,tIndex(proc)); // this one should always be 0 1109 1270 }
Note: See TracChangeset
for help on using the changeset viewer.