Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/ojs/ojs-define-precision.test.ts
6438 views
1
import { docs, outputForInput } from "../../utils.ts";
2
import { assert } from "testing/asserts";
3
import { testRender } from "../render/render.ts";
4
import { verifyOjsDefine } from "../../verify.ts";
5
6
// Test for #13958: ojs_define() rounds numbers incorrectly
7
// Test across all three execution engines: knitr, jupyter, julia
8
const engines = ["knitr", "jupyter", "julia"];
9
10
for (const engine of engines) {
11
const input = docs(`ojs/ojs-define-numeric-precision/with-${engine}.qmd`);
12
const output = outputForInput(input, "html");
13
14
testRender(
15
input,
16
"html",
17
false,
18
[
19
verifyOjsDefine(async (contents) => {
20
const numEntry = contents.find((item) => item.name === "num");
21
assert(numEntry, "Should find 'num' variable in ojs-define data");
22
assert(
23
typeof numEntry.value === "number",
24
"ojs-define value should be a number"
25
);
26
27
// Validate numeric precision (the actual bug test)
28
const expected = 0.00008604168504168504;
29
const tolerance = 1e-15; // Machine epsilon tolerance
30
31
const diff = Math.abs(numEntry.value - expected);
32
assert(
33
diff < tolerance,
34
`ojs-define value should preserve full precision. Expected ${expected}, got ${numEntry.value}, diff ${diff}`
35
);
36
}, `ojs_define preserves full numeric precision (${engine})`)(output.outputPath),
37
],
38
);
39
}
40
41