Skip to content

Commit d761977

Browse files
committed
[mathcore] Fix failure detection of testkdTreeBinning
The test had no failure return code, so errors would go undetected.
1 parent 89c9763 commit d761977

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

math/mathcore/test/testkdTreeBinning.cxx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ using std::cout;
2828
using std::cerr;
2929
using std::endl;
3030

31-
void testkdTreeBinning() {
31+
// Returns the number of detected failures (0 on success) so that the caller can
32+
// turn it into a non-zero process exit code: ROOT's Error() only prints, it does
33+
// not by itself make the test fail under ctest.
34+
int testkdTreeBinning() {
35+
36+
int nfail = 0;
3237

3338
// -----------------------------------------------------------------------------------------------
3439
// C r e a t e r a n d o m s a m p l e
@@ -83,14 +88,22 @@ void testkdTreeBinning() {
8388
std::cout << "Bin with minimum density: " << ibinMin << " density = " << kdBins->GetBinDensity(ibinMin) << " content = " << kdBins->GetBinContent(ibinMin) << std::endl;
8489
std::cout << "Bin with maximum density: " << ibinMax << " density = " << kdBins->GetBinDensity(ibinMax) << " content = " << kdBins->GetBinContent(ibinMax) << std::endl;
8590

86-
if (kdBins->GetBinContent(ibinMax) != DATASZ/NBINS)
91+
if (kdBins->GetBinContent(ibinMax) != DATASZ/NBINS) {
8792
Error("testkdTreeBinning","Wrong bin content");
93+
++nfail;
94+
}
8895

8996
// order bins by density
9097
kdBins->SortBinsByDensity(true);
9198

92-
if (kdBins->GetBinMinDensity() != 0) Error("testkdTreeBinning","Wrong minimum bin after sorting");
93-
if (kdBins->GetBinMaxDensity() != nbins-1) Error("testkdTreeBinning","Wrong maximum bin after sorting");
99+
if (kdBins->GetBinMinDensity() != 0) {
100+
Error("testkdTreeBinning","Wrong minimum bin after sorting");
101+
++nfail;
102+
}
103+
if (kdBins->GetBinMaxDensity() != nbins-1) {
104+
Error("testkdTreeBinning","Wrong maximum bin after sorting");
105+
++nfail;
106+
}
94107

95108
if (showGraphics) {
96109
new TCanvas();
@@ -104,7 +117,6 @@ void testkdTreeBinning() {
104117
double point[2] = {0,0};
105118
// double binCenter[2];
106119
gRandom->SetSeed(0);
107-
bool ok = true;
108120
for (int itimes = 0; itimes < ntimes; itimes++) {
109121

110122
// generate a random point in 2D
@@ -126,12 +138,13 @@ void testkdTreeBinning() {
126138
std::cout << " point y " << point[1] << " BIN CENTER is " << binCenter[1] << " min " << binMin[1] << " max " << binMax[1] << std::endl;
127139
}
128140

129-
ok &= point[0] > binMin[0] && point[0] < binMax[0];
130-
ok &= point[1] > binMin[1] && point[1] < binMax[1];
141+
bool ok = point[0] > binMin[0] && point[0] < binMax[0] &&
142+
point[1] > binMin[1] && point[1] < binMax[1];
131143
if (!ok) {
132144
Error ("testkdTreeBinning::FindBin"," Point is not in the right bin " );
133145
std::cout << " point x " << point[0] << " BIN CENTER is " << binCenter[0] << " min " << binMin[0] << " max " << binMax[0] << std::endl;
134146
std::cout << " point y " << point[1] << " BIN CENTER is " << binCenter[1] << " min " << binMin[1] << " max " << binMax[1] << std::endl;
147+
++nfail;
135148
}
136149

137150
if (itimes < 2 && showGraphics ) {
@@ -144,13 +157,15 @@ void testkdTreeBinning() {
144157

145158
delete [] binCenter;
146159
}
147-
else
160+
else {
148161
Error("testkdTreeBinning::FindBin"," Bin %d is not existing ",ibin);
162+
++nfail;
163+
}
149164

150165

151166
}
152167

153-
return;
168+
return nfail;
154169

155170
}
156171

@@ -180,7 +195,7 @@ int main(int argc, char **argv)
180195
if ( showGraphics )
181196
theApp = new TApplication("App",&argc,argv);
182197

183-
testkdTreeBinning();
198+
int nfail = testkdTreeBinning();
184199

185200
if ( showGraphics )
186201
{
@@ -189,7 +204,7 @@ int main(int argc, char **argv)
189204
theApp = nullptr;
190205
}
191206

192-
return 0;
207+
return nfail;
193208

194209
}
195210

0 commit comments

Comments
 (0)