Skip to content

Commit f23c8aa

Browse files
committed
Extend stressGraphics to accept minimal deviations
For parallelcoord() test Mac platform make difference in one line from 30K - value 0.621 replaced by 0.620. Deviation caused by random generator. To keep testing working for such use case allow minimal deviation of single digit in the line for maximal 5 lines.
1 parent e65ed50 commit f23c8aa

File tree

1 file changed

+74
-24
lines changed

1 file changed

+74
-24
lines changed

test/stressGraphics.cxx

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100

101101

102102
const int kMaxNumTests = 70;
103-
const int kSkipSvgTest = 10;
103+
const int kFineSvgTest = 10; // SVG file can slightly vary
104+
const int kSkipSvgTest = 100; // do not perform SVG test
104105

105106
// Global variables.
106107
Int_t gVerbose = 0;
@@ -161,8 +162,8 @@ std::map<int, RefEntry> gRef;
161162
struct TestEntry {
162163
Int_t TestNum = 0;
163164
TString title, psfile, ps2file, pdffile, jpgfile, pngfile, svgfile, ccode;
164-
Bool_t execute_ccode = kFALSE, testsvg = kFALSE;
165-
Int_t IPS = 0;
165+
Bool_t execute_ccode = kFALSE;
166+
Int_t IPS = 0, testsvg = 0;
166167
};
167168

168169
std::vector<TestEntry> gReports;
@@ -265,23 +266,67 @@ Int_t FileSize(const TString &filename)
265266
}
266267
}
267268

268-
Bool_t CompareSVGFiles(const TString &filename1, const TString &filename2)
269+
////////////////////////////////////////////////////////////////////////////////
270+
/// Check if deviation in SVG line significant or can be ignored
271+
272+
bool SpecialCompareOfSVGLines(const std::string &line1, const std::string &line2)
273+
{
274+
if (line1.length() != line2.length())
275+
return false;
276+
277+
int npos = -1;
278+
279+
// for now allow only one single deviation deviation
280+
for (size_t i = 0; i < line1.length(); ++i) {
281+
if (line1[i] != line2[i]) {
282+
if (npos < 0)
283+
npos = i;
284+
else
285+
return false;
286+
}
287+
}
288+
289+
if (npos < 0)
290+
return true;
291+
292+
auto extract_float = [npos](const std::string &s) {
293+
int n = npos;
294+
while ((n > 0) && ((s[n]>='0' && s[n] <= '9') || (s[n] == '.') || (s[n] == '-'))) n--;
295+
float res;
296+
if (sscanf(s.c_str() + n + 1, "%f", &res) != 1)
297+
res = 0.;
298+
return res;
299+
};
300+
301+
auto v1 = extract_float(line1);
302+
auto v2 = extract_float(line2);
303+
304+
if (!v1 || !v2 || (v1*v2 < 0))
305+
return false;
306+
307+
return (TMath::Abs(v2 - v1) / (v2 + v1) < 0.01);
308+
}
309+
310+
////////////////////////////////////////////////////////////////////////////////
311+
/// Special compare of SVG files
312+
313+
Int_t CompareSVGFiles(const TString &filename1, const TString &filename2, int testsvg)
269314
{
270315
std::ifstream f1(filename1.Data());
271316
if (!f1) {
272317
printf("FAILURE to open %s\n", filename1.Data());
273-
return kFALSE;
318+
return 0;
274319
}
275320

276321
std::ifstream f2(filename2.Data());
277322
if (!f2) {
278323
printf("FAILURE to open %s\n", filename2.Data());
279-
return kFALSE;
324+
return 0;
280325
}
281326

282327
std::string line1, line2;
283328

284-
int cnt = 0, diffcnt = 0;
329+
int cnt = 0, diffcnt = 0, finediffcnt = 0;
285330

286331
while (std::getline(f1, line1) && std::getline(f2, line2)) {
287332
++cnt;
@@ -300,28 +345,31 @@ Bool_t CompareSVGFiles(const TString &filename1, const TString &filename2)
300345
printf("\n");
301346
printf("Ref: %s\n", line1.substr(0, 200).c_str());
302347
printf("New: %s\n", line2.substr(0, 200).c_str());
303-
if (++diffcnt > 5)
304-
return kFALSE;
348+
if ((testsvg == kFineSvgTest) && SpecialCompareOfSVGLines(line1, line2)) {
349+
if (finediffcnt++ > 5)
350+
return 0;
351+
} else if (++diffcnt > 5)
352+
return 0;
305353
}
306354

307355
if (diffcnt > 0)
308-
return kFALSE;
356+
return 0;
309357

310358
if (!f1.eof()) {
311359
printf("FAILURE ref file %s still has content\n", filename1.Data());
312360
printf("Diff in line %d\n", cnt);
313361
printf("Ref: %s\n", line1.substr(0, 200).c_str());
314-
return kFALSE;
362+
return 0;
315363
}
316364

317365
if (std::getline(f2, line2) || !f2.eof()) {
318366
printf("FAILURE new file %s still has content\n", filename2.Data());
319367
printf("Diff in line %d\n", cnt);
320368
printf("New: %s\n", line2.substr(0, 200).c_str());
321-
return kFALSE;
369+
return 0;
322370
}
323371

324-
return kTRUE;
372+
return (finediffcnt > 0) ? kFineSvgTest : 1;
325373
}
326374

