Skip to content

Commit 5bd6352

Browse files
committed
Check json conversion in build3d.js
1 parent d583611 commit 5bd6352

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

demo/node/build3d.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { httpRequest, create, openFile, treeDraw, build3d } from 'jsroot';
22

3-
async function test3d(obj, opt, title) {
3+
async function test3d(obj, opt, title, json_reflength = -1) {
44
if (!obj) {
55
console.error(`No object provided for ${title}`);
66
return null;
@@ -13,7 +13,15 @@ async function test3d(obj, opt, title) {
1313
return null;
1414
}
1515

16-
console.log(`${title} Ok`);
16+
if (json_reflength <= 0)
17+
console.log(`${title} Ok`);
18+
else {
19+
let json = JSON.stringify(obj3d.toJSON());
20+
if (Math.abs(json.length - json_reflength) / json_reflength > 0.01)
21+
console.error(`${title} FAILURE json ${json.length} too much differ from refernce ${json_reflength}`);
22+
else
23+
console.log(`${title} OK json ${json.length}`);
24+
}
1725

1826
return obj3d;
1927
}
@@ -26,19 +34,19 @@ let server = 'https://root.cern/js/files/',
2634
let file = await openFile(filename);
2735
let hist2 = await file.readObject('hpxpy');
2836

29-
await test3d(hist2, 'lego2', 'TH2 lego plot');
37+
await test3d(hist2, 'lego2', 'TH2 lego plot', 6916869);
3038

3139
let tuple = await file.readObject('ntuple');
3240
let hist3 = await treeDraw(tuple, 'px:py:pz;hbins:15');
3341

34-
await test3d(hist3, 'box3', 'TH3 box plot');
42+
await test3d(hist3, 'box3', 'TH3 box plot', 4223457);
3543

3644
let hist1 = await file.readObject('hpx');
3745

38-
await test3d(hist1, 'lego2', 'TH1 lego plot');
46+
await test3d(hist1, 'lego2', 'TH1 lego plot', 3332953);
3947

4048
let geom = await httpRequest(filename3, 'object');
41-
await test3d(geom, '', 'Geometry build');
49+
await test3d(geom, '', 'Geometry build', 1811230);
4250

4351
let file2 = await openFile(filename2);
4452
let gr2 = await file2.readObject('Graph2D');
@@ -51,4 +59,4 @@ latex.fTextAlign = 22;
5159
latex.fTextColor = 3;
5260
latex.fTextSize = 10;
5361

54-
await test3d(latex, '', 'TLatex drawing');
62+
await test3d(latex, '', 'TLatex drawing', 457275);

0 commit comments

Comments
 (0)