Public
Edited
Mar 28
Insert cell
Insert cell
Insert cell
viewof table = Inputs.table(errorTable)
Insert cell
{
const names = Object.keys(math.expression.mathWithTransform);

const docsHelp = names.map((name) => {
try {
return math.help(name);
} catch (err) {
return null;
}
});

const originalConfig = math.config();

function testExamples(examples) {
math.config(originalConfig);
try {
math.evaluate(examples);
return true;
} catch {
return false;
}
}

const failingTests = [];
docsHelp.forEach((x) => {
if (x !== null && !testExamples(x.doc.examples))
failingTests.push(x.doc.name);
});

return failingTests;
}
Insert cell
math = require("mathjs@12.4.3")
Insert cell
skipNames = ["addScalar", "divideScalar", "equalScalar", "multiplyScalar", "subtractScalar", "apply", "replacer", "reviver"]
Insert cell
namesToTest = Object.keys(math.expression.mathWithTransform).filter(name => !skipNames.includes(name))
Insert cell
evaluateHelpString = namesToTest.map(name => {try{return math.evaluate(`help("${name}")`).toString()} catch (err){return err.toString()}})
Insert cell
helpString = namesToTest.map(name => {try{return math.help(name).toString()} catch (err){return err.toString()}})
Insert cell
evaluateHelpString.filter((doc, i) => doc !== helpString[i])
Insert cell
math.help("partitionSelect")
Insert cell
Insert cell
errorTable = {
const examplesWithError = [];
let m = math.create();
let parser = m.parser();
for (const name in math) {
let hasExamples;
let examples;
let isFunction;
try {
isFunction = typeof parser.evaluate(name) === "function" ? true : false;
} catch (error) {
isFunction = false;
}
if (isFunction) {
try {
examples = math.evaluate(`help(${name})`).doc.examples;
hasExamples = examples ? true : false;
} catch (error) {
hasExamples = false;
}
if (hasExamples) {
let hasError;
let result;
try {
parser.clear();
result = parser.evaluate(examples);
hasError = false;
} catch (error) {
try {
// config (and maybe others) mutates m and causes good examples to fail
// m = math.create();
parser = math.parser();
result = parser.evaluate(examples);
hasError = false;
} catch (error) {
result = error.toString();
hasError = true;
}
}
if (hasError) examplesWithError.push({ name, examples, result });
} else {
// if there are no examples in docs
examplesWithError.push({
name,
examples: null,
result: "Unavailable examples"
});
}
}
}
return examplesWithError;
}
Insert cell
{
const parserFunctions = [];
for (const name in math) {
try {
if (typeof math.evaluate(name) === "function") {
parserFunctions.push(name);
}
} catch (error) {}
}
return parserFunctions;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more