327375

@@ -387,10 +435,10 @@ void TestReport(TCanvas *C, const TString &title, const TString &arg = "", Int_t
387435
TestEntry e;
388436
e.TestNum = gTestNum;
389437
e.title = title;
390-
e.testsvg = IPS < kSkipSvgTest;
391-
if (!e.testsvg) IPS -= kSkipSvgTest;
438+
if (IPS < kSkipSvgTest)
439+
e.testsvg = (IPS < kFineSvgTest) ? 1 : kFineSvgTest;
392440

393-
e.IPS = gWebMode ? 1 : IPS; // check only size of web SVG files
441+
e.IPS = gWebMode ? 1 : IPS % 10; // check only size of web SVG files
394442
e.psfile = TString::Format("%s1_%2.2d.%s", filePrefix, e.TestNum, main_extension);
395443
e.ps2file = TString::Format("%s2_%2.2d.%s", filePrefix, e.TestNum, main_extension);
396444
e.pdffile = TString::Format("%s%2.2d.pdf", filePrefix, e.TestNum);
@@ -496,9 +544,9 @@ void print_reports()
496544

497545
if (gSvgMode) {
498546

499-
Bool_t res = kTRUE;
547+
Int_t res = 1;
500548
if (e.testsvg)
501-
res = CompareSVGFiles(gSvgRefPath + e.svgfile, e.svgfile);
549+
res = CompareSVGFiles(gSvgRefPath + e.svgfile, e.svgfile, e.testsvg);
502550

503551
if (!res) {
504552
auto filesize = FileSize(e.svgfile);
@@ -514,10 +562,12 @@ void print_reports()
514562
std::cout << ".";
515563

516564
if (res) {
517-
if (e.testsvg)
518-
std::cout << " OK\n";
519-
else
565+
if (!e.testsvg)
520566
std::cout << " SKIP\n";
567+
else if (res == kFineSvgTest)
568+
std::cout << " NEAR\n";
569+
else
570+
std::cout << " OK\n";
521571
if (!gOptionK)
522572
gSystem->Unlink(e.svgfile);
523573
} else {
@@ -2832,21 +2882,21 @@ void parallelcoord()
28322882
{
28332883
TCanvas *C = StartTest(800,700);
28342884

2835-
TNtuple *ntuple = (TNtuple*)gHsimple->Get("ntuple");
2885+
auto ntuple = static_cast<TNtuple *>(gHsimple->Get("ntuple"));
28362886

28372887
C->Divide(1,2);
28382888

28392889
C->cd(1);
28402890
ntuple->Draw("px:py:pz:random:px*py*pz","","para");
2841-
TParallelCoord* para = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject("ParaCoord");
2891+
auto para = static_cast<TParallelCoord *> (gPad->GetListOfPrimitives()->FindObject("ParaCoord"));
28422892
para->SetLineColor(25);
28432893
TColor *col25 = gROOT->GetColor(25);
28442894
if (col25) col25->SetAlpha(0.05);
28452895

28462896
C->cd(2);
28472897
ntuple->Draw("px:py:pz:random:px*py*pz","","candle");
28482898

2849-
TestReport(C, "Parallel Coordinates");
2899+
TestReport(C, "Parallel Coordinates", "", kFineSvgTest);
28502900

28512901
if (col25) col25->SetAlpha(1.);
28522902
}

0 commit comments

Comments
 (0)