diff --git a/packages/doenetml-worker/src/components/Parabola.js b/packages/doenetml-worker/src/components/Parabola.js index 64e3b568b..8927b1569 100644 --- a/packages/doenetml-worker/src/components/Parabola.js +++ b/packages/doenetml-worker/src/components/Parabola.js @@ -477,6 +477,28 @@ export default class Parabola extends Curve { return { setValue: { numericalPrescribedVertex: [x, y] } }; }, + + inverseDefinition({ + desiredStateVariableValues, + dependencyValues, + }) { + if (dependencyValues.prescribedVertex === null) { + return { success: false }; + } + + return { + success: true, + instructions: [ + { + setDependency: "prescribedVertex", + desiredValue: me.fromAst([ + "vector", + ...desiredStateVariableValues.numericalPrescribedVertex, + ]), + }, + ], + }; + }, }; stateVariableDefinitions.pointsAreNumerical = { @@ -597,13 +619,16 @@ export default class Parabola extends Curve { realValued: true, }, }; - } else { - // vertex and at least one point prescribed. - // use the first point and ignore the remaining + } else if ( + dependencyValues.numericalThroughPoints.length === 1 + ) { + // vertex and one point prescribed. // create parabola y = a*(x-x1)^2 + y1 // where a is determined by the first point + // if point is on top of vertex, then ignore it + let v = dependencyValues.numericalPrescribedVertex; let x1 = v[0]; let y1 = v[1]; @@ -612,17 +637,38 @@ export default class Parabola extends Curve { let x2 = p1[0]; let y2 = p1[1]; - a = (y2 - y1) / (x2 - x1) ** 2; - b = -2 * a * x1; - c = a * x1 * x1 + y1; + if (x1 === x2) { + if (y1 == y2) { + a = dependencyValues.aShadow; + b = -2 * a * x1; + c = a * x1 ** 2 + y1; + } else { + realValued = false; + a = NaN; + b = NaN; + c = NaN; + } + } else { + a = (y2 - y1) / (x2 - x1) ** 2; + b = -2 * a * x1; + c = a * x1 * x1 + y1; + } + return { setValue: { a, b, c, realValued } }; + } else { + let warning = { + message: + "Haven't implemented parabola with vertex through more than 1 point.", + level: 1, + }; return { setValue: { - a, - b, - c, - realValued: true, + a: NaN, + b: NaN, + c: NaN, + realValued: false, }, + sendWarnings: [warning], }; } } @@ -876,6 +922,83 @@ export default class Parabola extends Curve { } }; + if (dependencyValues.numericalPrescribedVertex) { + if (dependencyValues.numericalThroughPoints.length === 0) { + // just vertex + // move it to be at vertex with new parameter values + // modify a if changed + + let a = await getWorkingParameterValue("a"); + let b = await getWorkingParameterValue("b"); + let c = await getWorkingParameterValue("c"); + + let x1 = -b / (2 * a); + let y1 = c - (b * b) / (4 * a); + + let instructions = [ + { + setDependency: "numericalPrescribedVertex", + desiredValue: [x1, y1], + }, + ]; + + if (desiredNumericalValues.a !== undefined) { + instructions.push({ + setDependency: "aShadow", + desiredValue: desiredNumericalValues.a, + }); + } + + return { + success: true, + instructions, + }; + } else { + // vertex and one point prescribed + + // Move vertex to be at the new vertex. + // Translate the point horizontally by the amount vertex moved + // and move point vertical to parabola + + let a = await getWorkingParameterValue("a"); + let b = await getWorkingParameterValue("b"); + let c = await getWorkingParameterValue("c"); + + let vx = -b / (2 * a); + let vy = c - (b * b) / (4 * a); + + let dx = + vx - dependencyValues.numericalPrescribedVertex[0]; + + let px = + dependencyValues.numericalThroughPoints[0][0] + dx; + let py = a * px * px + b * px + c; + + let instructions = [ + { + setDependency: "numericalPrescribedVertex", + desiredValue: [vx, vy], + }, + { + setDependency: "numericalThroughPoints", + desiredValue: [[px, py]], + }, + ]; + + if (desiredNumericalValues.a !== undefined) { + instructions.push({ + setDependency: "aShadow", + desiredValue: desiredNumericalValues.a, + }); + } + + return { + success: true, + instructions, + }; + } + } + if (dependencyValues.numericalThroughPoints.length === 0) { let instructions = []; diff --git a/packages/doenetml-worker/src/test/tagSpecific/parabola.test.ts b/packages/doenetml-worker/src/test/tagSpecific/parabola.test.ts new file mode 100644 index 000000000..f4361d773 --- /dev/null +++ b/packages/doenetml-worker/src/test/tagSpecific/parabola.test.ts @@ -0,0 +1,963 @@ +import { describe, expect, it, vi } from "vitest"; +import { createTestCore, returnAllStateVariables } from "../utils/test-core"; +import { + moveControlVector, + movePoint, + moveThroughPoint, + updateMathInputValue, + updateTextInputValue, +} from "../utils/actions"; +import Core from "../../Core"; +import me from "math-expressions"; + +const Mock = vi.fn(); +vi.stubGlobal("postMessage", Mock); +vi.mock("hyperformula"); + +async function setupScene(parabolaML: string) { + let core = await createTestCore({ + doenetML: + ` + +` + + parabolaML + + ` + + + + $p1{name="p2"} + $v1{name="v2"} + +$g2{name="g3" newNamespace} + +$p2.equation{assignNames="e2"} + +

a =

+

b =

+

c =

+ +

a2 =

+

b2 =

+

c2 =

+ + `, + }); + + return core; +} + +function calc_pars_from_points({ + points, + have_vertex = false, + old_pars, +}: { + points: number[][]; + have_vertex?: boolean; + old_pars?: { a: number; b: number; c: number }; +}) { + let a: number, b: number, c: number; + + // deduplicate points + points = points.filter( + (v, i) => + !points.slice(0, i).some((u) => u[0] === v[0] && u[1] === v[1]), + ); + + if (points.length === 0) { + if (old_pars) { + a = old_pars.a; + b = old_pars.b; + c = old_pars.c; + } else { + a = 1; + b = 0; + c = 0; + } + } else if (points.length === 1) { + // one given point is the vertex + // (doesn't matter if have_vertex is true) + let x1 = points[0][0]; + let y1 = points[0][1]; + if (old_pars) { + a = old_pars.a; + } else { + a = 1; + } + b = -2 * a * x1; + c = a * x1 ** 2 + y1; + } else if (points.length === 2) { + let x1 = points[0][0]; + let x2 = points[1][0]; + let y1 = points[0][1]; + let y2 = points[1][1]; + + if (have_vertex) { + a = (y2 - y1) / (x2 - x1) ** 2; + b = -2 * a * x1; + c = a * x1 * x1 + y1; + } else { + if (old_pars) { + a = old_pars.a; + } else { + a = 1; + } + + b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); + c = y1 - a * x1 ** 2 - b * x1; + } + } else { + let x1 = points[0][0]; + let x2 = points[1][0]; + let x3 = points[2][0]; + let y1 = points[0][1]; + let y2 = points[1][1]; + let y3 = points[2][1]; + + let x12 = x1 * x1; + let x22 = x2 * x2; + let x32 = x3 * x3; + + let u1 = x12 - x32; + let u2 = x22 - x32; + + let v1 = x1 - x3; + let v2 = x2 - x3; + + let z1 = y1 - y3; + let z2 = y2 - y3; + + let det = u1 * v2 - u2 * v1; + + a = (z1 * v2 - z2 * v1) / det; + b = (z2 * u1 - z1 * u2) / det; + c = y1 - b * x1 - a * x12; + } + + if (!(Number.isFinite(a) && Number.isFinite(b) && Number.isFinite(c))) { + a = NaN; + b = NaN; + c = NaN; + } + return [a, b, c]; +} + +function adjust_points_from_pars({ + a, + b, + c, + points, + have_vertex, +}: { + a: number; + b: number; + c: number; + points: number[][]; + have_vertex: boolean; +}) { + if (points.length === 1) { + let vertex_x = -b / (2 * a); + let vertex_y = c - b ** 2 / (4 * a); + points[0] = [vertex_x, vertex_y]; + } else if (have_vertex) { + let vertex_x = -b / (2 * a); + let vertex_y = c - b ** 2 / (4 * a); + let dx = vertex_x - points[0][0]; + let p1x = points[1][0] + dx; + points[0] = [vertex_x, vertex_y]; + points[1] = [p1x, a * p1x ** 2 + b * p1x + c]; + } else { + for (let pt of points) { + pt[1] = a * pt[0] ** 2 + b * pt[0] + c; + } + } +} + +async function runTests({ + core, + points = [], + vertex, +}: { + core: Core; + points?: number[][]; + vertex?: number[]; +}) { + let names = [ + ["/p1", "/v1"], + ["/p2", "/v2"], + ["/g3/p2", "/g3/v2"], + ]; + + let have_vertex = vertex !== undefined; + if (vertex !== undefined) { + points = [vertex, ...points]; + } + + let [a, b, c] = calc_pars_from_points({ points, have_vertex }); + + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // Change a + a = -2; + await updateMathInputValue({ latex: `${a}`, name: "/a", core }); + adjust_points_from_pars({ a, b, c, points, have_vertex }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // change b + b = 3; + await updateMathInputValue({ latex: `${b}`, name: "/b", core }); + adjust_points_from_pars({ a, b, c, points, have_vertex }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // change c + c = 9; + await updateMathInputValue({ latex: `${c}`, name: "/c", core }); + adjust_points_from_pars({ a, b, c, points, have_vertex }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // Change a2 + a = 0.2; + await updateMathInputValue({ latex: `${a}`, name: "/a2", core }); + adjust_points_from_pars({ a, b, c, points, have_vertex }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // change b2 + b = -1.7; + await updateMathInputValue({ latex: `${b}`, name: "/b2", core }); + adjust_points_from_pars({ a, b, c, points, have_vertex }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // change c2 + c = -4.5; + await updateMathInputValue({ latex: `${c}`, name: "/c2", core }); + adjust_points_from_pars({ a, b, c, points, have_vertex }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // move vertices + let vertexValues = [ + [-2, 1], + [5, -6], + [-3, -2], + ]; + for (let [ind, namePair] of names.entries()) { + let vertexName = namePair[1]; + let values = vertexValues[ind]; + let vertex_x = values[0]; + let vertex_y = values[1]; + await movePoint({ name: vertexName, x: vertex_x, y: vertex_y, core }); + + let b = -2 * a * vertex_x; + let c = vertex_y + a * vertex_x * vertex_x; + adjust_points_from_pars({ a, b, c, points, have_vertex }); + + await checkAllParabolaValues({ names, a, b, c, points, core }); + } + + if (points.length === 0) { + return; + } + + // move points + let last_specified_pars = { a, b, c }; + + points = [ + [-4, 7], + [0, -2], + [-9, 2], + ].slice(0, points.length); + for (let [ind, pt] of points.entries()) { + await movePoint({ name: `/P${ind + 1}`, x: pt[0], y: pt[1], core }); + } + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + if (points.length === 1) { + return; + } + + // move points on top of each other, become vertex + points = points.map((_) => [3, -9]); + + for (let [ind, pt] of points.entries()) { + await movePoint({ name: `/P${ind + 1}`, x: pt[0], y: pt[1], core }); + } + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // move one point above others, parabola becomes undefined + points[0][1] = -3; + await movePoint({ name: `/P1`, y: points[0][1], core }); + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // move that point apart + points[0][0] = 5; + await movePoint({ name: `/P1`, x: points[0][0], core }); + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + if (points.length === 2) { + return; + } + + // change point grouping (so point 2 is the one apart) + points[0] = [3, -9]; + points[1] = [4, -9]; + for (let [ind, pt] of points.slice(0, 2).entries()) { + await movePoint({ name: `/P${ind + 1}`, x: pt[0], y: pt[1], core }); + } + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // change point grouping (so point 3 is the one apart) + points[1] = [3, -9]; + points[2] = [5, 4]; + for (let [ind, pt] of points.entries()) { + if (ind == 0) { + continue; + } + await movePoint({ name: `/P${ind + 1}`, x: pt[0], y: pt[1], core }); + } + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // move all points above each other, parabola undefined + points = [ + [5, 1], + [5, 2], + [5, 3], + ]; + for (let [ind, pt] of points.entries()) { + await movePoint({ name: `/P${ind + 1}`, x: pt[0], y: pt[1], core }); + } + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); + + // move points apart + points = [ + [-5, -9], + [-4, 1], + [0, 1], + ]; + for (let [ind, pt] of points.entries()) { + await movePoint({ name: `/P${ind + 1}`, x: pt[0], y: pt[1], core }); + } + [a, b, c] = calc_pars_from_points({ + points, + have_vertex, + old_pars: last_specified_pars, + }); + await checkAllParabolaValues({ names, a, b, c, points, core }); +} + +async function checkAllParabolaValues({ + names, + a, + b, + c, + points, + core, +}: { + names: string[][]; + a: number; + b: number; + c: number; + points: number[][]; + core: Core; +}) { + for (let namePair of names) { + await checkParabolaValues({ + name: namePair[0], + vertexName: namePair[1], + a, + b, + c, + core, + }); + } + + const stateVariables = await returnAllStateVariables(core); + for (let [i, pt] of points.entries()) { + expect(stateVariables[`/P${i + 1}`].stateValues.xs[0].tree).closeTo( + pt[0], + 1e-12, + ); + expect(stateVariables[`/P${i + 1}`].stateValues.xs[1].tree).closeTo( + pt[1], + 1e-12, + ); + } +} + +async function checkParabolaValues({ + name, + vertexName, + a, + b, + c, + core, +}: { + name: string; + vertexName: string; + a: number; + b: number; + c: number; + core: Core; +}) { + let vertex_x = -b / (2 * a); + let vertex_y = c - b ** 2 / (4 * a); + + const stateVariables = await returnAllStateVariables(core); + + if (Number.isFinite(a) && Number.isFinite(b) && Number.isFinite(c)) { + expect(stateVariables[name].stateValues.a).closeTo(a, 1e-12); + expect(stateVariables[name].stateValues.b).closeTo(b, 1e-12); + expect(stateVariables[name].stateValues.c).closeTo(c, 1e-12); + + let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); + expect( + stateVariables[name].stateValues.equation.equals( + equationExpression, + ), + ).eq(true); + expect( + stateVariables["/e2"].stateValues.value.equals(equationExpression), + ).eq(true); + } else { + expect(stateVariables[name].stateValues.a).eqls(NaN); + expect(stateVariables[name].stateValues.b).eqls(NaN); + expect(stateVariables[name].stateValues.c).eqls(NaN); + } + if (Number.isFinite(vertex_x)) { + expect( + stateVariables[name].stateValues.vertex[0].evaluate_numbers().tree, + ).closeTo(vertex_x, 1e-12); + expect( + stateVariables[vertexName].stateValues.xs[0].evaluate_numbers() + .tree, + ).closeTo(vertex_x, 1e-12); + } else { + expect( + stateVariables[name].stateValues.vertex[0].evaluate_numbers().tree, + ).eq("\uff3f"); + expect( + stateVariables[vertexName].stateValues.xs[0].evaluate_numbers() + .tree, + ).eq("\uff3f"); + } + if (Number.isFinite(vertex_y)) { + expect( + stateVariables[name].stateValues.vertex[1].evaluate_numbers().tree, + ).closeTo(vertex_y, 1e-12); + expect( + stateVariables[vertexName].stateValues.xs[1].evaluate_numbers() + .tree, + ).closeTo(vertex_y, 1e-12); + } else { + expect( + stateVariables[name].stateValues.vertex[1].evaluate_numbers().tree, + ).eq("\uff3f"); + expect( + stateVariables[vertexName].stateValues.xs[1].evaluate_numbers() + .tree, + ).eq("\uff3f"); + } +} + +describe("Parabola Tag Tests", async () => { + it("parabola with no parameters gives y=x^2", async () => { + let core = await setupScene(``); + + await runTests({ core }); + }); + + it("parabola through no points gives y=x^2", async () => { + let core = await setupScene(``); + + await runTests({ core }); + }); + + it("parabola through one point uses it as vertex", async () => { + let core = await setupScene(` + (1,2) + `); + + await runTests({ core, points: [[1, 2]] }); + }); + + it("parabola through two points", async () => { + let core = await setupScene(` + (1,2) + (3,4) + `); + + await runTests({ + core, + points: [ + [1, 2], + [3, 4], + ], + }); + }); + + it("parabola through three points", async () => { + let core = await setupScene(` + (1,2) + (3,4) + (5,6) + `); + + await runTests({ + core, + points: [ + [1, 2], + [3, 4], + [5, 6], + ], + }); + }); + + it("warning with parabola through four points", async () => { + let core = await createTestCore({ + doenetML: ` + + + + + `, + }); + + let errorWarnings = core.errorWarnings; + + expect(errorWarnings.errors.length).eq(0); + expect(errorWarnings.warnings.length).eq(1); + + expect(errorWarnings.warnings[0].message).contain( + `Haven't implemented parabola through more than 3 points`, + ); + expect(errorWarnings.warnings[0].level).eq(1); + expect(errorWarnings.warnings[0].doenetMLrange.lineBegin).eq(3); + expect(errorWarnings.warnings[0].doenetMLrange.charBegin).eq(5); + expect(errorWarnings.warnings[0].doenetMLrange.lineEnd).eq(3); + expect(errorWarnings.warnings[0].doenetMLrange.charEnd).eq(50); + }); + + it("parabola with prescribed vertex", async () => { + let core = await setupScene(` + (1,2) + `); + + await runTests({ core, vertex: [1, 2] }); + }); + + it("parabola with prescribed vertex and through point", async () => { + let core = await setupScene(` + (1,2) + (3,4) + `); + + await runTests({ core, points: [[3, 4]], vertex: [1, 2] }); + }); + + it("warning with parabola with vertex and two points", async () => { + let core = await createTestCore({ + doenetML: ` + + + + + `, + }); + + let errorWarnings = core.errorWarnings; + + expect(errorWarnings.errors.length).eq(0); + expect(errorWarnings.warnings.length).eq(1); + + expect(errorWarnings.warnings[0].message).contain( + `Haven't implemented parabola with vertex through more than 1 point`, + ); + expect(errorWarnings.warnings[0].level).eq(1); + expect(errorWarnings.warnings[0].doenetMLrange.lineBegin).eq(3); + expect(errorWarnings.warnings[0].doenetMLrange.charBegin).eq(5); + expect(errorWarnings.warnings[0].doenetMLrange.lineEnd).eq(3); + expect(errorWarnings.warnings[0].doenetMLrange.charEnd).eq(53); + }); + + it("constrain to parabola", async () => { + let core = await createTestCore({ + doenetML: ` + + + + + $p + + + + + $p{name="p2"} + $A{name="A2"} + + $g2{name="g3" newNamespace} + `, + }); + + let f_p = (x) => (x - 1) ** 2 + 2; + + async function check_items(xMin: number, xMax: number) { + const stateVariables = await returnAllStateVariables(core); + const [x1, x2] = stateVariables["/A"].stateValues.xs.map( + (v) => v.tree, + ); + const [x12, x22] = stateVariables["/A2"].stateValues.xs.map( + (v) => v.tree, + ); + const [x13, x23] = stateVariables["/g3/A2"].stateValues.xs.map( + (v) => v.tree, + ); + expect(x1).greaterThan(xMin).lessThan(xMax); + expect(x2).closeTo(f_p(x1), 1e-14); + expect(x12).eq(x1); + expect(x13).eq(x1); + expect(x22).eq(x2); + expect(x23).eq(x2); + } + + await check_items(0, 1); + + await movePoint({ name: "/A", x: 9, y: -2, core }); + await check_items(0, 9); + + await movePoint({ name: "/A2", x: -9, y: 4, core }); + await check_items(-9, 0); + + await movePoint({ name: "/g3/A2", x: 0.9, y: 9, core }); + await check_items(-10, 0.9); + + await movePoint({ name: "/g3/A2", x: 1.1, y: 9, core }); + await check_items(1.11, 10); + }); + + it("constrain to parabola opening downward", async () => { + let core = await createTestCore({ + doenetML: ` + + + + + $p + + + + + $p{name="p2"} + $A{name="A2"} + + $g2{name="g3" newNamespace} + `, + }); + + let f_p = (x) => -((x - 1) ** 2 + 2); + + async function check_items(xMin: number, xMax: number) { + const stateVariables = await returnAllStateVariables(core); + const [x1, x2] = stateVariables["/A"].stateValues.xs.map( + (v) => v.tree, + ); + const [x12, x22] = stateVariables["/A2"].stateValues.xs.map( + (v) => v.tree, + ); + const [x13, x23] = stateVariables["/g3/A2"].stateValues.xs.map( + (v) => v.tree, + ); + expect(x1).greaterThan(xMin).lessThan(xMax); + expect(x2).closeTo(f_p(x1), 1e-14); + expect(x12).eq(x1); + expect(x13).eq(x1); + expect(x22).eq(x2); + expect(x23).eq(x2); + } + + await check_items(0, 1); + + await movePoint({ name: "/A", x: 9, y: 2, core }); + await check_items(0, 9); + + await movePoint({ name: "/A2", x: -9, y: -4, core }); + await check_items(-9, 0); + + await movePoint({ name: "/g3/A2", x: 0.9, y: -9, core }); + await check_items(-10, 0.9); + + await movePoint({ name: "/g3/A2", x: 1.1, y: -9, core }); + await check_items(1.11, 10); + }); + + it("constrain to parabola that is a line", async () => { + let core = await createTestCore({ + doenetML: ` + + + + + $p + + + + + $p{name="p2"} + $A{name="A2"} + + $g2{name="g3" newNamespace} + `, + }); + + let f_p = (x) => 0.5 * x + 1.5; + + async function check_items(x: number) { + const stateVariables = await returnAllStateVariables(core); + const [x1, x2] = stateVariables["/A"].stateValues.xs.map( + (v) => v.tree, + ); + const [x12, x22] = stateVariables["/A2"].stateValues.xs.map( + (v) => v.tree, + ); + const [x13, x23] = stateVariables["/g3/A2"].stateValues.xs.map( + (v) => v.tree, + ); + expect(x1).closeTo(x, 1e-14); + expect(x2).closeTo(f_p(x1), 1e-14); + expect(x12).eq(x1); + expect(x13).eq(x1); + expect(x22).eq(x2); + expect(x23).eq(x2); + } + + await check_items(1.5 / -2.5); + + await movePoint({ name: "/A", x: 9, y: -2, core }); + await check_items((1.5 - 2 * 9 + 2) / -2.5); + + await movePoint({ name: "/A2", x: -9, y: 4, core }); + await check_items((1.5 + 2 * 9 - 4) / -2.5); + + await movePoint({ name: "/g3/A2", x: 0.9, y: 9, core }); + await check_items((1.5 - 2 * 0.9 - 9) / -2.5); + }); + + it("constrain to parabola opening downward, different axis scales", async () => { + let core = await createTestCore({ + doenetML: ` + + + + + $p + + + + + $p{name="p2"} + $A{name="A2"} + + $g2{name="g3" ymin="-1000" ymax="1000" newNamespace} + `, + }); + + let f_p = (x) => -100 * ((x - 1) ** 2 + 2); + + async function check_items(xMin: number, xMax: number) { + const stateVariables = await returnAllStateVariables(core); + const [x1, x2] = stateVariables["/A"].stateValues.xs.map( + (v) => v.tree, + ); + const [x12, x22] = stateVariables["/A2"].stateValues.xs.map( + (v) => v.tree, + ); + const [x13, x23] = stateVariables["/g3/A2"].stateValues.xs.map( + (v) => v.tree, + ); + expect(x1).greaterThan(xMin).lessThan(xMax); + expect(x2).closeTo(f_p(x1), 1e-12); + expect(x12).eq(x1); + expect(x13).eq(x1); + expect(x22).eq(x2); + expect(x23).eq(x2); + } + + await check_items(0, 1); + + await movePoint({ name: "/A", x: 9, y: 200, core }); + await check_items(0, 9); + + await movePoint({ name: "/A2", x: -9, y: -400, core }); + await check_items(-9, 0); + + await movePoint({ name: "/g3/A2", x: 0.9, y: -900, core }); + await check_items(-10, 0.9); + + await movePoint({ name: "/g3/A2", x: 1.1, y: -900, core }); + await check_items(1.11, 10); + + await movePoint({ name: "/A", x: 9, y: 0, core }); + await check_items(2, 10); + + await movePoint({ name: "/A2", x: -9, y: 100, core }); + await check_items(-10, 0); + }); + + it("copy parabola and overwrite parameters", async () => { + let core = await createTestCore({ + doenetML: ` + + + $p0{vertex="(3,4)" name="p1"} + $p1{through="(5,-4)" name="p2"} + $p0{through="(-5,-2)" name="p3"} + $p3{vertex="(-6,6)" name="p4"} + + + $g1{name="g2"} + + `, + }); + + let stateVariables = await returnAllStateVariables(core); + + expect(stateVariables["/g1/p0"].stateValues.a).closeTo(1, 1e-12); + expect(stateVariables["/g1/p0"].stateValues.b).closeTo(0, 1e-12); + expect(stateVariables["/g1/p0"].stateValues.c).closeTo(0, 1e-12); + expect(stateVariables["/g2/p0"].stateValues.a).closeTo(1, 1e-12); + expect(stateVariables["/g2/p0"].stateValues.b).closeTo(0, 1e-12); + expect(stateVariables["/g2/p0"].stateValues.c).closeTo(0, 1e-12); + + expect(stateVariables["/g1/p1"].stateValues.a).closeTo(1, 1e-12); + expect(stateVariables["/g1/p1"].stateValues.b).closeTo(-6, 1e-12); + expect(stateVariables["/g1/p1"].stateValues.c).closeTo(13, 1e-12); + expect(stateVariables["/g2/p1"].stateValues.a).closeTo(1, 1e-12); + expect(stateVariables["/g2/p1"].stateValues.b).closeTo(-6, 1e-12); + expect(stateVariables["/g2/p1"].stateValues.c).closeTo(13, 1e-12); + + expect(stateVariables["/g1/p2"].stateValues.a).closeTo(-2, 1e-12); + expect(stateVariables["/g1/p2"].stateValues.b).closeTo(12, 1e-12); + expect(stateVariables["/g1/p2"].stateValues.c).closeTo(-14, 1e-12); + expect(stateVariables["/g2/p2"].stateValues.a).closeTo(-2, 1e-12); + expect(stateVariables["/g2/p2"].stateValues.b).closeTo(12, 1e-12); + expect(stateVariables["/g2/p2"].stateValues.c).closeTo(-14, 1e-12); + + expect(stateVariables["/g1/p3"].stateValues.a).closeTo(1, 1e-12); + expect(stateVariables["/g1/p3"].stateValues.b).closeTo(10, 1e-12); + expect(stateVariables["/g1/p3"].stateValues.c).closeTo(23, 1e-12); + expect(stateVariables["/g2/p3"].stateValues.a).closeTo(1, 1e-12); + expect(stateVariables["/g2/p3"].stateValues.b).closeTo(10, 1e-12); + expect(stateVariables["/g2/p3"].stateValues.c).closeTo(23, 1e-12); + + expect(stateVariables["/g1/p4"].stateValues.a).closeTo(-8, 1e-12); + expect(stateVariables["/g1/p4"].stateValues.b).closeTo(-96, 1e-12); + expect(stateVariables["/g1/p4"].stateValues.c).closeTo(-282, 1e-12); + expect(stateVariables["/g2/p4"].stateValues.a).closeTo(-8, 1e-12); + expect(stateVariables["/g2/p4"].stateValues.b).closeTo(-96, 1e-12); + expect(stateVariables["/g2/p4"].stateValues.c).closeTo(-282, 1e-12); + }); + + it("copy propIndex of points, dot and array notation", async () => { + let core = await createTestCore({ + doenetML: ` + + + + +

+ +

+ +

+ +

+ `, + }); + + let t1x = 2, + t1y = -3; + let t2x = 3, + t2y = 4; + let t3x = -3, + t3y = 4; + + let stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/P1"]).eq(undefined); + expect(stateVariables["/P2"]).eq(undefined); + expect(stateVariables["/P3"]).eq(undefined); + expect(stateVariables["/x"]).eq(undefined); + expect(stateVariables["/xa"]).eq(undefined); + + await updateMathInputValue({ latex: "1", name: "/n", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/P1"].stateValues.xs.map((v) => v.tree)).eqls([ + t1x, + t1y, + ]); + expect(stateVariables["/P2"]).eq(undefined); + expect(stateVariables["/P3"]).eq(undefined); + expect(stateVariables["/x"].stateValues.value.tree).eq(t2x); + expect(stateVariables["/xa"].stateValues.value.tree).eq(t2x); + + await updateMathInputValue({ latex: "2", name: "/n", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/P1"].stateValues.xs.map((v) => v.tree)).eqls([ + t2x, + t2y, + ]); + expect(stateVariables["/P2"]).eq(undefined); + expect(stateVariables["/P3"]).eq(undefined); + expect(stateVariables["/x"].stateValues.value.tree).eq(t2y); + expect(stateVariables["/xa"].stateValues.value.tree).eq(t2y); + + await updateMathInputValue({ latex: "3", name: "/n", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/P1"].stateValues.xs.map((v) => v.tree)).eqls([ + t3x, + t3y, + ]); + expect(stateVariables["/P2"]).eq(undefined); + expect(stateVariables["/P3"]).eq(undefined); + expect(stateVariables["/x"]).eq(undefined); + expect(stateVariables["/xa"]).eq(undefined); + + await updateMathInputValue({ latex: "4", name: "/n", core }); + stateVariables = await returnAllStateVariables(core); + expect(stateVariables["/P1"]).eq(undefined); + expect(stateVariables["/P2"]).eq(undefined); + expect(stateVariables["/P3"]).eq(undefined); + expect(stateVariables["/x"]).eq(undefined); + expect(stateVariables["/xa"]).eq(undefined); + }); +}); diff --git a/packages/test-cypress/cypress/e2e/tagSpecific/parabola.cy.js b/packages/test-cypress/cypress/e2e/tagSpecific/parabola.cy.js deleted file mode 100644 index 5df0ff1a9..000000000 --- a/packages/test-cypress/cypress/e2e/tagSpecific/parabola.cy.js +++ /dev/null @@ -1,15226 +0,0 @@ -import me from "math-expressions"; -import { cesc, cesc2 } from "@doenet/utils"; - -function nInDOM(n) { - if (n < 0) { - return `−${Math.abs(n)}`; - } else { - return String(n); - } -} - -describe("Parabola Tag Tests", function () { - beforeEach(() => { - cy.clearIndexedDB(); - cy.visit("/"); - }); - - it("parabola with no parameters gives y=x^2", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - $_parabola1.vertex{assignNames="v"} - - - $_parabola1{name="p2"} - $v{name="v2"} - - $g2{name="g3" newNamespace} - - $p2.equation{assignNames="e2"} - -

a =

-

b =

-

c =

- -

a2 =

-

b2 =

-

c2 =

- - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - cy.window().then(async (win) => { - let a = 1, - b = 0, - c = 0; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=x2"); - }); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change a"); - cy.get(cesc("#\\/a") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 0, - c = 0; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=−2x2"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change b"); - cy.get(cesc("#\\/b") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 0; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=−2x2+3x"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change c"); - cy.get(cesc("#\\/c") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}9{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+9"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=−2x2+3x+9"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change a2"); - cy.get(cesc("#\\/a2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}0.2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = 3, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2+3x+9"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=0.2x2+3x+9"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-1.7{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2−1.7x+9"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=0.2x2−1.7x+9"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change c2"); - cy.get(cesc("#\\/c2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-4.5{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = -4.5; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should( - "contain.text", - "y=0.2x2−1.7x−4.5", - ); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=0.2x2−1.7x−4.5"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = 0.2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex2"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - await win.callAction1({ - actionName: "movePoint", - componentName: "/v2", - args: { x: 5, y: -6 }, - }); - - let a = 0.2; - - let vertex_x = 5; - let vertex_y = -6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex3"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/v2", - args: { x: -3, y: -2 }, - }); - - let a = 0.2; - - let vertex_x = -3; - let vertex_y = -2; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - }); - }); - - it("parabola through no points gives y=x^2", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - $_parabola1.vertex{assignNames="v"} - - - $_parabola1{name="p2"} - $v{name="v2"} - - $g2{name="g3" newNamespace} - - $p2.equation{assignNames="e2"} - -

a =

-

b =

-

c =

- -

a2 =

-

b2 =

-

c2 =

- - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - cy.window().then(async (win) => { - let a = 1, - b = 0, - c = 0; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=x2"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change a"); - cy.get(cesc("#\\/a") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 0, - c = 0; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2"); - - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=−2x2"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change b"); - cy.get(cesc("#\\/b") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 0; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=−2x2+3x"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change c"); - cy.get(cesc("#\\/c") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}9{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+9"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=−2x2+3x+9"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change a2"); - cy.get(cesc("#\\/a2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}0.2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = 3, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2+3x+9"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=0.2x2+3x+9"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-1.7{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2−1.7x+9"); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=0.2x2−1.7x+9"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change c2"); - cy.get(cesc("#\\/c2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-4.5{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = -4.5; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.get(cesc2("#/e2")).should( - "contain.text", - "y=0.2x2−1.7x−4.5", - ); - cy.get(cesc2("#/e2")) - .find(".mjx-mrow") - .eq(0) - .invoke("text") - .then((text) => { - expect(text.trim()).equal("y=0.2x2−1.7x−4.5"); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = 0.2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex2"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v2", - args: { x: 5, y: -6 }, - }); - - let a = 0.2; - - let vertex_x = 5; - let vertex_y = -6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex3"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/v2", - args: { x: -3, y: -2 }, - }); - - let a = 0.2; - - let vertex_x = -3; - let vertex_y = -2; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - }); - }); - - it("parabola through one point uses it as vertex", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - (1,2) - - $_parabola1.vertex{assignNames="v"} - - - $_parabola1{name="p2"} - $v{name="v2"} - - $g2{name="g3" newNamespace} - - $p2.equation{assignNames="e2"} - -

a =

-

b =

-

c =

- -

a2 =

-

b2 =

-

c2 =

- - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - cy.window().then(async (win) => { - let a = 1, - b = -2, - c = 3; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change a"); - cy.get(cesc("#\\/a") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = -2, - c = 3; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2−2x+3"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change b"); - cy.get(cesc("#\\/b") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 3; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+3"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change c"); - cy.get(cesc("#\\/c") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}9{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change a2"); - cy.get(cesc("#\\/a2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}0.2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = 3, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2+3x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-1.7{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = 9; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2−1.7x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("Change c2"); - cy.get(cesc("#\\/c2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-4.5{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = -4.5; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should( - "contain.text", - "y=0.2x2−1.7x−4.5", - ); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = 0.2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move vertex2"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v2", - args: { x: 5, y: -6 }, - }); - - let a = 0.2; - - let vertex_x = 5; - let vertex_y = -6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - - cy.log("move point defining vertex"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: 2, y: 6 }, - }); - - let a = 0.2; - - let vertex_x = 2; - let vertex_y = 6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - }); - }); - }); - }); - - it("parabola through two points", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - (1,2) - (3,4) - - $_parabola1.vertex{assignNames="v"} - - - $_parabola1{name="p2"} - $v{name="v2"} - - $g2{name="g3" newNamespace} - - $p2.equation{assignNames="e2"} - -

a =

-

b =

-

c =

- -

a2 =

-

b2 =

-

c2 =

- - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - cy.get(cesc2("#/e2")).should("contain.text", "y=x2−3x+4"); - - cy.window().then(async (win) => { - let x1 = 1, - x2 = 3; - let y1 = 2, - y2 = 4; - - let a = 1; - - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("Change a"); - cy.get(cesc("#\\/a") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - // first calculate old values of parameters - let x1 = 1, - x2 = 3; - let y1 = 2, - y2 = 4; - - let a = 1; - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - a = -2; - - // revise y1 and y2 for new value of a - y1 = a * x1 ** 2 + b * x1 + c; - y2 = a * x2 ** 2 + b * x2 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2−3x+4"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("Change b"); - cy.get(cesc("#\\/b") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - // first calculate old values of parameters - let x1 = 1, - x2 = 3; - let y1 = 2, - y2 = 4; - - let a = 1; - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - (a = -2), (b = 3); - - // revise y1 and y2 for new values of a and b - y1 = a * x1 ** 2 + b * x1 + c; - y2 = a * x2 ** 2 + b * x2 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+4"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("Change c"); - cy.get(cesc("#\\/c") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}9{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("Change a2"); - cy.get(cesc("#\\/a2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}0.2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = 3, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2+3x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-1.7{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2−1.7x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("Change c2"); - cy.get(cesc("#\\/c2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-4.5{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = -4.5; - - // calculate point locations - let x1 = 1, - x2 = 3; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should( - "contain.text", - "y=0.2x2−1.7x−4.5", - ); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = 0.2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - // calculate point locations - let x1 = 1, - x2 = 3; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("move vertex2"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v2", - args: { x: 5, y: -6 }, - }); - - let a = 0.2; - - let vertex_x = 5; - let vertex_y = -6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - // calculate point locations - let x1 = 1, - x2 = 3; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("move both points"); - cy.window().then(async (win) => { - let x1 = -4, - x2 = 0; - let y1 = 7, - y2 = -2; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("move points on top of each other, become vertex"); - cy.window().then(async (win) => { - let x1 = 3, - x2 = 3; - let y1 = -9, - y2 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let vertex_x = x1; - let vertex_y = y1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("move points above each other, parabola undefined"); - cy.window().then(async (win) => { - let x1 = -4, - x2 = -4; - let y1 = -9, - y2 = 1; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - assert.isNaN(stateVariables["/_parabola1"].stateValues.a); - assert.isNaN(stateVariables["/_parabola1"].stateValues.b); - assert.isNaN(stateVariables["/_parabola1"].stateValues.c); - expect( - stateVariables["/_parabola1"].stateValues.vertex, - ).eqls(["\uff3f", "\uff3f"]); - expect(stateVariables["/v"].stateValues.xs[0]).eq("\uff3f"); - expect(stateVariables["/v"].stateValues.xs[1]).eq("\uff3f"); - assert.isNaN(stateVariables["/p2"].stateValues.a); - assert.isNaN(stateVariables["/p2"].stateValues.b); - assert.isNaN(stateVariables["/p2"].stateValues.c); - expect(stateVariables["/p2"].stateValues.vertex).eqls([ - "\uff3f", - "\uff3f", - ]); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - assert.isNaN(stateVariables["/g3/p2"].stateValues.a); - assert.isNaN(stateVariables["/g3/p2"].stateValues.b); - assert.isNaN(stateVariables["/g3/p2"].stateValues.c); - expect(stateVariables["/g3/p2"].stateValues.vertex).eqls([ - "\uff3f", - "\uff3f", - ]); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - - cy.log("move points apart"); - cy.window().then(async (win) => { - let x1 = 4, - x2 = -6; - let y1 = 5, - y2 = 8; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - }); - }); - }); - }); - - it("parabola through three points", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - (1,2) - (3,4) - (5,6) - - $_parabola1.vertex{assignNames="v"} - - - $_parabola1{name="p2"} - $v{name="v2"} - - $g2{name="g3" newNamespace} - - $p2.equation{assignNames="e2"} - -

a =

-

b =

-

c =

- -

a2 =

-

b2 =

-

c2 =

- - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - cy.window().then(async (win) => { - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = 2, - y2 = 4, - y3 = 6; - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - stateVariables["/_parabola1"].stateValues.vertex[0], - ).eq("\uff3f"); - expect( - stateVariables["/_parabola1"].stateValues.vertex[1], - ).eq("\uff3f"); - expect(stateVariables["/v"].stateValues.xs[0]).eq("\uff3f"); - expect(stateVariables["/v"].stateValues.xs[1]).eq("\uff3f"); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/p2"].stateValues.vertex[0]).eq( - "\uff3f", - ); - expect(stateVariables["/p2"].stateValues.vertex[1]).eq( - "\uff3f", - ); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.vertex[0]).eq( - "\uff3f", - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[1]).eq( - "\uff3f", - ); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change a"); - cy.get(cesc("#\\/a") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - // first calculate old values of parameters - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = 2, - y2 = 4, - y3 = 6; - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - a = -2; - - // revise ys for new value of a - y1 = a * x1 ** 2 + b * x1 + c; - y2 = a * x2 ** 2 + b * x2 + c; - y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+x+1"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change b"); - cy.get(cesc("#\\/b") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - // first calculate old values of parameters - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = 2, - y2 = 4, - y3 = 6; - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - (a = -2), (b = 3); - - // revise ys for new values of a and b - y1 = a * x1 ** 2 + b * x1 + c; - y2 = a * x2 ** 2 + b * x2 + c; - y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+1"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change c"); - cy.get(cesc("#\\/c") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}9{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=−2x2+3x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change a2"); - cy.get(cesc("#\\/a2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}0.2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = 3, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2+3x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-1.7{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should("contain.text", "y=0.2x2−1.7x+9"); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change c2"); - cy.get(cesc("#\\/c2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-4.5{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = 0.2, - b = -1.7, - c = -4.5; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.get(cesc2("#/e2")).should( - "contain.text", - "y=0.2x2−1.7x−4.5", - ); - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = 0.2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move vertex2"); - cy.window().then(async (win) => { - await win.callAction1({ - actionName: "movePoint", - componentName: "/v2", - args: { x: 5, y: -6 }, - }); - - let a = 0.2; - - let vertex_x = 5; - let vertex_y = -6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move all points"); - cy.window().then(async (win) => { - let x1 = -4, - x2 = 0, - x3 = -9; - let y1 = 7, - y2 = -2, - y3 = -2; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move points on top of each other, become vertex"); - cy.window().then(async (win) => { - let x1 = 3, - x2 = 3, - x3 = 3; - let y1 = -9, - y2 = -9, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - let a = 0.2; - - let vertex_x = x1; - let vertex_y = y1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move one point apart"); - cy.window().then(async (win) => { - let x1 = 3, - x2 = 3, - x3 = 4; - let y1 = -9, - y2 = -9, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - let a = 0.2; - - let b = (y1 - y3 - a * (x1 ** 2 - x3 ** 2)) / (x1 - x3); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("change point grouping"); - cy.window().then(async (win) => { - let x1 = 3, - x2 = 4, - x3 = 4; - let y1 = -9, - y2 = -9, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let b = (y1 - y3 - a * (x1 ** 2 - x3 ** 2)) / (x1 - x3); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("change point grouping again"); - cy.window().then(async (win) => { - let x1 = 4, - x2 = 6, - x3 = 4; - let y1 = -9, - y2 = 3, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move points above each other, parabola undefined"); - cy.window().then(async (win) => { - let x1 = -4, - x2 = -4, - x3 = 0; - let y1 = -9, - y2 = 1, - y3 = 1; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - assert.isNaN(stateVariables["/_parabola1"].stateValues.a); - assert.isNaN(stateVariables["/_parabola1"].stateValues.b); - assert.isNaN(stateVariables["/_parabola1"].stateValues.c); - expect( - stateVariables["/_parabola1"].stateValues.vertex, - ).eqls(["\uff3f", "\uff3f"]); - expect(stateVariables["/v"].stateValues.xs[0]).eq("\uff3f"); - expect(stateVariables["/v"].stateValues.xs[1]).eq("\uff3f"); - assert.isNaN(stateVariables["/p2"].stateValues.a); - assert.isNaN(stateVariables["/p2"].stateValues.b); - assert.isNaN(stateVariables["/p2"].stateValues.c); - expect(stateVariables["/p2"].stateValues.vertex).eqls([ - "\uff3f", - "\uff3f", - ]); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - assert.isNaN(stateVariables["/g3/p2"].stateValues.a); - assert.isNaN(stateVariables["/g3/p2"].stateValues.b); - assert.isNaN(stateVariables["/g3/p2"].stateValues.c); - expect(stateVariables["/g3/p2"].stateValues.vertex).eqls([ - "\uff3f", - "\uff3f", - ]); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move points apart"); - cy.window().then(async (win) => { - let x1 = -5, - x2 = -4, - x3 = 0; - let y1 = -9, - y2 = 1, - y3 = 1; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - }); - }); - - it("warning with parabola through four points", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - cy.window().then(async (win) => { - let errorWarnings = await win.returnErrorWarnings1(); - - expect(errorWarnings.errors.length).eq(0); - expect(errorWarnings.warnings.length).eq(1); - - expect(errorWarnings.warnings[0].message).contain( - `Haven't implemented parabola through more than 3 points`, - ); - expect(errorWarnings.warnings[0].level).eq(1); - expect(errorWarnings.warnings[0].doenetMLrange.lineBegin).eq(4); - expect(errorWarnings.warnings[0].doenetMLrange.charBegin).eq(5); - expect(errorWarnings.warnings[0].doenetMLrange.lineEnd).eq(4); - expect(errorWarnings.warnings[0].doenetMLrange.charEnd).eq(50); - }); - }); - - // test unfinished - it.skip("parabola through variable number of points", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a -

Number of points:

- - - - - - $n.value - - - - $_parabola1.vertex{name="v"} - - - $_parabola1{name="p2"} - $v{name="v2"} - - $g2{name="g3" newNamespace} - -

a =

-

b =

-

c =

- -

a2 =

-

b2 =

-

c2 =

- - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let parabola3 = - stateVariables["/g3"].replacements[0].activeChildren[0]; - let vertex3 = - stateVariables["/g3"].replacements[0].activeChildren[1]; - - cy.window().then(async (win) => { - let a = 1, - b = -2, - c = 2; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - stateVariables["/_parabola1"].stateValues.vertex[0], - ).eq(vertex_x); - expect( - stateVariables["/_parabola1"].stateValues.vertex[1], - ).eq(vertex_y); - expect(stateVariables["/v"].stateValues.xs[0]).eq(vertex_x); - expect(stateVariables["/v"].stateValues.xs[1]).eq(vertex_y); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - }); - }); - - cy.log("Change a"); - cy.get(cesc("#\\/a") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = -2, - c = 2; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - stateVariables["/_parabola1"].stateValues.vertex[0], - ).eq(vertex_x); - expect( - stateVariables["/_parabola1"].stateValues.vertex[1], - ).eq(vertex_y); - expect(stateVariables["/v"].stateValues.xs[0]).eq(vertex_x); - expect(stateVariables["/v"].stateValues.xs[1]).eq(vertex_y); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2, - b = 3, - c = 2; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - stateVariables["/_parabola1"].stateValues.vertex[0], - ).eq(vertex_x); - expect( - stateVariables["/_parabola1"].stateValues.vertex[1], - ).eq(vertex_y); - expect(stateVariables["/v"].stateValues.xs[0]).eq(vertex_x); - expect(stateVariables["/v"].stateValues.xs[1]).eq(vertex_y); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = -2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - stateVariables["/_parabola1"].stateValues.vertex[0], - ).eq(vertex_x); - expect( - stateVariables["/_parabola1"].stateValues.vertex[1], - ).eq(vertex_y); - expect(stateVariables["/v"].stateValues.xs[0]).eq(vertex_x); - expect(stateVariables["/v"].stateValues.xs[1]).eq(vertex_y); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - }); - }); - - cy.log("Add a second point"); - cy.get(cesc("#\\/n") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let a = -2; - - let x1 = -2, - x2 = 2; - let y1 = 1, - y2 = 3; - - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - stateVariables["/_parabola1"].stateValues.vertex[0], - ).eq(vertex_x); - expect( - stateVariables["/_parabola1"].stateValues.vertex[1], - ).eq(vertex_y); - expect(stateVariables["/v"].stateValues.xs[0]).eq(vertex_x); - expect(stateVariables["/v"].stateValues.xs[1]).eq(vertex_y); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/p2"].stateValues.vertex[1]).eq( - vertex_y, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - vertex_x, - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - vertex_y, - ); - }); - }); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - // first calculate old values of parameters - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = 2, - y2 = 4, - y3 = 6; - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - a = -2; - - // revise ys for new value of a - y1 = a * x1 ** 2 + b * x1 + c; - y2 = a * x2 ** 2 + b * x2 + c; - y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change b"); - cy.get(cesc("#\\/b") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}3{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - // first calculate old values of parameters - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = 2, - y2 = 4, - y3 = 6; - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - (a = -2), (b = 3); - - // revise ys for new values of a and b - y1 = a * x1 ** 2 + b * x1 + c; - y2 = a * x2 ** 2 + b * x2 + c; - y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change c"); - cy.get(cesc("#\\/c") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}9{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let a = -2, - b = 3, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change a2"); - cy.get(cesc("#\\/a2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}0.2{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let a = 0.2, - b = 3, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change b2"); - cy.get(cesc("#\\/b2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-1.7{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let a = 0.2, - b = -1.7, - c = 9; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("Change c2"); - cy.get(cesc("#\\/c2") + " textarea").type( - "{ctrl+home}{shift+end}{backspace}-4.5{enter}", - { force: true }, - ); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let a = 0.2, - b = -1.7, - c = -4.5; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move vertex1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - await win.callAction1({ - actionName: "movePoint", - componentName: "/v", - args: { x: -2, y: 1 }, - }); - - let a = 0.2; - - let vertex_x = -2; - let vertex_y = 1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move vertex2"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - await win.callAction1({ - actionName: "movePoint", - componentName: "/v2", - args: { x: 5, y: -6 }, - }); - - let a = 0.2; - - let vertex_x = 5; - let vertex_y = -6; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - // calculate point locations - let x1 = 1, - x2 = 3, - x3 = 5; - let y1 = a * x1 ** 2 + b * x1 + c; - let y2 = a * x2 ** 2 + b * x2 + c; - let y3 = a * x3 ** 2 + b * x3 + c; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move all points"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = -4, - x2 = 0, - x3 = -9; - let y1 = 7, - y2 = -2, - y3 = -2; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move points on top of each other, become vertex"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = 3, - x2 = 3, - x3 = 3; - let y1 = -9, - y2 = -9, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - let a = 0.2; - - let vertex_x = x1; - let vertex_y = y1; - - let b = -2 * a * vertex_x; - let c = vertex_y + a * vertex_x * vertex_x; - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move one point apart"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = 3, - x2 = 3, - x3 = 4; - let y1 = -9, - y2 = -9, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - let a = 0.2; - - let b = (y1 - y3 - a * (x1 ** 2 - x3 ** 2)) / (x1 - x3); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("change point grouping"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = 3, - x2 = 4, - x3 = 4; - let y1 = -9, - y2 = -9, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let b = (y1 - y3 - a * (x1 ** 2 - x3 ** 2)) / (x1 - x3); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("change point grouping again"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = 4, - x2 = 6, - x3 = 4; - let y1 = -9, - y2 = 3, - y3 = -9; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let a = 0.2; - - let b = (y1 - y2 - a * (x1 ** 2 - x2 ** 2)) / (x1 - x2); - let c = y1 - a * x1 ** 2 - b * x1; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move points above each other, parabola undefined"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = -4, - x2 = -4, - x3 = 0; - let y1 = -9, - y2 = 1, - y3 = 1; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point3", - args: { x: x3, y: y3 }, - }); - - cy.window().then(async (win) => { - assert.isNaN(stateVariables["/_parabola1"].stateValues.a); - assert.isNaN(stateVariables["/_parabola1"].stateValues.b); - assert.isNaN(stateVariables["/_parabola1"].stateValues.c); - expect( - stateVariables["/_parabola1"].stateValues.vertex, - ).eqls(["\uff3f", "\uff3f"]); - expect(stateVariables["/v"].stateValues.xs[0]).eq("\uff3f"); - expect(stateVariables["/v"].stateValues.xs[1]).eq("\uff3f"); - assert.isNaN(stateVariables["/p2"].stateValues.a); - assert.isNaN(stateVariables["/p2"].stateValues.b); - assert.isNaN(stateVariables["/p2"].stateValues.c); - expect(stateVariables["/p2"].stateValues.vertex).eqls([ - "\uff3f", - "\uff3f", - ]); - expect(stateVariables["/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - assert.isNaN(stateVariables["/g3/p2"].stateValues.a); - assert.isNaN(stateVariables["/g3/p2"].stateValues.b); - assert.isNaN(stateVariables["/g3/p2"].stateValues.c); - expect(stateVariables["/g3/p2"].stateValues.vertex).eqls([ - "\uff3f", - "\uff3f", - ]); - expect(stateVariables["/g3/v2"].stateValues.xs[0]).eq( - "\uff3f", - ); - expect(stateVariables["/g3/v2"].stateValues.xs[1]).eq( - "\uff3f", - ); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - - cy.log("move points apart"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let x1 = -5, - x2 = -4, - x3 = 0; - let y1 = -9, - y2 = 1, - y3 = 1; - - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point1", - args: { x: x1, y: y1 }, - }); - await win.callAction1({ - actionName: "movePoint", - componentName: "/_point2", - args: { x: x2, y: y2 }, - }); - - let x12 = x1 * x1; - let x22 = x2 * x2; - let x32 = x3 * x3; - - let u1 = x12 - x32; - let u2 = x22 - x32; - - let v1 = x1 - x3; - let v2 = x2 - x3; - - let z1 = y1 - y3; - let z2 = y2 - y3; - - let det = u1 * v2 - u2 * v1; - - let a = (z1 * v2 - z2 * v1) / det; - let b = (z2 * u1 - z1 * u2) / det; - let c = y1 - b * x1 - a * x12; - - let vertex_x = -b / (2 * a); - let vertex_y = c - b ** 2 / (4 * a); - - let equationExpression = me.fromText(`y=${a}x^2+${b}x+${c}`); - - cy.window().then(async (win) => { - expect(stateVariables["/_parabola1"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/_parabola1"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/_parabola1"].stateValues - .vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect(stateVariables["/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst(stateVariables["/p2"].stateValues.equation) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/e2"].stateValues.value) - .equals(equationExpression), - ).eq(true); - expect(stateVariables["/g3/p2"].stateValues.a).closeTo( - a, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.b).closeTo( - b, - 1e-12, - ); - expect(stateVariables["/g3/p2"].stateValues.c).closeTo( - c, - 1e-12, - ); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.equation, - ) - .equals(equationExpression), - ).eq(true); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[0], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst( - stateVariables["/g3/p2"].stateValues.vertex[1], - ) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[0]) - .evaluate_numbers().tree, - ).closeTo(vertex_x, 1e-12); - expect( - me - .fromAst(stateVariables["/g3/v2"].stateValues.xs[1]) - .evaluate_numbers().tree, - ).closeTo(vertex_y, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point1"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y1, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point2"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y2, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[0], - ) - .evaluate_numbers().tree, - ).closeTo(x3, 1e-12); - expect( - me - .fromAst( - stateVariables["/_point3"].stateValues.xs[1], - ) - .evaluate_numbers().tree, - ).closeTo(y3, 1e-12); - }); - }); - }); - }); - - it("constrain to parabola", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - - $p - - - - - $p{name="p2"} - $A{name="A2"} - - $g2{name="g3" newNamespace} - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - let f_p = (x) => (x - 1) ** 2 + 2; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let [x1, x2] = stateVariables["/A"].stateValues.xs; - let [x12, x22] = stateVariables["/A2"].stateValues.xs; - let [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(0); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A", - args: { x: 9, y: -2 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(9); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A2", - args: { x: -9, y: 4 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(-9); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 0.9, y: 9 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(0.9); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 1.1, y: 9 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(1.11); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - }); - }); - - it("constrain to parabola opening downward", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - - $p - - - - - $p{name="p2"} - $A{name="A2"} - - $g2{name="g3" newNamespace} - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - let f_p = (x) => -((x - 1) ** 2 + 2); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let [x1, x2] = stateVariables["/A"].stateValues.xs; - let [x12, x22] = stateVariables["/A2"].stateValues.xs; - let [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(0); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A", - args: { x: 9, y: 2 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(9); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A2", - args: { x: -9, y: -4 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(-9); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 0.9, y: -9 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(0.9); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 1.1, y: -9 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(1.11); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - }); - }); - - it("constrain to parabola that is a line", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - - $p - - - - - $p{name="p2"} - $A{name="A2"} - - $g2{name="g3" newNamespace} - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - let f_p = (x) => 0.5 * x + 1.5; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let [x1, x2] = stateVariables["/A"].stateValues.xs; - let [x12, x22] = stateVariables["/A2"].stateValues.xs; - let [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).closeTo(1.5 / -2.5, 1e-14); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A", - args: { x: 9, y: -2 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).closeTo((1.5 - 2 * 9 + 2) / -2.5, 1e-14); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A2", - args: { x: -9, y: 4 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).closeTo((1.5 + 2 * 9 - 4) / -2.5, 1e-14); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 0.9, y: 9 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).closeTo((1.5 - 2 * 0.9 - 9) / -2.5, 1e-14); - expect(x2).closeTo(f_p(x1), 1e-14); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - }); - }); - - it("constrain to parabola opening downward, different axis scales", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - - $p - - - - - $p{name="p2"} - $A{name="A2"} - - $g2{name="g3" ymin="-1000" ymax="1000" newNamespace} - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - let f_p = (x) => -100 * ((x - 1) ** 2 + 2); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let [x1, x2] = stateVariables["/A"].stateValues.xs; - let [x12, x22] = stateVariables["/A2"].stateValues.xs; - let [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(0); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A", - args: { x: 9, y: 200 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(9); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A2", - args: { x: -9, y: -400 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(-9); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 0.9, y: -900 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(0.9); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/g3/A2", - args: { x: 1.1, y: -900 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(1.11); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A", - args: { x: 9, y: 0 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).greaterThan(2); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - - await win.callAction1({ - actionName: "movePoint", - componentName: "/A2", - args: { x: -9, y: 100 }, - }); - stateVariables = await win.returnAllStateVariables1(); - [x1, x2] = stateVariables["/A"].stateValues.xs; - [x12, x22] = stateVariables["/A2"].stateValues.xs; - [x13, x23] = stateVariables["/g3/A2"].stateValues.xs; - expect(x1).lessThan(0); - expect(x2).closeTo(f_p(x1), 1e-12); - expect(x12).eq(x1); - expect(x13).eq(x1); - expect(x22).eq(x2); - expect(x23).eq(x2); - }); - }); - - it("copy parabola and overwrite parameters", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - $p0{vertex="(3,4)" name="p1"} - $p1{through="(5,-4)" name="p2"} - $p0{through="(-5,-2)" name="p3"} - $p3{vertex="(-6,6)" name="p4"} - - - $g1{name="g2"} - - `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - expect(stateVariables["/g1/p0"].stateValues.a).closeTo(1, 1e-12); - expect(stateVariables["/g1/p0"].stateValues.b).closeTo(0, 1e-12); - expect(stateVariables["/g1/p0"].stateValues.c).closeTo(0, 1e-12); - expect(stateVariables["/g2/p0"].stateValues.a).closeTo(1, 1e-12); - expect(stateVariables["/g2/p0"].stateValues.b).closeTo(0, 1e-12); - expect(stateVariables["/g2/p0"].stateValues.c).closeTo(0, 1e-12); - - expect(stateVariables["/g1/p1"].stateValues.a).closeTo(1, 1e-12); - expect(stateVariables["/g1/p1"].stateValues.b).closeTo(-6, 1e-12); - expect(stateVariables["/g1/p1"].stateValues.c).closeTo(13, 1e-12); - expect(stateVariables["/g2/p1"].stateValues.a).closeTo(1, 1e-12); - expect(stateVariables["/g2/p1"].stateValues.b).closeTo(-6, 1e-12); - expect(stateVariables["/g2/p1"].stateValues.c).closeTo(13, 1e-12); - - expect(stateVariables["/g1/p2"].stateValues.a).closeTo(-2, 1e-12); - expect(stateVariables["/g1/p2"].stateValues.b).closeTo(12, 1e-12); - expect(stateVariables["/g1/p2"].stateValues.c).closeTo(-14, 1e-12); - expect(stateVariables["/g2/p2"].stateValues.a).closeTo(-2, 1e-12); - expect(stateVariables["/g2/p2"].stateValues.b).closeTo(12, 1e-12); - expect(stateVariables["/g2/p2"].stateValues.c).closeTo(-14, 1e-12); - - expect(stateVariables["/g1/p3"].stateValues.a).closeTo(1, 1e-12); - expect(stateVariables["/g1/p3"].stateValues.b).closeTo(10, 1e-12); - expect(stateVariables["/g1/p3"].stateValues.c).closeTo(23, 1e-12); - expect(stateVariables["/g2/p3"].stateValues.a).closeTo(1, 1e-12); - expect(stateVariables["/g2/p3"].stateValues.b).closeTo(10, 1e-12); - expect(stateVariables["/g2/p3"].stateValues.c).closeTo(23, 1e-12); - - expect(stateVariables["/g1/p4"].stateValues.a).closeTo(-8, 1e-12); - expect(stateVariables["/g1/p4"].stateValues.b).closeTo(-96, 1e-12); - expect(stateVariables["/g1/p4"].stateValues.c).closeTo(-282, 1e-12); - expect(stateVariables["/g2/p4"].stateValues.a).closeTo(-8, 1e-12); - expect(stateVariables["/g2/p4"].stateValues.b).closeTo(-96, 1e-12); - expect(stateVariables["/g2/p4"].stateValues.c).closeTo(-282, 1e-12); - }); - }); - - it("copy propIndex of points", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - -

- -

- -

- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - let t1x = 2, - t1y = -3; - let t2x = 3, - t2y = 4; - let t3x = -3, - t3y = 4; - - cy.get(cesc("#\\/P1") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should("not.exist"); - - cy.get(cesc("#\\/n") + " textarea").type("1{enter}", { force: true }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should( - "contain.text", - `(${nInDOM(t1x)},${nInDOM(t1y)})`, - ); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "contain.text", - `${nInDOM(t2x)}`, - ); - - cy.get(cesc("#\\/n") + " textarea").type("{end}{backspace}2{enter}", { - force: true, - }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should( - "contain.text", - `(${nInDOM(t2x)},${nInDOM(t2y)})`, - ); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "contain.text", - `${nInDOM(t2y)}`, - ); - - cy.get(cesc("#\\/n") + " textarea").type("{end}{backspace}3{enter}", { - force: true, - }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should( - "contain.text", - `(${nInDOM(t3x)},${nInDOM(t3y)})`, - ); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should("not.exist"); - - cy.get(cesc("#\\/n") + " textarea").type("{end}{backspace}4{enter}", { - force: true, - }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should("not.exist"); - }); - - it("copy propIndex of points, dot and array notation", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` - a - - - - -

- -

- -

- -

- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); // to wait for page to load - - let t1x = 2, - t1y = -3; - let t2x = 3, - t2y = 4; - let t3x = -3, - t3y = 4; - - cy.get(cesc("#\\/P1") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/xa") + " .mjx-mrow").should("not.exist"); - - cy.get(cesc("#\\/n") + " textarea").type("1{enter}", { force: true }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should( - "contain.text", - `(${nInDOM(t1x)},${nInDOM(t1y)})`, - ); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "contain.text", - `${nInDOM(t2x)}`, - ); - cy.get(cesc("#\\/xa") + " .mjx-mrow").should( - "contain.text", - `${nInDOM(t2x)}`, - ); - - cy.get(cesc("#\\/n") + " textarea").type("{end}{backspace}2{enter}", { - force: true, - }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should( - "contain.text", - `(${nInDOM(t2x)},${nInDOM(t2y)})`, - ); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should( - "contain.text", - `${nInDOM(t2y)}`, - ); - cy.get(cesc("#\\/xa") + " .mjx-mrow").should( - "contain.text", - `${nInDOM(t2y)}`, - ); - - cy.get(cesc("#\\/n") + " textarea").type("{end}{backspace}3{enter}", { - force: true, - }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should( - "contain.text", - `(${nInDOM(t3x)},${nInDOM(t3y)})`, - ); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/xa") + " .mjx-mrow").should("not.exist"); - - cy.get(cesc("#\\/n") + " textarea").type("{end}{backspace}4{enter}", { - force: true, - }); - cy.get(cesc("#\\/P1") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P2") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/P3") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/x") + " .mjx-mrow").should("not.exist"); - cy.get(cesc("#\\/xa") + " .mjx-mrow").should("not.exist"); - }); -});