Skip to content

Commit 3979a50

Browse files
author
Lijun Zhang
committed
IRSA-371:
Updated and added unit test after HistogramProcessor changed showEmptyBin's default
1 parent 1da5141 commit 3979a50

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

src/firefly/java/edu/caltech/ipac/firefly/server/query/HistogramProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,19 @@ public class HistogramProcessor extends IpacTablePartProcessor {
6060
// private final String ALGORITHM = "algorithm";
6161
private final String FALSEPOSTIVERATE = "falsePositiveRate";
6262
private final String PRESERVE_EMPTY_BIN="preserveEmptyBins";
63-
private boolean showEmptyBin= true;
6463
private String algorithm = null;// FIXED_SIZE_ALGORITHM;
65-
private int numBins=0;
6664
private double binWidth=0.0;
6765
private String binSelection=null;
6866
private String binSize;
69-
private double min = Double.NaN;
70-
private double max = Double.NaN;
7167
private String columnExpression;
7268
private double falsePostiveRate = 0.05;
7369

70+
//change to protected so that they can be set by unit test class
71+
protected boolean showEmptyBin= true;
72+
protected int numBins=0;
73+
protected double min = Double.NaN;
74+
protected double max = Double.NaN;
75+
7476

7577
private static String[] getInputFilePath(String inputFileName) {
7678
String[] dirs = inputFileName.split("/");

src/firefly/test/edu/caltech/ipac/firefly/server/query/HistogramProcessorTest.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.caltech.ipac.firefly.server.query;
22
import edu.caltech.ipac.astro.IpacTableException;
33

4+
import edu.caltech.ipac.firefly.ConfigTest;
45
import edu.caltech.ipac.util.DataGroup;
56
import edu.caltech.ipac.util.DataObject;
67
import edu.caltech.ipac.util.DataType;
@@ -13,14 +14,11 @@
1314
/**
1415
* Created by zhang on 10/29/15.
1516
*/
16-
public class HistogramProcessorTest {
17-
18-
17+
public class HistogramProcessorTest extends ConfigTest {
1918

2019

2120
@Test
22-
public void testFixedBinSize() throws DataAccessException {
23-
21+
public void testFixedBinSize() throws DataAccessException {
2422
//create five bin histData
2523
double[] histData = {
2624
0.00000,
@@ -53,8 +51,39 @@ public void testFixedBinSize() throws DataAccessException {
5351
validateResult(expectedDG, outDG);
5452

5553

54+
HistogramProcessor hp1 = new HistogramProcessor();
55+
hp1.setBinNumber(6);
56+
//showEmptyBins = true
57+
double[] histData1 = {
58+
2.70000,
59+
2.50000,
60+
6.00000,
61+
6.20000,
62+
7.00000,
63+
4.05000,
64+
7.10000,
65+
7.30000,
66+
7.40000,
67+
9.8000,
68+
9.20000,
69+
8.50000,
70+
};
71+
hp1.showEmptyBin=true;
72+
hp1.min= 0;
73+
hp1.max = 12;
74+
int[] expectedNumPointsInBin1={0, 2, 1, 6, 3, 0};
75+
double[] expectedBinMin1={0.0, 2, 4, 6.0, 8.0, 10.0};
76+
double[] expectedBinMax1={2, 4, 6, 8, 10, 12};
77+
DataGroup expectedDG1= createDataGroup(expectedNumPointsInBin1, expectedBinMin1, expectedBinMax1);
78+
79+
DataGroup outDG1 = hp1.createHistogramTable(histData1);
80+
81+
validateResult(expectedDG1, outDG1);
82+
83+
5684
}
5785

86+
5887
private void validateResult(DataGroup expected, DataGroup calculated){
5988
for (int i=0; i<expected.size(); i++ ){
6089
Object[] expectedDJ = expected.get(i).getData();
@@ -105,8 +134,6 @@ private DataGroup createDataGroup( int[] numPointInBin, double[] binMin, double[
105134
*
106135
*
107136
*/
108-
109-
110137
public void testVariableBinSize() {
111138

112139
double[] histData = {
@@ -309,7 +336,7 @@ public void testVariableBinSize() {
309336
int nbin=6;
310337
double delta =( max -min)/100*nbin;
311338
//double[] expectedBins={ -14.3997518146, -6.0146658712, 1.1825927451, 2.7383052264, 5.4734012726, 12.938348639};
312-
boolean showEmptyBin=false;
339+
313340

314341
int[] expectedNumPointInBin = {12, 59, 68, 36, 16};
315342

@@ -337,6 +364,9 @@ public void testVariableBinSize() {
337364
try {
338365

339366
HistogramProcessor hp = new HistogramProcessor();
367+
hp.showEmptyBin=false;
368+
369+
//Algorithm=null, the variable bin size is used
340370
DataGroup outDG = hp.createHistogramTable(histData);
341371

342372
DataGroup expectedDG = createDataGroup(expectedNumPointInBin, expectedBinMin, expectedBinMax );
@@ -346,17 +376,6 @@ public void testVariableBinSize() {
346376
catch (Exception ex){
347377
ex.printStackTrace();
348378
}
349-
;
350-
351-
352-
}
353-
public static void main(String args[]) throws IpacTableException, IOException, DataAccessException {
354-
HistogramProcessorTest myTest = new HistogramProcessorTest();
355-
356-
myTest.testFixedBinSize();
357-
myTest.testVariableBinSize();
358-
359-
360379

361380
}
362381

src/firefly/test/edu/caltech/ipac/firefly/server/query/StatisticsProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ public void testStatisticDataArray(){
101101

102102

103103
}
104-
104+
/*
105105
public static void main(String args[]) throws IpacTableException, IOException, DataAccessException, FitsException, ClassNotFoundException {
106106
String fileName = "ipacTableTestFile.tbl";
107107
StatisticsProcessorTest myTest = new StatisticsProcessorTest();
108108
sp = new StatisticsProcessor();
109109
inDg = FileLoader.loadIpacTable(StatisticsProcessor.class, fileName );
110110
myTest.testCreateStatisticTable();
111111
myTest.testStatisticDataArray();
112-
}
112+
}*/
113113

114114
}

0 commit comments

Comments
 (0)