Adding new expression tests.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a01b7a17ef
commit
2594fd6844
9 changed files with 274 additions and 62 deletions
|
@ -48,7 +48,7 @@ describe("Module/Latex", function() {
|
|||
})
|
||||
|
||||
describe("#requestAsyncRender", function() {
|
||||
it("should return a render result with a valid source, a width, and a height", async function() {
|
||||
it("returns a render result with a valid source, a width, and a height", async function() {
|
||||
const data = await LatexAPI.requestAsyncRender("\\frac{x}{3}", 13, "#AA0033")
|
||||
expect(data).to.be.an("object")
|
||||
expect(data.source).to.be.a("string")
|
||||
|
@ -57,7 +57,7 @@ describe("Module/Latex", function() {
|
|||
expect(data.width).to.be.a("number")
|
||||
})
|
||||
|
||||
it("should call functions from the LaTeX module", async function() {
|
||||
it("calls functions from the LaTeX module", async function() {
|
||||
const renderSyncSpy = spy.on(Latex, "renderSync")
|
||||
const renderAsyncSpy = spy.on(Latex, "renderAsync")
|
||||
Latex.supportsAsyncRender = true
|
||||
|
@ -84,7 +84,7 @@ describe("Module/Latex", function() {
|
|||
})
|
||||
|
||||
describe("#findPrerendered", function() {
|
||||
it("should return the same data as async render for the same markup, font size, and color", async function() {
|
||||
it("returns the same data as async render for the same markup, font size, and color", async function() {
|
||||
const data = await LatexAPI.requestAsyncRender("\\frac{x}{3}", 13, "#AA0033")
|
||||
const found = LatexAPI.findPrerendered("\\frac{x}{3}", 13, "#AA0033")
|
||||
expect(found).to.not.be.null
|
||||
|
@ -92,7 +92,7 @@ describe("Module/Latex", function() {
|
|||
expect(found.width).to.equal(data.width)
|
||||
})
|
||||
|
||||
it("should return null if the markup hasn't been prerendered with the same markup, font size, and color", async function() {
|
||||
it("returns null if the markup hasn't been prerendered with the same markup, font size, and color", async function() {
|
||||
await LatexAPI.requestAsyncRender("\\frac{x}{3}", 13, "#AA0033")
|
||||
expect(LatexAPI.findPrerendered("\\frac{y}{3}", 13, "#AA0033")).to.be.null
|
||||
expect(LatexAPI.findPrerendered("\\frac{x}{3}", 12, "#AA0033")).to.be.null
|
||||
|
@ -101,7 +101,7 @@ describe("Module/Latex", function() {
|
|||
})
|
||||
|
||||
describe("#par", function() {
|
||||
it("should add parentheses to strings", function() {
|
||||
it("adds parentheses to strings", function() {
|
||||
expect(LatexAPI.par("string")).to.equal("(string)")
|
||||
expect(LatexAPI.par("aaaa")).to.equal("(aaaa)")
|
||||
expect(LatexAPI.par("")).to.equal("()")
|
||||
|
@ -110,14 +110,14 @@ describe("Module/Latex", function() {
|
|||
})
|
||||
|
||||
describe("#parif", function() {
|
||||
it("should add parentheses to strings that contain one of the ones in the list", function() {
|
||||
it("adds parentheses to strings that contain one of the ones in the list", function() {
|
||||
expect(LatexAPI.parif("string", ["+"])).to.equal("string")
|
||||
expect(LatexAPI.parif("string+assert", ["+"])).to.equal("(string+assert)")
|
||||
expect(LatexAPI.parif("string+assert", ["+", "-"])).to.equal("(string+assert)")
|
||||
expect(LatexAPI.parif("string-assert", ["+", "-"])).to.equal("(string-assert)")
|
||||
})
|
||||
|
||||
it("shouldn't add new parentheses to strings that contains one of the ones in the list if they already have one", function() {
|
||||
it("doesn't add new parentheses to strings that contains one of the ones in the list if they already have one", function() {
|
||||
expect(LatexAPI.parif("(string+assert", ["+"])).to.equal("((string+assert)")
|
||||
expect(LatexAPI.parif("string+assert)", ["+"])).to.equal("(string+assert))")
|
||||
expect(LatexAPI.parif("(string+assert)", ["+"])).to.equal("(string+assert)")
|
||||
|
@ -125,14 +125,14 @@ describe("Module/Latex", function() {
|
|||
expect(LatexAPI.parif("(string-assert)", ["+", "-"])).to.equal("(string-assert)")
|
||||
})
|
||||
|
||||
it("shouldn't add parentheses to strings that does not contains one of the ones in the list", function() {
|
||||
it("doesn't add parentheses to strings that does not contains one of the ones in the list", function() {
|
||||
expect(LatexAPI.parif("string", ["+"])).to.equal("string")
|
||||
expect(LatexAPI.parif("string+assert", ["-"])).to.equal("string+assert")
|
||||
expect(LatexAPI.parif("(string*assert", ["+", "-"])).to.equal("(string*assert")
|
||||
expect(LatexAPI.parif("string/assert)", ["+", "-"])).to.equal("string/assert)")
|
||||
})
|
||||
|
||||
it("should remove parentheses from strings that does not contains one of the ones in the list", function() {
|
||||
it("removes parentheses from strings that does not contains one of the ones in the list", function() {
|
||||
expect(LatexAPI.parif("(string)", ["+"])).to.equal("string")
|
||||
expect(LatexAPI.parif("(string+assert)", ["-"])).to.equal("string+assert")
|
||||
expect(LatexAPI.parif("((string*assert)", ["+", "-"])).to.equal("(string*assert")
|
||||
|
@ -164,47 +164,47 @@ describe("Module/Latex", function() {
|
|||
"{}_{4}", "{}_{5}", "{}_{6}", "{}_{7}", "{}_{8}", "{}_{9}", "{}_{0}",
|
||||
"\\pi", "\\infty"]
|
||||
|
||||
it("should convert unicode characters to their latex equivalent", function() {
|
||||
it("converts unicode characters to their latex equivalent", function() {
|
||||
for(let i = 0; i < from.length; i++)
|
||||
expect(LatexAPI.variable(from[i])).to.include(to[i])
|
||||
})
|
||||
|
||||
it("should wrap within dollar signs when the option is included", function() {
|
||||
it("wraps within dollar signs when the option is included", function() {
|
||||
for(let i = 0; i < from.length; i++) {
|
||||
expect(LatexAPI.variable(from[i], false)).to.equal(to[i])
|
||||
expect(LatexAPI.variable(from[i], true)).to.equal(`$${to[i]}$`)
|
||||
}
|
||||
})
|
||||
|
||||
it("should be able to convert multiple of them", function() {
|
||||
it("can convert multiple of them", function() {
|
||||
expect(LatexAPI.variable("α₂", false)).to.equal("\\alpha{}_{2}")
|
||||
expect(LatexAPI.variable("∞piΠ", false)).to.equal("\\infty\\pi\\Pi")
|
||||
})
|
||||
})
|
||||
|
||||
describe("#functionToLatex", function() {
|
||||
it("should transform derivatives into latex fractions", function() {
|
||||
it("transforms derivatives into latex fractions", function() {
|
||||
const d1 = LatexAPI.functionToLatex("derivative", ["'3t'", "'t'", "x+2"])
|
||||
const d2 = LatexAPI.functionToLatex("derivative", ["f", "x+2"])
|
||||
expect(d1).to.equal("\\frac{d3x}{dx}")
|
||||
expect(d2).to.equal("\\frac{df}{dx}(x+2)")
|
||||
})
|
||||
|
||||
it("should transform integrals into latex limits", function() {
|
||||
it("transforms integrals into latex limits", function() {
|
||||
const i1 = LatexAPI.functionToLatex("integral", ["0", "x", "'3y'", "'y'"])
|
||||
const i2 = LatexAPI.functionToLatex("integral", ["1", "2", "f"])
|
||||
expect(i1).to.equal("\\int\\limits_{0}^{x}3y dy")
|
||||
expect(i2).to.equal("\\int\\limits_{1}^{2}f(t) dt")
|
||||
})
|
||||
|
||||
it("should transform sqrt functions to sqrt latex", function() {
|
||||
it("transforms sqrt functions to sqrt latex", function() {
|
||||
const sqrt1 = LatexAPI.functionToLatex("sqrt", ["(x+2)"])
|
||||
const sqrt2 = LatexAPI.functionToLatex("sqrt", ["\\frac{x}{2}"])
|
||||
expect(sqrt1).to.equal("\\sqrt{x+2}")
|
||||
expect(sqrt2).to.equal("\\sqrt{\\frac{x}{2}}")
|
||||
})
|
||||
|
||||
it("should transform abs, floor and ceil", function() {
|
||||
it("transforms abs, floor and ceil", function() {
|
||||
const abs = LatexAPI.functionToLatex("abs", ["x+3"])
|
||||
const floor = LatexAPI.functionToLatex("floor", ["x+3"])
|
||||
const ceil = LatexAPI.functionToLatex("ceil", ["x+3"])
|
||||
|
@ -213,7 +213,7 @@ describe("Module/Latex", function() {
|
|||
expect(ceil).to.equal("\\left\\lceil{x+3}\\right\\rceil")
|
||||
})
|
||||
|
||||
it("should transform regular functions into latex", function() {
|
||||
it("transforms regular functions into latex", function() {
|
||||
const f1 = LatexAPI.functionToLatex("f", ["x+3", true])
|
||||
const f2 = LatexAPI.functionToLatex("h_1", ["10"])
|
||||
expect(f1).to.equal("\\mathrm{f}\\left(x+3, true\\right)")
|
||||
|
@ -222,7 +222,7 @@ describe("Module/Latex", function() {
|
|||
})
|
||||
|
||||
describe("#expression", function() {
|
||||
it("should transform parsed expressions", function() {
|
||||
it("transforms parsed expressions", function() {
|
||||
const expr = ExprEval.parse("(+1! == 2/2 ? sin [-2.2][0] : f(t)^(1+1-1) + sqrt(A.t)) * 3 % 1")
|
||||
const expected = "((((+1!))==(\\frac{2}{2}) ? (\\mathrm{sin}\\left(([(-2.2)][0])\\right)) : (\\mathrm{f}\\left(t\\right)^{1+1-1}+\\sqrt{A.t})) \\times 3) \\mathrm{mod} 1"
|
||||
expect(LatexAPI.expression(expr.tokens)).to.equal(expected)
|
||||
|
|
|
@ -26,5 +26,6 @@ import { expect } from "chai"
|
|||
// import Objects from "../../src/module/objects.mjs"
|
||||
//
|
||||
// describe("Module/Objects", function() {
|
||||
//
|
||||
// describe("#getNewName", function() {
|
||||
// })
|
||||
// })
|
Loading…
Add table
Add a link
Reference in a new issue