diff --git a/packages/doenetml-worker/src/test/tagSpecific/selectprimenumbers.test.ts b/packages/doenetml-worker/src/test/tagSpecific/selectprimenumbers.test.ts
index 3dd2df742..8f07d0471 100644
--- a/packages/doenetml-worker/src/test/tagSpecific/selectprimenumbers.test.ts
+++ b/packages/doenetml-worker/src/test/tagSpecific/selectprimenumbers.test.ts
@@ -1,13 +1,9 @@
import { describe, expect, it, vi } from "vitest";
import { createTestCore, returnAllStateVariables } from "../utils/test-core";
-import { cleanLatex } from "../utils/math";
import {
updateBooleanInputValue,
updateMathInputValue,
- updateMatrixInputValue,
- updateTextInputValue,
} from "../utils/actions";
-import me from "math-expressions";
const Mock = vi.fn();
vi.stubGlobal("postMessage", Mock);
diff --git a/packages/doenetml-worker/src/test/tagSpecific/selectrandomnumbers.test.ts b/packages/doenetml-worker/src/test/tagSpecific/selectrandomnumbers.test.ts
new file mode 100644
index 000000000..01afc1aeb
--- /dev/null
+++ b/packages/doenetml-worker/src/test/tagSpecific/selectrandomnumbers.test.ts
@@ -0,0 +1,887 @@
+import { describe, expect, it, vi } from "vitest";
+import { createTestCore, returnAllStateVariables } from "../utils/test-core";
+import { updateMathInputValue } from "../utils/actions";
+import me from "math-expressions";
+
+const Mock = vi.fn();
+vi.stubGlobal("postMessage", Mock);
+
+describe("SelectRandomNumbers tag tests", async () => {
+ async function test_combined_statistics({
+ doenetML,
+ componentName,
+ numSamplesPerComponent,
+ numRepetitions,
+ minValue,
+ strictMin = true,
+ maxValue,
+ strictMax = true,
+ validValues,
+ allowedMeanMid,
+ allowedMeanSpread,
+ allowedVarianceMid,
+ allowedVarianceSpread,
+ expectedMean,
+ expectedVariance,
+ }: {
+ doenetML: string;
+ componentName: string;
+ numSamplesPerComponent: number;
+ numRepetitions: number;
+ minValue?: number;
+ strictMin?: boolean;
+ maxValue?: number;
+ strictMax?: boolean;
+ validValues?: number[];
+ allowedMeanMid?: number;
+ allowedMeanSpread?: number;
+ allowedVarianceMid?: number;
+ allowedVarianceSpread?: number;
+ expectedMean?: number;
+ expectedVariance?: number;
+ }) {
+ let samples: number[] = [];
+ for (let i = 0; i < numRepetitions; i++) {
+ let core = await createTestCore({
+ doenetML,
+ requestedVariantIndex: i,
+ });
+ const stateVariables = await returnAllStateVariables(core);
+ samples.push(
+ ...stateVariables[componentName].replacements!.map(
+ (x) => stateVariables[x.componentName].stateValues.value,
+ ),
+ );
+
+ if (expectedMean !== undefined && i == 0) {
+ expect(stateVariables[componentName].stateValues.mean).closeTo(
+ expectedMean,
+ 1e-10,
+ );
+ }
+
+ if (expectedVariance !== undefined && i == 0) {
+ expect(
+ stateVariables[componentName].stateValues.variance,
+ ).closeTo(expectedVariance, 1e-10);
+ expect(
+ stateVariables[componentName].stateValues.standardDeviation,
+ ).closeTo(Math.sqrt(expectedVariance), 1e-10);
+ }
+ }
+
+ expect(samples.length).eq(numSamplesPerComponent * numRepetitions);
+
+ if (minValue !== undefined) {
+ for (let sample of samples) {
+ if (strictMin) {
+ expect(sample).gt(minValue);
+ } else {
+ expect(sample).gte(minValue);
+ }
+ }
+ }
+
+ if (maxValue !== undefined) {
+ for (let sample of samples) {
+ if (strictMax) {
+ expect(sample).lt(maxValue);
+ } else {
+ expect(sample).lte(maxValue);
+ }
+ }
+ }
+
+ if (validValues !== undefined) {
+ for (let sample of samples) {
+ expect(validValues.includes(sample)).eq(true);
+ }
+ }
+
+ if (allowedMeanMid !== undefined && allowedMeanSpread !== undefined) {
+ let meanX = me.math.mean(samples);
+ expect(meanX).closeTo(allowedMeanMid, allowedMeanSpread);
+ }
+
+ if (
+ allowedVarianceMid !== undefined &&
+ allowedVarianceSpread !== undefined
+ ) {
+ let varX = me.math.variance(samples, "uncorrected");
+ expect(varX).closeTo(allowedVarianceMid, allowedVarianceSpread);
+ }
+ }
+
+ it("no parameters, select single uniform random number from 0 to 1", async () => {
+ const doenetML = `
+
+
$maxNum2.value{assignNames="maxNum2a"}
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let sample1replacements = stateVariables["/sample1"].replacements!; + let sample2replacements = stateVariables["/sample2"].replacements!; + expect(sample1replacements.length).eq(20); + expect(sample2replacements.length).eq(10); + let sample1numbers = sample1replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let sample2numbers = sample2replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + + for (let num of sample1numbers) { + expect(num).gte(0); + expect(num).lt(10); + } + for (let num of sample2numbers) { + expect([0, 1, 2, 3, 4].includes(num)).eq(true); + } + + // Nothing changes when change mathInputs + await updateMathInputValue({ + latex: "7", + componentName: "/numToSelect", + core, + }); + await updateMathInputValue({ + latex: "11", + componentName: "/maxNum", + core, + }); + await updateMathInputValue({ + latex: "16", + componentName: "/numToSelect2", + core, + }); + await updateMathInputValue({ + latex: "18", + componentName: "/maxNum2", + core, + }); + + stateVariables = await returnAllStateVariables(core); + sample1replacements = stateVariables["/sample1"].replacements!; + sample2replacements = stateVariables["/sample2"].replacements!; + + expect( + sample1replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ), + ).eqls(sample1numbers); + expect( + sample2replacements.map( + (x) => stateVariables[x.componentName].stateValues.value, + ), + ).eqls(sample2numbers); + }); + + it("select doesn't resample in dynamic map", async () => { + let core = await createTestCore({ + doenetML: ` + How many numbers do you want?$map1
+ + $p1{name="p3"} + $p2{name="p4"} + + $p3{name="p5"} + $p4{name="p6"} + `, + }); + + async function check_sampled_numbers(sampledNumbers: number[]) { + const stateVariables = await returnAllStateVariables(core); + + expect( + stateVariables["/p1"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p2"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p3"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p4"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p5"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + + expect( + stateVariables["/p6"].activeChildren.map( + (child) => + stateVariables[child.componentName].stateValues.value, + ), + ).eqls(sampledNumbers); + } + + let sampledNumbers: number[] = []; + + // initially nothing + await check_sampled_numbers([]); + + // sample one variable + await updateMathInputValue({ latex: "1", componentName: "/mi1", core }); + + let stateVariables = await returnAllStateVariables(core); + sampledNumbers.push(stateVariables["/a/n"].stateValues.value); + await check_sampled_numbers(sampledNumbers); + + // go back to nothing + await updateMathInputValue({ latex: "0", componentName: "/mi1", core }); + await check_sampled_numbers([]); + + // get same number back + await updateMathInputValue({ latex: "1", componentName: "/mi1", core }); + await check_sampled_numbers(sampledNumbers); + + // get two more samples + await updateMathInputValue({ latex: "3", componentName: "/mi1", core }); + + stateVariables = await returnAllStateVariables(core); + let n1 = stateVariables["/a/n"].stateValues.value; + let n2 = stateVariables["/b/n"].stateValues.value; + let n3 = stateVariables["/c/n"].stateValues.value; + expect(n1).eq(sampledNumbers[0]); + sampledNumbers.push(n2); + sampledNumbers.push(n3); + await check_sampled_numbers(sampledNumbers); + + // go back to nothing + await updateMathInputValue({ latex: "0", componentName: "/mi1", core }); + await check_sampled_numbers([]); + + // get first two numbers back + await updateMathInputValue({ latex: "2", componentName: "/mi1", core }); + await check_sampled_numbers(sampledNumbers.slice(0, 2)); + + // get six total samples + await updateMathInputValue({ latex: "6", componentName: "/mi1", core }); + + stateVariables = await returnAllStateVariables(core); + n1 = stateVariables["/a/n"].stateValues.value; + n2 = stateVariables["/b/n"].stateValues.value; + n3 = stateVariables["/c/n"].stateValues.value; + let n4 = stateVariables["/d/n"].stateValues.value; + let n5 = stateVariables["/e/n"].stateValues.value; + let n6 = stateVariables["/f/n"].stateValues.value; + expect(n1).eq(sampledNumbers[0]); + expect(n2).eq(sampledNumbers[1]); + expect(n3).eq(sampledNumbers[2]); + sampledNumbers.push(n4); + sampledNumbers.push(n5); + sampledNumbers.push(n6); + await check_sampled_numbers(sampledNumbers); + + // go back to nothing + await updateMathInputValue({ latex: "0", componentName: "/mi1", core }); + await check_sampled_numbers([]); + + // get all six back + await updateMathInputValue({ latex: "6", componentName: "/mi1", core }); + await check_sampled_numbers(sampledNumbers); + }); + + it("select single discrete uniform number, assign name", async () => { + let core = await createTestCore({ + doenetML: ` +$u{name="u2"}
+$v{name="v2"}
+$w{name="w2"}
+ `, + }); + + let options = [3, 10]; + + let stateVariables = await returnAllStateVariables(core); + + let u = stateVariables["/u"]; + let u2 = stateVariables["/u2"]; + + expect(options.includes(u.stateValues.value)).eq(true); + expect(u.stateValues.value).eq(u2.stateValues.value); + + let v = stateVariables["/v"]; + let v2 = stateVariables["/v2"]; + expect(options.includes(v.stateValues.value)).eq(true); + expect(v.stateValues.value).eq(v2.stateValues.value); + + let w = stateVariables["/w"]; + let w2 = stateVariables["/w2"]; + expect(options.includes(w.stateValues.value)).eq(true); + expect(w.stateValues.value).eq(w2.stateValues.value); + }); + + it("select multiple uniform random numbers, assign names", async () => { + let core = await createTestCore({ + doenetML: ` +
+
$u{name="u2"}
+$v{name="v2"}
+$w{name="w2"}
+ `, + }); + + let results: number[] = []; + + let stateVariables = await returnAllStateVariables(core); + let s = stateVariables["/s"]; + expect(s.replacements!.length).eq(6); + for (let ind = 0; ind < 6; ind++) { + let num = + stateVariables[s.replacements![ind].componentName].stateValues + .value; + results[ind] = num; + expect(num).gte(3); + expect(num).lt(13); + } + + let u = stateVariables["/u"]; + let u2 = stateVariables["/u2"]; + expect(u.stateValues.value).eq(results[0]); + expect(u2.stateValues.value).eq(results[0]); + + let v = stateVariables["/v"]; + let v2 = stateVariables["/v2"]; + expect(v.stateValues.value).eq(results[1]); + expect(v2.stateValues.value).eq(results[1]); + + let w = stateVariables["/w"]; + let w2 = stateVariables["/w2"]; + expect(w.stateValues.value).eq(results[2]); + expect(w2.stateValues.value).eq(results[2]); + }); + + it("select multiple uniform random numbers, assign names, newNamespace", async () => { + let core = await createTestCore({ + doenetML: ` +
+
$(s/u{name="u2"})
+$(s/v{name="v2"})
+$(s/w{name="w2"})
+ `, + }); + + let results: number[] = []; + + let stateVariables = await returnAllStateVariables(core); + let s = stateVariables["/s"]; + expect(s.replacements!.length).eq(6); + for (let ind = 0; ind < 6; ind++) { + let num = + stateVariables[s.replacements![ind].componentName].stateValues + .value; + results[ind] = num; + expect(num).gte(3); + expect(num).lt(13); + } + + let u = stateVariables["/s/u"]; + let u2 = stateVariables["/u2"]; + expect(u.stateValues.value).eq(results[0]); + expect(u2.stateValues.value).eq(results[0]); + + let v = stateVariables["/s/v"]; + let v2 = stateVariables["/v2"]; + expect(v.stateValues.value).eq(results[1]); + expect(v2.stateValues.value).eq(results[1]); + + let w = stateVariables["/s/w"]; + let w2 = stateVariables["/w2"]; + expect(w.stateValues.value).eq(results[2]); + expect(w2.stateValues.value).eq(results[2]); + }); + + it("numToSelect from selectFromSequence", async () => { + let core = await createTestCore({ + doenetML: ` +n1 =
nums =
a1=$a1, b1=$b1, c1=$c1, d1=$d1, e1=$e1
+ +n2 =
nums =
a2=$a2, b2=$b2, c2=$c2, d2=$d2, e2=$e2
+ +n3 =
nums =
a3=$a3, b3=$b3, c3=$c3, d3=$d3, e3=$e3
+ +n4 =
nums =
a4=$a4, b4=$b4, c4=$c4, d4=$d4, e4=$e4
+ +n5 =
nums =
a5=$a5, b5=$b5, c5=$c5, d5=$d5, e5=$e5
+ `, + }); + + let stateVariables = await returnAllStateVariables(core); + let n1 = stateVariables["/n1"].stateValues.value; + let n2 = stateVariables["/n2"].stateValues.value; + let n3 = stateVariables["/n3"].stateValues.value; + let n4 = stateVariables["/n4"].stateValues.value; + let n5 = stateVariables["/n5"].stateValues.value; + + let nums1 = stateVariables["/nums1"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums2 = stateVariables["/nums2"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums3 = stateVariables["/nums3"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums4 = stateVariables["/nums4"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + let nums5 = stateVariables["/nums5"].replacements!.map( + (x) => stateVariables[x.componentName].stateValues.value, + ); + + expect(nums1.length).eq(n1); + expect(nums2.length).eq(n2); + expect(nums3.length).eq(n3); + expect(nums4.length).eq(n4); + expect(nums5.length).eq(n5); + + nums1.length = 5; + nums2.length = 5; + nums3.length = 5; + nums4.length = 5; + nums5.length = 5; + + nums1.fill("", n1); + nums2.fill("", n2); + nums3.fill("", n3); + nums4.fill("", n4); + nums5.fill("", n5); + + let l = ["a", "b", "c", "d", "e"]; + + expect(stateVariables["/p1"].stateValues.text).eq( + nums1 + .map((v, i) => `${l[i]}1=${v ? Math.round(v * 1e9) / 1e9 : ""}`) + .join(", "), + ); + expect(stateVariables["/p2"].stateValues.text).eq( + nums2 + .map((v, i) => `${l[i]}2=${v ? Math.round(v * 1e9) / 1e9 : ""}`) + .join(", "), + ); + expect(stateVariables["/p3"].stateValues.text).eq( + nums3 + .map((v, i) => `${l[i]}3=${v ? Math.round(v * 1e9) / 1e9 : ""}`) + .join(", "), + ); + expect(stateVariables["/p4"].stateValues.text).eq( + nums4 + .map((v, i) => `${l[i]}4=${v ? Math.round(v * 1e9) / 1e9 : ""}`) + .join(", "), + ); + expect(stateVariables["/p5"].stateValues.text).eq( + nums5 + .map((v, i) => `${l[i]}5=${v ? Math.round(v * 1e9) / 1e9 : ""}`) + .join(", "), + ); + }); + + it("rounding", async () => { + let core = await createTestCore({ + doenetML: ` +$maxnum2{name="maxnum2a"}
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load - - let sample1numbers, sample2numbers; - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let sample1replacements = stateVariables["/sample1"].replacements; - let sample2replacements = stateVariables["/sample2"].replacements; - expect(sample1replacements.length).eq(20); - expect(sample2replacements.length).eq(10); - sample1numbers = sample1replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - sample2numbers = sample2replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - - for (let num of sample1numbers) { - expect(num).gte(0); - expect(num).lt(10); - } - for (let num of sample2numbers) { - expect([0, 1, 2, 3, 4].includes(num)).eq(true); - } - }); - - cy.log("Nothing changes when change mathinputs"); - cy.get(cesc("#\\/numToSelect") + " textarea").type( - `{end}{backspace}{backspace}7{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/maxnum") + " textarea").type( - `{end}{backspace}{backspace}11{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/numToSelect2") + " textarea").type( - `{end}{backspace}{backspace}15{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/maxnum2") + " textarea").type( - `{end}{backspace}{backspace}18{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/maxnum2a")).should("contain.text", "18"); - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let sample1replacements = stateVariables["/sample1"].replacements; - let sample2replacements = stateVariables["/sample2"].replacements; - - expect( - sample1replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ), - ).eqls(sample1numbers); - expect( - sample2replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ), - ).eqls(sample2numbers); - }); - }); - - it("random number doesn't resample in dynamic map", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$_aslist1
- - $p1{name="p4"} - $p2{name="p5"} - $p3{name="p6"} - - $p4{name="p7"} - $p5{name="p8"} - $p6{name="p9"} -$_mathinput1{name="m1"}
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load - - let samplednumbers = []; - - cy.log("initially nothing"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("sample one variable"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}1{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - samplednumbers.push(n1); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - for (let ind = 0; ind < 1; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("go back to nothing"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}0{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "0"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("get same number back"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}1{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "1"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(1); - - for (let ind = 0; ind < 1; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("get two more samples"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}3{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "3"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - let n3 = stateVariables["/c/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - samplednumbers.push(n2); - samplednumbers.push(n3); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(3); - for (let ind = 0; ind < 3; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("go back to nothing"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}0{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "0"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("get first two numbers back"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}2{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "2"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect(n2).eq(samplednumbers[1]); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(2); - - for (let ind = 0; ind < 2; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("get six total samples"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}6{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "6"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - let n3 = stateVariables["/c/n"].stateValues.value; - let n4 = stateVariables["/d/n"].stateValues.value; - let n5 = stateVariables["/e/n"].stateValues.value; - let n6 = stateVariables["/f/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect(n2).eq(samplednumbers[1]); - expect(n3).eq(samplednumbers[2]); - samplednumbers.push(n4); - samplednumbers.push(n5); - samplednumbers.push(n6); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - for (let ind = 0; ind < 6; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - - cy.log("go back to nothing"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}0{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "0"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(0); - }); - - cy.log("get all six back"); - cy.get(cesc("#\\/_mathinput1") + " textarea").type( - `{end}{backspace}6{enter}`, - { force: true }, - ); - cy.get(cesc("#\\/m1")).should("contain.text", "6"); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - let n1 = stateVariables["/a/n"].stateValues.value; - let n2 = stateVariables["/b/n"].stateValues.value; - let n3 = stateVariables["/c/n"].stateValues.value; - let n4 = stateVariables["/d/n"].stateValues.value; - let n5 = stateVariables["/e/n"].stateValues.value; - let n6 = stateVariables["/f/n"].stateValues.value; - expect(n1).eq(samplednumbers[0]); - expect(n2).eq(samplednumbers[1]); - expect(n3).eq(samplednumbers[2]); - expect(n4).eq(samplednumbers[3]); - expect(n5).eq(samplednumbers[4]); - expect(n6).eq(samplednumbers[5]); - expect( - stateVariables[ - stateVariables["/p1"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p2"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p3"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p4"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p5"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p6"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p7"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p8"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - expect( - stateVariables[ - stateVariables["/p9"].activeChildren[0].componentName - ].activeChildren.length, - ).eq(6); - for (let ind = 0; ind < 6; ind++) { - expect( - stateVariables[ - stateVariables[ - stateVariables["/p1"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p2"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p3"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p4"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p5"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p6"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p7"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p8"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - expect( - stateVariables[ - stateVariables[ - stateVariables["/p9"].activeChildren[0] - .componentName - ].activeChildren[ind].componentName - ].stateValues.value, - ).eq(samplednumbers[ind]); - } - }); - }); - - it("select single discrete uniform number, assign name", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$u{name="u2"}
-$v{name="v2"}
-$w{name="w2"}
- `, - }, - "*", - ); - }); - - let options = [3, 10]; - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load - - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let u = stateVariables["/u"]; - let u2 = stateVariables["/u2"]; - - expect(options.includes(u.stateValues.value)).eq(true); - expect(u.stateValues.value).eq(u2.stateValues.value); - - let v = stateVariables["/v"]; - let v2 = stateVariables["/v2"]; - expect(options.includes(v.stateValues.value)).eq(true); - expect(v.stateValues.value).eq(v2.stateValues.value); - - let w = stateVariables["/w"]; - let w2 = stateVariables["/w2"]; - expect(options.includes(w.stateValues.value)).eq(true); - expect(w.stateValues.value).eq(w2.stateValues.value); - }); - }); - - it("select multiple uniform random numbers, assign names", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$u{name="u2"}
-$v{name="v2"}
-$w{name="w2"}
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load - - let results = []; - - for (let ind = 0; ind < 6; ind++) { - cy.get(cesc("#\\/_p1") + " > :nth-child(" + (2 * ind + 4) + ")") - .invoke("text") - .then((text) => { - let num = Number(text); - results[ind] = num; - expect(num).gte(3); - expect(num).lt(13); - }); - } - - cy.log("check by name").then(() => { - cy.get(cesc("#\\/u")).should("have.text", results[0]); - cy.get(cesc("#\\/u2")).should("have.text", results[0]); - cy.get(cesc("#\\/v")).should("have.text", results[1]); - cy.get(cesc("#\\/v2")).should("have.text", results[1]); - cy.get(cesc("#\\/w")).should("have.text", results[2]); - cy.get(cesc("#\\/w2")).should("have.text", results[2]); - }); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let u = stateVariables["/u"]; - let u2 = stateVariables["/u2"]; - expect(u.stateValues.value).closeTo(results[0], 1e-8); - expect(u2.stateValues.value).closeTo(results[0], 1e-8); - - let v = stateVariables["/v"]; - let v2 = stateVariables["/v2"]; - expect(v.stateValues.value).closeTo(results[1], 1e-8); - expect(v2.stateValues.value).closeTo(results[1], 1e-8); - - let w = stateVariables["/w"]; - let w2 = stateVariables["/w2"]; - expect(w.stateValues.value).closeTo(results[2], 1e-8); - expect(w2.stateValues.value).closeTo(results[2], 1e-8); - - let s = stateVariables["/s"]; - expect(s.replacements.length).eq(6); - for (let ind = 0; ind < 6; ind++) { - let r = stateVariables[s.replacements[ind].componentName]; - expect(r.stateValues.value).closeTo(results[ind], 1e-8); - } - }); - }); - - it("select multiple uniform random numbers, assign names, newNamespace", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -$(s/u{name="u2"})
-$(s/v{name="v2"})
-$(s/w{name="w2"})
- `, - }, - "*", - ); - }); - - cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load - - let results = []; - - for (let ind = 0; ind < 6; ind++) { - cy.get(cesc("#\\/_p1") + " > :nth-child(" + (2 * ind + 4) + ")") - .invoke("text") - .then((text) => { - let num = Number(text); - results[ind] = num; - expect(num).gte(3); - expect(num).lt(13); - }); - } - - cy.log("check by name").then(() => { - cy.get(cesc("#\\/s\\/u")).should("have.text", results[0]); - cy.get(cesc("#\\/u2")).should("have.text", results[0]); - cy.get(cesc("#\\/s\\/v")).should("have.text", results[1]); - cy.get(cesc("#\\/v2")).should("have.text", results[1]); - cy.get(cesc("#\\/s\\/w")).should("have.text", results[2]); - cy.get(cesc("#\\/w2")).should("have.text", results[2]); - }); - cy.window().then(async (win) => { - let stateVariables = await win.returnAllStateVariables1(); - - let u = stateVariables["/s/u"]; - let u2 = stateVariables["/u2"]; - expect(u.stateValues.value).closeTo(results[0], 1e-8); - expect(u2.stateValues.value).closeTo(results[0], 1e-8); - - let v = stateVariables["/s/v"]; - let v2 = stateVariables["/v2"]; - expect(v.stateValues.value).closeTo(results[1], 1e-8); - expect(v2.stateValues.value).closeTo(results[1], 1e-8); - - let w = stateVariables["/s/w"]; - let w2 = stateVariables["/w2"]; - expect(w.stateValues.value).closeTo(results[2], 1e-8); - expect(w2.stateValues.value).closeTo(results[2], 1e-8); - - let s = stateVariables["/s"]; - expect(s.replacements.length).eq(6); - for (let ind = 0; ind < 6; ind++) { - let r = stateVariables[s.replacements[ind].componentName]; - expect(r.stateValues.value).closeTo(results[ind], 1e-8); - } - }); - }); - - it("numToSelect from selectfromsequence", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -n1 =
nums =
a1=$a1, b1=$b1, c1=$c1, d1=$d1, e1=$e1
- -n2 =
nums =
a2=$a2, b2=$b2, c2=$c2, d2=$d2, e2=$e2
- -n3 =
nums =
a3=$a3, b3=$b3, c3=$c3, d3=$d3, e3=$e3
- -n4 =
nums =
a4=$a4, b4=$b4, c4=$c4, d4=$d4, e4=$e4
- -n5 =
nums =
a5=$a5, b5=$b5, c5=$c5, d5=$d5, e5=$e5
- `, - }, - "*", - ); - }); - - 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 n1 = stateVariables["/n1"].stateValues.value; - let n2 = stateVariables["/n2"].stateValues.value; - let n3 = stateVariables["/n3"].stateValues.value; - let n4 = stateVariables["/n4"].stateValues.value; - let n5 = stateVariables["/n5"].stateValues.value; - - let nums1 = stateVariables["/nums1"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums2 = stateVariables["/nums2"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums3 = stateVariables["/nums3"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums4 = stateVariables["/nums4"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - let nums5 = stateVariables["/nums5"].replacements.map( - (x) => stateVariables[x.componentName].stateValues.value, - ); - - expect(nums1.length).eq(n1); - expect(nums2.length).eq(n2); - expect(nums3.length).eq(n3); - expect(nums4.length).eq(n4); - expect(nums5.length).eq(n5); - - nums1.length = 5; - nums2.length = 5; - nums3.length = 5; - nums4.length = 5; - nums5.length = 5; - - nums1.fill("", n1); - nums2.fill("", n2); - nums3.fill("", n3); - nums4.fill("", n4); - nums5.fill("", n5); - - let l = ["a", "b", "c", "d", "e"]; - - cy.get(cesc("#\\/p1")).should( - "have.text", - nums1 - .map( - (v, i) => - `${l[i]}1=${v ? Math.round(v * 1e9) / 1e9 : ""}`, - ) - .join(", "), - ); - cy.get(cesc("#\\/p2")).should( - "have.text", - nums2 - .map( - (v, i) => - `${l[i]}2=${v ? Math.round(v * 1e9) / 1e9 : ""}`, - ) - .join(", "), - ); - cy.get(cesc("#\\/p3")).should( - "have.text", - nums3 - .map( - (v, i) => - `${l[i]}3=${v ? Math.round(v * 1e9) / 1e9 : ""}`, - ) - .join(", "), - ); - cy.get(cesc("#\\/p4")).should( - "have.text", - nums4 - .map( - (v, i) => - `${l[i]}4=${v ? Math.round(v * 1e9) / 1e9 : ""}`, - ) - .join(", "), - ); - cy.get(cesc("#\\/p5")).should( - "have.text", - nums5 - .map( - (v, i) => - `${l[i]}5=${v ? Math.round(v * 1e9) / 1e9 : ""}`, - ) - .join(", "), - ); - }); - }); - - it("rounding", () => { - cy.window().then(async (win) => { - win.postMessage( - { - doenetML: ` -