Path: blob/main/tests/smoke/ojs/ojs-define-precision.test.ts
6438 views
import { docs, outputForInput } from "../../utils.ts";1import { assert } from "testing/asserts";2import { testRender } from "../render/render.ts";3import { verifyOjsDefine } from "../../verify.ts";45// Test for #13958: ojs_define() rounds numbers incorrectly6// Test across all three execution engines: knitr, jupyter, julia7const engines = ["knitr", "jupyter", "julia"];89for (const engine of engines) {10const input = docs(`ojs/ojs-define-numeric-precision/with-${engine}.qmd`);11const output = outputForInput(input, "html");1213testRender(14input,15"html",16false,17[18verifyOjsDefine(async (contents) => {19const numEntry = contents.find((item) => item.name === "num");20assert(numEntry, "Should find 'num' variable in ojs-define data");21assert(22typeof numEntry.value === "number",23"ojs-define value should be a number"24);2526// Validate numeric precision (the actual bug test)27const expected = 0.00008604168504168504;28const tolerance = 1e-15; // Machine epsilon tolerance2930const diff = Math.abs(numEntry.value - expected);31assert(32diff < tolerance,33`ojs-define value should preserve full precision. Expected ${expected}, got ${numEntry.value}, diff ${diff}`34);35}, `ojs_define preserves full numeric precision (${engine})`)(output.outputPath),36],37);38}394041