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:
-
-
-
-
- $_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");
- });
-});