MCPcopy
hub / github.com/josdejong/mathjs / ex

Function ex

test/unit-tests/expression/node/OperatorNode.test.js:226–241  ·  view source on GitHub ↗
(example, parens = ['keep', 'auto'])

Source from the content-addressed store, hash-verified

224 // Takes optional 2nd argument that gives the list of paren values to try,
225 // defaults to ['keep', 'auto']
226 function ex (example, parens = ['keep', 'auto']) {
227 const hasi = 'i' in example
228 const expr = hasi ? math.parse(example.i) : example.n
229 const orig = hasi
230 ? example.i
231 : `${expr.getIdentifier()}${expr.args.map(arg => arg.getIdentifier())}`
232 for (const paren of parens) {
233 const prefix = `${orig},${paren}: ` // eases reading of failure output
234 const skey = 's' in example ? 's' : 's' + paren
235 const lkey = 'l' in example ? 'l' : 'l' + paren
236 assert.strictEqual(
237 prefix + expr.toString({ parenthesis: paren }), prefix + example[skey])
238 assert.strictEqual(
239 prefix + expr.toTex({ parenthesis: paren }), prefix + example[lkey])
240 }
241 }
242
243 describe('toString and toTex', function () {
244 it('on an OperatorNode', function () {

Callers 1

Calls 5

parseMethod · 0.65
mapMethod · 0.65
toStringMethod · 0.65
toTexMethod · 0.65
getIdentifierMethod · 0.45

Tested by

no test coverage detected