Don't treat inner classes as test classes with ant.
[fits.git] / src / nom / tam / fits / test / TilerTest.java
1 package nom.tam.fits.test;
2
3 import nom.tam.fits.*;
4 import nom.tam.util.*;
5 import nom.tam.image.ImageTiler;
6 import java.io.*;
7
8
9 import org.junit.Test;
10 import static org.junit.Assert.assertEquals;
11 import junit.framework.JUnit4TestAdapter;
12
13 /** This class tests the ImageTiler.  It
14  *  first creates a FITS file and then reads
15  *  it back and allows the user to select
16  *  tiles.  The values of the corner and center
17  *  pixels for the selected tile are displayed.
18  *  Both file and memory tiles are checked.
19  */
20 public class TilerTest {
21
22     void doTile(String test,
23             float[][] data,
24             ImageTiler t,
25             int x, int y, int nx, int ny)
26             throws Exception {
27
28         float[] tile = new float[nx * ny];
29         t.getTile(tile, new int[]{y, x}, new int[]{ny, nx});
30
31
32         float sum0 = 0;
33         float sum1 = 0;
34
35         for (int i = 0; i < nx; i += 1) {
36             for (int j = 0; j < ny; j += 1) {
37                 sum0 += tile[i + j * nx];
38                 sum1 += data[j + y][i + x];
39             }
40         }
41
42         assertEquals("Tiler" + test, sum0, sum1, 0);
43     }
44
45     @Test
46     public void test() throws Exception {
47
48         float[][] data = new float[300][300];
49
50         for (int i = 0; i < 300; i += 1) {
51             for (int j = 0; j < 300; j += 1) {
52                 data[i][j] = 1000 * i + j;
53             }
54         }
55
56         Fits f = new Fits();
57
58         BufferedFile bf = new BufferedFile("tiler1.fits", "rw");
59         f.addHDU(Fits.makeHDU(data));
60
61         f.write(bf);
62         bf.close();
63
64         f = new Fits("tiler1.fits");
65
66         ImageHDU h = (ImageHDU) f.readHDU();
67
68         ImageTiler t = h.getTiler();
69         doTile("t1", data, t, 200, 200, 50, 50);
70         doTile("t2", data, t, 133, 133, 72, 26);
71
72         Object o = h.getData().getKernel();
73         doTile("t3", data, t, 200, 200, 50, 50);
74         doTile("t4", data, t, 133, 133, 72, 26);
75     }
76 }