@doenet/doenetml 0.6.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (549) hide show
  1. package/.prettierrc +3 -0
  2. package/LICENSE +661 -0
  3. package/README.md +146 -0
  4. package/cypress/e2e/ActivityViewer/activityVariants.cy.js +1770 -0
  5. package/cypress/e2e/ActivityViewer/compiledActivity.cy.js +83 -0
  6. package/cypress/e2e/ActivityViewer/relationshipsAmongPages.cy.js +697 -0
  7. package/cypress/e2e/answerValidation/errorinnumbers.cy.js +2125 -0
  8. package/cypress/e2e/answerValidation/factoring.cy.js +1945 -0
  9. package/cypress/e2e/answerValidation/factoringOldAlgorithm.cy.js +892 -0
  10. package/cypress/e2e/answerValidation/functionanswers.cy.js +314 -0
  11. package/cypress/e2e/answerValidation/matchingpatterns.cy.js +287 -0
  12. package/cypress/e2e/answerValidation/matchpartial.cy.js +6711 -0
  13. package/cypress/e2e/answerValidation/pointlocation.cy.js +3989 -0
  14. package/cypress/e2e/answerValidation/symbolicequality.cy.js +1893 -0
  15. package/cypress/e2e/answerValidation/videoProgress.cy.js +210 -0
  16. package/cypress/e2e/assignNames/basiccopy.cy.js +2376 -0
  17. package/cypress/e2e/assignNames/collections.cy.js +9247 -0
  18. package/cypress/e2e/assignNames/selects.cy.js +105 -0
  19. package/cypress/e2e/assignNames/sequences.cy.js +1964 -0
  20. package/cypress/e2e/baseComponent/basecomponentproperties.cy.js +999 -0
  21. package/cypress/e2e/baseComponent/doenetMLtext.cy.js +427 -0
  22. package/cypress/e2e/chemistry/atom.cy.js +201 -0
  23. package/cypress/e2e/chemistry/ion.cy.js +608 -0
  24. package/cypress/e2e/chemistry/ioniccompound.cy.js +133 -0
  25. package/cypress/e2e/dynamicalsystem/cobwebpolyline.cy.js +2653 -0
  26. package/cypress/e2e/dynamicalsystem/equilibriumcurve.cy.js +311 -0
  27. package/cypress/e2e/dynamicalsystem/equilibriumline.cy.js +279 -0
  28. package/cypress/e2e/dynamicalsystem/equilibriumpoint.cy.js +283 -0
  29. package/cypress/e2e/dynamicalsystem/odesystem.cy.js +1834 -0
  30. package/cypress/e2e/equality/mathexpressions.cy.js +948 -0
  31. package/cypress/e2e/graphing/graphreferences.cy.js +978 -0
  32. package/cypress/e2e/graphing/graphreferences2.cy.js +615 -0
  33. package/cypress/e2e/linearAlgebra/eigenDecomposition.cy.js +401 -0
  34. package/cypress/e2e/tagSpecific/angle.cy.js +3898 -0
  35. package/cypress/e2e/tagSpecific/animatefromsequence.cy.js +2306 -0
  36. package/cypress/e2e/tagSpecific/answer.cy.js +31647 -0
  37. package/cypress/e2e/tagSpecific/bestfitline.cy.js +612 -0
  38. package/cypress/e2e/tagSpecific/blockquote.cy.js +30 -0
  39. package/cypress/e2e/tagSpecific/boolean.cy.js +742 -0
  40. package/cypress/e2e/tagSpecific/booleaninput.cy.js +1283 -0
  41. package/cypress/e2e/tagSpecific/booleanlist.cy.js +588 -0
  42. package/cypress/e2e/tagSpecific/booleanoperators.cy.js +596 -0
  43. package/cypress/e2e/tagSpecific/booleanoperatorsonmath.cy.js +498 -0
  44. package/cypress/e2e/tagSpecific/callaction.cy.js +2835 -0
  45. package/cypress/e2e/tagSpecific/choiceinput.cy.js +3205 -0
  46. package/cypress/e2e/tagSpecific/circle.cy.js +22036 -0
  47. package/cypress/e2e/tagSpecific/codeeditor.cy.js +1995 -0
  48. package/cypress/e2e/tagSpecific/collect.cy.js +5035 -0
  49. package/cypress/e2e/tagSpecific/componentsize.cy.js +502 -0
  50. package/cypress/e2e/tagSpecific/conditionalcontent.cy.js +3495 -0
  51. package/cypress/e2e/tagSpecific/contentBrowser.cy.js +335 -0
  52. package/cypress/e2e/tagSpecific/contentpicker.cy.js +261 -0
  53. package/cypress/e2e/tagSpecific/copy.cy.js +12627 -0
  54. package/cypress/e2e/tagSpecific/copy2.cy.js +5698 -0
  55. package/cypress/e2e/tagSpecific/curve.bezier.cy.js +12440 -0
  56. package/cypress/e2e/tagSpecific/curve.cy.js +1716 -0
  57. package/cypress/e2e/tagSpecific/curve.function.cy.js +1471 -0
  58. package/cypress/e2e/tagSpecific/curve.parametrized.cy.js +920 -0
  59. package/cypress/e2e/tagSpecific/document.cy.js +234 -0
  60. package/cypress/e2e/tagSpecific/endpoint.cy.js +197 -0
  61. package/cypress/e2e/tagSpecific/evaluate.cy.js +8895 -0
  62. package/cypress/e2e/tagSpecific/extract.cy.js +2282 -0
  63. package/cypress/e2e/tagSpecific/feedback.cy.js +2941 -0
  64. package/cypress/e2e/tagSpecific/function.cy.js +9450 -0
  65. package/cypress/e2e/tagSpecific/functioniterates.cy.js +1178 -0
  66. package/cypress/e2e/tagSpecific/functionoperators.cy.js +4047 -0
  67. package/cypress/e2e/tagSpecific/graph.cy.js +2491 -0
  68. package/cypress/e2e/tagSpecific/group.cy.js +683 -0
  69. package/cypress/e2e/tagSpecific/hint.cy.js +204 -0
  70. package/cypress/e2e/tagSpecific/image.cy.js +770 -0
  71. package/cypress/e2e/tagSpecific/integer.cy.js +206 -0
  72. package/cypress/e2e/tagSpecific/label.cy.js +800 -0
  73. package/cypress/e2e/tagSpecific/legend.cy.js +1001 -0
  74. package/cypress/e2e/tagSpecific/line.cy.js +12167 -0
  75. package/cypress/e2e/tagSpecific/linesegment.cy.js +4749 -0
  76. package/cypress/e2e/tagSpecific/lorem.cy.js +289 -0
  77. package/cypress/e2e/tagSpecific/map.cy.js +4476 -0
  78. package/cypress/e2e/tagSpecific/matchespattern.cy.js +693 -0
  79. package/cypress/e2e/tagSpecific/math.cy.js +10990 -0
  80. package/cypress/e2e/tagSpecific/mathdisplay.cy.js +2689 -0
  81. package/cypress/e2e/tagSpecific/mathinput.cy.js +15628 -0
  82. package/cypress/e2e/tagSpecific/mathinputgraph.cy.js +566 -0
  83. package/cypress/e2e/tagSpecific/mathlist.cy.js +4073 -0
  84. package/cypress/e2e/tagSpecific/mathoperators.cy.js +13851 -0
  85. package/cypress/e2e/tagSpecific/matrix.cy.js +8825 -0
  86. package/cypress/e2e/tagSpecific/matrixinput.cy.js +16277 -0
  87. package/cypress/e2e/tagSpecific/module.cy.js +1771 -0
  88. package/cypress/e2e/tagSpecific/number.cy.js +2221 -0
  89. package/cypress/e2e/tagSpecific/numberlist.cy.js +1285 -0
  90. package/cypress/e2e/tagSpecific/p.cy.js +72 -0
  91. package/cypress/e2e/tagSpecific/paginator.cy.js +2983 -0
  92. package/cypress/e2e/tagSpecific/parabola.cy.js +14331 -0
  93. package/cypress/e2e/tagSpecific/paragraphmarkup.cy.js +104 -0
  94. package/cypress/e2e/tagSpecific/periodicset.cy.js +1439 -0
  95. package/cypress/e2e/tagSpecific/piecewisefunction.cy.js +1055 -0
  96. package/cypress/e2e/tagSpecific/pluralize.cy.js +274 -0
  97. package/cypress/e2e/tagSpecific/point.cy.js +8895 -0
  98. package/cypress/e2e/tagSpecific/point2.cy.js +10259 -0
  99. package/cypress/e2e/tagSpecific/polygon.cy.js +5039 -0
  100. package/cypress/e2e/tagSpecific/polyline.cy.js +4704 -0
  101. package/cypress/e2e/tagSpecific/problem.cy.js +2768 -0
  102. package/cypress/e2e/tagSpecific/ray.cy.js +10770 -0
  103. package/cypress/e2e/tagSpecific/rectangle.cy.js +2143 -0
  104. package/cypress/e2e/tagSpecific/ref.cy.js +420 -0
  105. package/cypress/e2e/tagSpecific/regularPolygon.cy.js +1006 -0
  106. package/cypress/e2e/tagSpecific/regularPolygon2.cy.js +100 -0
  107. package/cypress/e2e/tagSpecific/regularPolygon3.cy.js +777 -0
  108. package/cypress/e2e/tagSpecific/samplerandomnumbers.cy.js +3619 -0
  109. package/cypress/e2e/tagSpecific/sectioning.cy.js +3530 -0
  110. package/cypress/e2e/tagSpecific/select.cy.js +5376 -0
  111. package/cypress/e2e/tagSpecific/selectfromsequence.cy.js +3846 -0
  112. package/cypress/e2e/tagSpecific/selectrandomnumbers.cy.js +2914 -0
  113. package/cypress/e2e/tagSpecific/sequence.cy.js +2093 -0
  114. package/cypress/e2e/tagSpecific/shuffle.cy.js +490 -0
  115. package/cypress/e2e/tagSpecific/sidebyside.cy.js +8057 -0
  116. package/cypress/e2e/tagSpecific/singlecharactercomponents.cy.js +72 -0
  117. package/cypress/e2e/tagSpecific/slider.cy.js +914 -0
  118. package/cypress/e2e/tagSpecific/solution.cy.js +109 -0
  119. package/cypress/e2e/tagSpecific/solveequations.cy.js +1026 -0
  120. package/cypress/e2e/tagSpecific/sort.cy.js +1685 -0
  121. package/cypress/e2e/tagSpecific/spreadsheet.cy.js +5971 -0
  122. package/cypress/e2e/tagSpecific/subsetofreals.cy.js +2725 -0
  123. package/cypress/e2e/tagSpecific/substitute.cy.js +2646 -0
  124. package/cypress/e2e/tagSpecific/tabular.cy.js +36 -0
  125. package/cypress/e2e/tagSpecific/text.cy.js +975 -0
  126. package/cypress/e2e/tagSpecific/textinput.cy.js +2177 -0
  127. package/cypress/e2e/tagSpecific/textlist.cy.js +369 -0
  128. package/cypress/e2e/tagSpecific/triangle.cy.js +1936 -0
  129. package/cypress/e2e/tagSpecific/triggerset.cy.js +2023 -0
  130. package/cypress/e2e/tagSpecific/updatevalue.cy.js +3288 -0
  131. package/cypress/e2e/tagSpecific/vector.cy.js +20183 -0
  132. package/cypress/e2e/tagSpecific/video.cy.js +612 -0
  133. package/cypress/e2e/tagSpecific/when.cy.js +202 -0
  134. package/cypress/e2e/variants/specifysinglevariant.cy.js +6726 -0
  135. package/cypress/e2e/variants/uniquevariants.cy.js +4846 -0
  136. package/cypress/fixtures/example.json +5 -0
  137. package/cypress/support/commands.js +32 -0
  138. package/cypress/support/e2e.js +31 -0
  139. package/cypress.config.js +18 -0
  140. package/docs/codeSnippet.jsx +11 -0
  141. package/docs/index.html +133 -0
  142. package/docs/index.jsx +138 -0
  143. package/docs/prism.css +3 -0
  144. package/index.html +14 -0
  145. package/index.js +21 -0
  146. package/media/answer_example.png +0 -0
  147. package/media/graph_example.png +0 -0
  148. package/media/graph_markup_example.png +0 -0
  149. package/package.json +83 -0
  150. package/public/favicon.ico +0 -0
  151. package/public/fonts/files/open-sans-v18-latin-700.woff +0 -0
  152. package/public/fonts/files/open-sans-v18-latin-700.woff2 +0 -0
  153. package/public/fonts/files/open-sans-v18-latin-700italic.woff +0 -0
  154. package/public/fonts/files/open-sans-v18-latin-700italic.woff2 +0 -0
  155. package/public/fonts/files/open-sans-v18-latin-italic.woff +0 -0
  156. package/public/fonts/files/open-sans-v18-latin-italic.woff2 +0 -0
  157. package/public/fonts/files/open-sans-v18-latin-light-italic.woff +0 -0
  158. package/public/fonts/files/open-sans-v18-latin-light-italic.woff2 +0 -0
  159. package/public/fonts/files/open-sans-v18-latin-light.woff +0 -0
  160. package/public/fonts/files/open-sans-v18-latin-light.woff2 +0 -0
  161. package/public/fonts/files/open-sans-v18-latin-regular.woff +0 -0
  162. package/public/fonts/files/open-sans-v18-latin-regular.woff2 +0 -0
  163. package/src/Core/ComponentTypes.js +426 -0
  164. package/src/Core/Core.js +11852 -0
  165. package/src/Core/CoreWorker.js +127 -0
  166. package/src/Core/Dependencies.js +8226 -0
  167. package/src/Core/Numerics.js +473 -0
  168. package/src/Core/ParameterStack.js +36 -0
  169. package/src/Core/ReadOnlyProxyHandler.js +41 -0
  170. package/src/Core/StateProxyHandler.js +88 -0
  171. package/src/Core/components/Aliases.js +67 -0
  172. package/src/Core/components/Angle.js +758 -0
  173. package/src/Core/components/AnimateFromSequence.js +922 -0
  174. package/src/Core/components/Answer.js +2087 -0
  175. package/src/Core/components/AsList.js +83 -0
  176. package/src/Core/components/AttractTo.js +245 -0
  177. package/src/Core/components/AttractToAngles.js +262 -0
  178. package/src/Core/components/AttractToConstraint.js +104 -0
  179. package/src/Core/components/AttractToGrid.js +315 -0
  180. package/src/Core/components/Award.js +906 -0
  181. package/src/Core/components/BestFitLine.js +318 -0
  182. package/src/Core/components/BezierControls.js +719 -0
  183. package/src/Core/components/BlockQuote.js +35 -0
  184. package/src/Core/components/Boolean.js +500 -0
  185. package/src/Core/components/BooleanInput.js +330 -0
  186. package/src/Core/components/BooleanList.js +396 -0
  187. package/src/Core/components/BooleanOperators.js +35 -0
  188. package/src/Core/components/BooleanOperatorsOfMath.js +148 -0
  189. package/src/Core/components/CallAction.js +261 -0
  190. package/src/Core/components/Caption.js +73 -0
  191. package/src/Core/components/Case.js +56 -0
  192. package/src/Core/components/Cell.js +439 -0
  193. package/src/Core/components/CellBlock.js +64 -0
  194. package/src/Core/components/Chart.js +795 -0
  195. package/src/Core/components/Choice.js +266 -0
  196. package/src/Core/components/ChoiceInput.js +1407 -0
  197. package/src/Core/components/Circle.js +2884 -0
  198. package/src/Core/components/CodeEditor.js +647 -0
  199. package/src/Core/components/CodeViewer.js +294 -0
  200. package/src/Core/components/CollaborateGroupSetup.js +46 -0
  201. package/src/Core/components/CollaborateGroups.js +119 -0
  202. package/src/Core/components/Collect.js +850 -0
  203. package/src/Core/components/Column.js +608 -0
  204. package/src/Core/components/ConditionalContent.js +468 -0
  205. package/src/Core/components/ConsiderAsResponses.js +49 -0
  206. package/src/Core/components/ConstrainTo.js +161 -0
  207. package/src/Core/components/ConstrainToAngles.js +244 -0
  208. package/src/Core/components/ConstrainToGraph.js +142 -0
  209. package/src/Core/components/ConstrainToGrid.js +175 -0
  210. package/src/Core/components/ConstraintUnion.js +119 -0
  211. package/src/Core/components/Constraints.js +497 -0
  212. package/src/Core/components/ContentBrowser.js +441 -0
  213. package/src/Core/components/ContentPicker.js +263 -0
  214. package/src/Core/components/ControlVectors.js +25 -0
  215. package/src/Core/components/Coords.js +63 -0
  216. package/src/Core/components/Copy.js +3412 -0
  217. package/src/Core/components/Curve.js +4130 -0
  218. package/src/Core/components/CustomAttribute.js +175 -0
  219. package/src/Core/components/DataFrame.js +357 -0
  220. package/src/Core/components/DiscreteSimulationResultList.js +342 -0
  221. package/src/Core/components/DiscreteSimulationResultPolyline.js +581 -0
  222. package/src/Core/components/Divisions.js +55 -0
  223. package/src/Core/components/Document.js +888 -0
  224. package/src/Core/components/Embed.js +65 -0
  225. package/src/Core/components/Endpoint.js +62 -0
  226. package/src/Core/components/Evaluate.js +321 -0
  227. package/src/Core/components/Extract.js +656 -0
  228. package/src/Core/components/Extrema.js +556 -0
  229. package/src/Core/components/Feedback.js +200 -0
  230. package/src/Core/components/FeedbackDefinitions.js +97 -0
  231. package/src/Core/components/Figure.js +148 -0
  232. package/src/Core/components/Footnote.js +73 -0
  233. package/src/Core/components/Function.js +5344 -0
  234. package/src/Core/components/FunctionIterates.js +306 -0
  235. package/src/Core/components/FunctionOperators.js +702 -0
  236. package/src/Core/components/Graph.js +1679 -0
  237. package/src/Core/components/Group.js +7 -0
  238. package/src/Core/components/HasSameFactoring.js +407 -0
  239. package/src/Core/components/Hint.js +241 -0
  240. package/src/Core/components/Image.js +524 -0
  241. package/src/Core/components/Indexing.js +79 -0
  242. package/src/Core/components/IntComma.js +64 -0
  243. package/src/Core/components/Integer.js +81 -0
  244. package/src/Core/components/Intersection.js +328 -0
  245. package/src/Core/components/Interval.js +29 -0
  246. package/src/Core/components/Label.js +492 -0
  247. package/src/Core/components/Latex.js +104 -0
  248. package/src/Core/components/Legend.js +329 -0
  249. package/src/Core/components/Line.js +2040 -0
  250. package/src/Core/components/LineSegment.js +882 -0
  251. package/src/Core/components/Lists.js +180 -0
  252. package/src/Core/components/Lorem.js +249 -0
  253. package/src/Core/components/MMeMen.js +377 -0
  254. package/src/Core/components/Map.js +873 -0
  255. package/src/Core/components/Markers.js +101 -0
  256. package/src/Core/components/MatchesPattern.js +339 -0
  257. package/src/Core/components/Math.js +2552 -0
  258. package/src/Core/components/MathInput.js +948 -0
  259. package/src/Core/components/MathList.js +828 -0
  260. package/src/Core/components/MathOperators.js +1286 -0
  261. package/src/Core/components/Matrix.js +497 -0
  262. package/src/Core/components/MatrixInput.js +3157 -0
  263. package/src/Core/components/MdMdnMrow.js +394 -0
  264. package/src/Core/components/Module.js +16 -0
  265. package/src/Core/components/Number.js +1031 -0
  266. package/src/Core/components/NumberList.js +550 -0
  267. package/src/Core/components/Option.js +24 -0
  268. package/src/Core/components/P.js +71 -0
  269. package/src/Core/components/Paginator.js +338 -0
  270. package/src/Core/components/Panel.js +126 -0
  271. package/src/Core/components/Parabola.js +1561 -0
  272. package/src/Core/components/ParagraphMarkup.js +59 -0
  273. package/src/Core/components/Pegboard.js +43 -0
  274. package/src/Core/components/PeriodicSet.js +291 -0
  275. package/src/Core/components/PiecewiseFunction.js +832 -0
  276. package/src/Core/components/Pluralize.js +198 -0
  277. package/src/Core/components/Point.js +1295 -0
  278. package/src/Core/components/Polygon.js +408 -0
  279. package/src/Core/components/Polyline.js +841 -0
  280. package/src/Core/components/RandomizedTextList.js +225 -0
  281. package/src/Core/components/Ray.js +1737 -0
  282. package/src/Core/components/Rectangle.js +1535 -0
  283. package/src/Core/components/Ref.js +350 -0
  284. package/src/Core/components/RegionBetweenCurveXAxis.js +124 -0
  285. package/src/Core/components/RegionHalfPlane.js +107 -0
  286. package/src/Core/components/RegularPolygon.js +2118 -0
  287. package/src/Core/components/RenderDoenetML.js +181 -0
  288. package/src/Core/components/Row.js +780 -0
  289. package/src/Core/components/SampleRandomNumbers.js +653 -0
  290. package/src/Core/components/Sectioning.js +303 -0
  291. package/src/Core/components/Select.js +947 -0
  292. package/src/Core/components/SelectFromSequence.js +1242 -0
  293. package/src/Core/components/SelectRandomNumbers.js +225 -0
  294. package/src/Core/components/Sequence.js +444 -0
  295. package/src/Core/components/Setup.js +53 -0
  296. package/src/Core/components/Shuffle.js +470 -0
  297. package/src/Core/components/SideBySide.js +2130 -0
  298. package/src/Core/components/SingleCharacterComponents.js +41 -0
  299. package/src/Core/components/Slider.js +819 -0
  300. package/src/Core/components/SolutionContainer.js +67 -0
  301. package/src/Core/components/Solutions.js +334 -0
  302. package/src/Core/components/SolveEquations.js +568 -0
  303. package/src/Core/components/Sort.js +398 -0
  304. package/src/Core/components/Sources.js +108 -0
  305. package/src/Core/components/Split.js +205 -0
  306. package/src/Core/components/Spreadsheet.js +1507 -0
  307. package/src/Core/components/StyleDefinitions.js +111 -0
  308. package/src/Core/components/SubsetOfReals.js +348 -0
  309. package/src/Core/components/SubsetOfRealsInput.js +1474 -0
  310. package/src/Core/components/Substitute.js +496 -0
  311. package/src/Core/components/SummaryStatistics.js +652 -0
  312. package/src/Core/components/Table.js +145 -0
  313. package/src/Core/components/Tabular.js +384 -0
  314. package/src/Core/components/Template.js +360 -0
  315. package/src/Core/components/Text.js +341 -0
  316. package/src/Core/components/TextInput.js +566 -0
  317. package/src/Core/components/TextList.js +442 -0
  318. package/src/Core/components/TextListFromString.js +137 -0
  319. package/src/Core/components/TextOperatorsOfMath.js +21 -0
  320. package/src/Core/components/Triangle.js +280 -0
  321. package/src/Core/components/TriggerSet.js +189 -0
  322. package/src/Core/components/TupleList.js +43 -0
  323. package/src/Core/components/UpdateValue.js +435 -0
  324. package/src/Core/components/VariantControl.js +36 -0
  325. package/src/Core/components/Vector.js +2478 -0
  326. package/src/Core/components/Verbatim.js +125 -0
  327. package/src/Core/components/Video.js +673 -0
  328. package/src/Core/components/When.js +198 -0
  329. package/src/Core/components/abstract/AngleListComponent.js +140 -0
  330. package/src/Core/components/abstract/BaseComponent.js +1496 -0
  331. package/src/Core/components/abstract/BlockComponent.js +5 -0
  332. package/src/Core/components/abstract/BooleanBaseOperator.js +88 -0
  333. package/src/Core/components/abstract/BooleanBaseOperatorOfMath.js +100 -0
  334. package/src/Core/components/abstract/BooleanBaseOperatorOneInput.js +44 -0
  335. package/src/Core/components/abstract/ComponentSize.js +789 -0
  336. package/src/Core/components/abstract/ComponentWithSelectableType.js +537 -0
  337. package/src/Core/components/abstract/CompositeComponent.js +142 -0
  338. package/src/Core/components/abstract/ConstraintComponent.js +19 -0
  339. package/src/Core/components/abstract/FunctionBaseOperator.js +680 -0
  340. package/src/Core/components/abstract/GraphicalComponent.js +56 -0
  341. package/src/Core/components/abstract/InlineComponent.js +5 -0
  342. package/src/Core/components/abstract/InlineRenderInlineChildren.js +63 -0
  343. package/src/Core/components/abstract/Input.js +192 -0
  344. package/src/Core/components/abstract/IntervalListComponent.js +218 -0
  345. package/src/Core/components/abstract/LineListComponent.js +114 -0
  346. package/src/Core/components/abstract/MathBaseOperator.js +631 -0
  347. package/src/Core/components/abstract/MathBaseOperatorOneInput.js +112 -0
  348. package/src/Core/components/abstract/PointListComponent.js +238 -0
  349. package/src/Core/components/abstract/SectioningComponent.js +1262 -0
  350. package/src/Core/components/abstract/SingleCharacterInline.js +23 -0
  351. package/src/Core/components/abstract/TextBaseOperatorOfMath.js +47 -0
  352. package/src/Core/components/abstract/TextOrInline.js +66 -0
  353. package/src/Core/components/abstract/VariableName.js +31 -0
  354. package/src/Core/components/abstract/VariableNameList.js +83 -0
  355. package/src/Core/components/abstract/VectorListComponent.js +235 -0
  356. package/src/Core/components/chemistry/Atom.js +910 -0
  357. package/src/Core/components/chemistry/ElectronConfiguration.js +36 -0
  358. package/src/Core/components/chemistry/Ion.js +684 -0
  359. package/src/Core/components/chemistry/IonicCompound.js +189 -0
  360. package/src/Core/components/chemistry/OrbitalDiagram.js +175 -0
  361. package/src/Core/components/chemistry/OrbitalDiagramInput.js +753 -0
  362. package/src/Core/components/chemistry/index.js +6 -0
  363. package/src/Core/components/commonsugar/breakstrings.js +627 -0
  364. package/src/Core/components/commonsugar/lists.js +177 -0
  365. package/src/Core/components/dynamicalSystems/CobwebPolyline.js +913 -0
  366. package/src/Core/components/dynamicalSystems/EquilibriumCurve.js +95 -0
  367. package/src/Core/components/dynamicalSystems/EquilibriumLine.js +93 -0
  368. package/src/Core/components/dynamicalSystems/EquilibriumPoint.js +93 -0
  369. package/src/Core/components/dynamicalSystems/ODESystem.js +943 -0
  370. package/src/Core/components/dynamicalSystems/index.js +5 -0
  371. package/src/Core/components/linearAlgebra/EigenDecomposition.js +294 -0
  372. package/src/Core/utils/array.js +30 -0
  373. package/src/Core/utils/booleanLogic.js +965 -0
  374. package/src/Core/utils/checkEquality.js +818 -0
  375. package/src/Core/utils/cid.js +29 -0
  376. package/src/Core/utils/componentInfoObjects.js +100 -0
  377. package/src/Core/utils/constraints.js +23 -0
  378. package/src/Core/utils/copy.js +572 -0
  379. package/src/Core/utils/deepFunctions.js +173 -0
  380. package/src/Core/utils/descendants.js +252 -0
  381. package/src/Core/utils/enumeration.js +234 -0
  382. package/src/Core/utils/feedback.js +84 -0
  383. package/src/Core/utils/function.js +1343 -0
  384. package/src/Core/utils/graphical.js +196 -0
  385. package/src/Core/utils/label.js +396 -0
  386. package/src/Core/utils/math.js +1056 -0
  387. package/src/Core/utils/naming.js +45 -0
  388. package/src/Core/utils/periodicSetEquality.js +403 -0
  389. package/src/Core/utils/randomNumbers.js +70 -0
  390. package/src/Core/utils/retrieveMedia.js +98 -0
  391. package/src/Core/utils/retrieveTextFile.js +140 -0
  392. package/src/Core/utils/returnAllPossibleVariants.js +73 -0
  393. package/src/Core/utils/rounding.js +316 -0
  394. package/src/Core/utils/sequence.js +754 -0
  395. package/src/Core/utils/serializedStateProcessing.js +4049 -0
  396. package/src/Core/utils/size.js +22 -0
  397. package/src/Core/utils/stateVariables.js +138 -0
  398. package/src/Core/utils/style.js +535 -0
  399. package/src/Core/utils/subset-of-reals.js +796 -0
  400. package/src/Core/utils/table.js +41 -0
  401. package/src/Core/utils/text.js +16 -0
  402. package/src/Core/utils/triggering.js +167 -0
  403. package/src/Core/utils/variants.js +477 -0
  404. package/src/DoenetML.css +308 -0
  405. package/src/DoenetML.jsx +201 -0
  406. package/src/Parser/doenet.grammar +90 -0
  407. package/src/Parser/doenet.js +33 -0
  408. package/src/Parser/doenet.terms.js +20 -0
  409. package/src/Parser/parser.js +266 -0
  410. package/src/Parser/tokens.js +129 -0
  411. package/src/Tools/CodeMirror.jsx +440 -0
  412. package/src/Tools/DarkmodeController.jsx +21 -0
  413. package/src/Tools/Footers/MathInputSelector.jsx +34 -0
  414. package/src/Tools/Footers/VirtualKeyboard.jsx +751 -0
  415. package/src/Tools/cypressTest/CypressTest.jsx +341 -0
  416. package/src/Tools/cypressTest/index.html +102 -0
  417. package/src/Tools/cypressTest/index.jsx +40 -0
  418. package/src/Viewer/ActivityViewer.jsx +1461 -0
  419. package/src/Viewer/PageViewer.jsx +1329 -0
  420. package/src/Viewer/renderers/alert.jsx +17 -0
  421. package/src/Viewer/renderers/angle.jsx +209 -0
  422. package/src/Viewer/renderers/answer.jsx +206 -0
  423. package/src/Viewer/renderers/asList.jsx +25 -0
  424. package/src/Viewer/renderers/blockQuote.jsx +41 -0
  425. package/src/Viewer/renderers/boolean.jsx +17 -0
  426. package/src/Viewer/renderers/booleanInput.css +105 -0
  427. package/src/Viewer/renderers/booleanInput.jsx +636 -0
  428. package/src/Viewer/renderers/button.jsx +369 -0
  429. package/src/Viewer/renderers/c.jsx +17 -0
  430. package/src/Viewer/renderers/callAction.jsx +18 -0
  431. package/src/Viewer/renderers/cell.jsx +59 -0
  432. package/src/Viewer/renderers/chart.jsx +83 -0
  433. package/src/Viewer/renderers/choiceInput.css +223 -0
  434. package/src/Viewer/renderers/choiceInput.jsx +535 -0
  435. package/src/Viewer/renderers/circle.jsx +990 -0
  436. package/src/Viewer/renderers/cobwebPolyline.jsx +442 -0
  437. package/src/Viewer/renderers/codeEditor.jsx +248 -0
  438. package/src/Viewer/renderers/codeViewer.jsx +105 -0
  439. package/src/Viewer/renderers/containerBlock.jsx +41 -0
  440. package/src/Viewer/renderers/containerInline.jsx +17 -0
  441. package/src/Viewer/renderers/contentBrowser.jsx +159 -0
  442. package/src/Viewer/renderers/contentPicker.jsx +160 -0
  443. package/src/Viewer/renderers/curve.jsx +1072 -0
  444. package/src/Viewer/renderers/ellipsis.jsx +17 -0
  445. package/src/Viewer/renderers/em.jsx +17 -0
  446. package/src/Viewer/renderers/embed.jsx +110 -0
  447. package/src/Viewer/renderers/feedback.jsx +74 -0
  448. package/src/Viewer/renderers/figure.jsx +131 -0
  449. package/src/Viewer/renderers/footnote.jsx +52 -0
  450. package/src/Viewer/renderers/graph.jsx +925 -0
  451. package/src/Viewer/renderers/hint.jsx +142 -0
  452. package/src/Viewer/renderers/image.jsx +581 -0
  453. package/src/Viewer/renderers/jsxgraph-distrib/jsxgraphcore.mjs +2 -0
  454. package/src/Viewer/renderers/jsxgraph-distrib/jsxgraphcore.mjs.map +1 -0
  455. package/src/Viewer/renderers/label.jsx +470 -0
  456. package/src/Viewer/renderers/legend.jsx +306 -0
  457. package/src/Viewer/renderers/line.jsx +511 -0
  458. package/src/Viewer/renderers/lineSegment.jsx +754 -0
  459. package/src/Viewer/renderers/list.jsx +111 -0
  460. package/src/Viewer/renderers/lq.jsx +12 -0
  461. package/src/Viewer/renderers/lsq.jsx +12 -0
  462. package/src/Viewer/renderers/math.jsx +582 -0
  463. package/src/Viewer/renderers/mathInput.css +10 -0
  464. package/src/Viewer/renderers/mathInput.jsx +425 -0
  465. package/src/Viewer/renderers/mathInputog.jsx +534 -0
  466. package/src/Viewer/renderers/mathList.jsx +39 -0
  467. package/src/Viewer/renderers/matrixInput.jsx +317 -0
  468. package/src/Viewer/renderers/mdash.jsx +12 -0
  469. package/src/Viewer/renderers/nbsp.jsx +12 -0
  470. package/src/Viewer/renderers/ndash.jsx +12 -0
  471. package/src/Viewer/renderers/number.jsx +454 -0
  472. package/src/Viewer/renderers/numberList.jsx +35 -0
  473. package/src/Viewer/renderers/orbitalDiagram.jsx +247 -0
  474. package/src/Viewer/renderers/orbitalDiagramInput.jsx +450 -0
  475. package/src/Viewer/renderers/p.jsx +38 -0
  476. package/src/Viewer/renderers/paginatorControls.jsx +41 -0
  477. package/src/Viewer/renderers/pegboard.jsx +239 -0
  478. package/src/Viewer/renderers/point.jsx +649 -0
  479. package/src/Viewer/renderers/polygon.jsx +612 -0
  480. package/src/Viewer/renderers/polyline.jsx +608 -0
  481. package/src/Viewer/renderers/pre.jsx +34 -0
  482. package/src/Viewer/renderers/q.jsx +17 -0
  483. package/src/Viewer/renderers/ray.jsx +410 -0
  484. package/src/Viewer/renderers/ref.jsx +149 -0
  485. package/src/Viewer/renderers/regionBetweenCurveXAxis.jsx +182 -0
  486. package/src/Viewer/renderers/renderDoenetML.jsx +56 -0
  487. package/src/Viewer/renderers/row.jsx +31 -0
  488. package/src/Viewer/renderers/rq.jsx +12 -0
  489. package/src/Viewer/renderers/rsq.jsx +12 -0
  490. package/src/Viewer/renderers/section.jsx +427 -0
  491. package/src/Viewer/renderers/sideBySide.jsx +80 -0
  492. package/src/Viewer/renderers/slider.jsx +800 -0
  493. package/src/Viewer/renderers/solution.jsx +134 -0
  494. package/src/Viewer/renderers/spreadsheet.jsx +83 -0
  495. package/src/Viewer/renderers/sq.jsx +17 -0
  496. package/src/Viewer/renderers/styles/global.css +14 -0
  497. package/src/Viewer/renderers/subsetOfRealsInput.jsx +392 -0
  498. package/src/Viewer/renderers/summaryStatistics.jsx +83 -0
  499. package/src/Viewer/renderers/table.jsx +78 -0
  500. package/src/Viewer/renderers/tabular.jsx +58 -0
  501. package/src/Viewer/renderers/tag.jsx +26 -0
  502. package/src/Viewer/renderers/text.jsx +439 -0
  503. package/src/Viewer/renderers/textInput.jsx +774 -0
  504. package/src/Viewer/renderers/textList.jsx +30 -0
  505. package/src/Viewer/renderers/triggerSet.jsx +52 -0
  506. package/src/Viewer/renderers/updateValue.jsx +30 -0
  507. package/src/Viewer/renderers/utils/css.js +13 -0
  508. package/src/Viewer/renderers/utils/graph.js +159 -0
  509. package/src/Viewer/renderers/utils/offGraphIndicators.js +91 -0
  510. package/src/Viewer/renderers/vector.jsx +678 -0
  511. package/src/Viewer/renderers/video.jsx +494 -0
  512. package/src/Viewer/useDoenetRenderer.jsx +128 -0
  513. package/src/main.jsx +16 -0
  514. package/src/media/fonts/files/open-sans-v18-latin-700.woff +0 -0
  515. package/src/media/fonts/files/open-sans-v18-latin-700.woff2 +0 -0
  516. package/src/media/fonts/files/open-sans-v18-latin-700italic.woff +0 -0
  517. package/src/media/fonts/files/open-sans-v18-latin-700italic.woff2 +0 -0
  518. package/src/media/fonts/files/open-sans-v18-latin-italic.woff +0 -0
  519. package/src/media/fonts/files/open-sans-v18-latin-italic.woff2 +0 -0
  520. package/src/media/fonts/files/open-sans-v18-latin-light-italic.woff +0 -0
  521. package/src/media/fonts/files/open-sans-v18-latin-light-italic.woff2 +0 -0
  522. package/src/media/fonts/files/open-sans-v18-latin-light.woff +0 -0
  523. package/src/media/fonts/files/open-sans-v18-latin-light.woff2 +0 -0
  524. package/src/media/fonts/files/open-sans-v18-latin-regular.woff +0 -0
  525. package/src/media/fonts/files/open-sans-v18-latin-regular.woff2 +0 -0
  526. package/src/test/testCode.doenet +26 -0
  527. package/src/test/testViewer.jsx +158 -0
  528. package/src/uiComponents/ActionButton.jsx +157 -0
  529. package/src/uiComponents/ActionButtonGroup.jsx +93 -0
  530. package/src/uiComponents/Button.jsx +160 -0
  531. package/src/uiComponents/ButtonGroup.jsx +56 -0
  532. package/src/uiComponents/ToggleButton.jsx +194 -0
  533. package/src/uiComponents/ToggleButtonGroup.jsx +77 -0
  534. package/src/utils/activityUtils.js +713 -0
  535. package/src/utils/array.js +17 -0
  536. package/src/utils/cid.js +34 -0
  537. package/src/utils/componentInfoObjects.js +89 -0
  538. package/src/utils/deepFunctions.js +165 -0
  539. package/src/utils/enumeration.js +226 -0
  540. package/src/utils/math.js +624 -0
  541. package/src/utils/naming.js +44 -0
  542. package/src/utils/retrieveTextFile.js +156 -0
  543. package/src/utils/returnAllPossibleVariants.js +81 -0
  544. package/src/utils/sequence.js +715 -0
  545. package/src/utils/serialize.js +29 -0
  546. package/src/utils/serializedStateProcessing.js +2587 -0
  547. package/src/utils/subset-of-reals.js +783 -0
  548. package/src/utils/url.js +19 -0
  549. package/vite.config.js +14 -0
@@ -0,0 +1,3619 @@
1
+ import me from "math-expressions";
2
+ import { cesc } from "../../../../src/utils/url";
3
+
4
+ describe("SampleRandomNumbers Tag Tests", function () {
5
+ beforeEach(() => {
6
+ cy.clearIndexedDB();
7
+ cy.visit("/src/Tools/cypressTest/");
8
+ });
9
+
10
+ it("no parameters, sample single uniform random number from 0 to 1", () => {
11
+ cy.window().then(async (win) => {
12
+ win.postMessage(
13
+ {
14
+ doenetML: `
15
+ <text>a</text>
16
+ <p><aslist>
17
+ <map>
18
+ <template><sampleRandomNumbers/></template>
19
+ <sources><sequence length="400" /></sources>
20
+ </map>
21
+ </aslist></p>
22
+
23
+ <p><aslist>
24
+ <copy target="_map1" />
25
+ </aslist></p>
26
+
27
+ <copy target="_p1" assignNames = "p" />
28
+ `,
29
+ },
30
+ "*",
31
+ );
32
+ });
33
+
34
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
35
+
36
+ cy.window().then(async (win) => {
37
+ let stateVariables = await win.returnAllStateVariables1();
38
+
39
+ let samples = stateVariables["/_map1"].replacements.map(
40
+ (x) =>
41
+ stateVariables[
42
+ stateVariables[
43
+ stateVariables[x.componentName].replacements[0].componentName
44
+ ].replacements[0].componentName
45
+ ].stateValues.value,
46
+ );
47
+
48
+ expect(samples.length).eq(400);
49
+
50
+ for (let sample of samples) {
51
+ expect(sample).gt(0);
52
+ expect(sample).lte(1);
53
+ }
54
+
55
+ let meanX = me.math.mean(samples);
56
+ let varX = me.math.variance(samples, "uncorrected");
57
+
58
+ expect(meanX).closeTo(0.5, 0.05);
59
+ expect(varX).closeTo(1 / 12, 0.015);
60
+
61
+ let firstSample =
62
+ stateVariables[
63
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
64
+ .replacements[0].componentName
65
+ ];
66
+ expect(firstSample.stateValues.mean).closeTo(0.5, 1e-10);
67
+ expect(firstSample.stateValues.variance).closeTo(1 / 12, 1e-10);
68
+ expect(firstSample.stateValues.standardDeviation).closeTo(
69
+ Math.sqrt(1 / 12),
70
+ 1e-10,
71
+ );
72
+
73
+ let copiedSamples = stateVariables["/_map1"].replacements.map(
74
+ (x) =>
75
+ stateVariables[
76
+ stateVariables[
77
+ stateVariables[x.componentName].replacements[0].componentName
78
+ ].replacements[0].componentName
79
+ ].stateValues.value,
80
+ );
81
+ expect(copiedSamples).eqls(samples);
82
+
83
+ let copiedCopiedSamples = stateVariables[
84
+ stateVariables["/p"].activeChildren[0].componentName
85
+ ].activeChildren.map(
86
+ (x) => stateVariables[x.componentName].stateValues.value,
87
+ );
88
+ expect(copiedCopiedSamples).eqls(samples);
89
+ });
90
+ });
91
+
92
+ it("sample five uniform random numbers from 0 to 8, only to specified", () => {
93
+ cy.window().then(async (win) => {
94
+ win.postMessage(
95
+ {
96
+ doenetML: `
97
+ <text>a</text>
98
+ <p><aslist>
99
+ <map>
100
+ <template><sampleRandomNumbers type="uniform" numSamples="5" to="8" /></template>
101
+ <sources><sequence length="80" /></sources>
102
+ </map>
103
+ </aslist></p>
104
+
105
+ <p><aslist>
106
+ <copy target="_map1" />
107
+ </aslist></p>
108
+
109
+ <copy target="_p1" assignNames = "p" />
110
+ `,
111
+ },
112
+ "*",
113
+ );
114
+ });
115
+
116
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
117
+
118
+ cy.window().then(async (win) => {
119
+ let stateVariables = await win.returnAllStateVariables1();
120
+
121
+ let samples = stateVariables["/_map1"].replacements.reduce(
122
+ (a, c) => [
123
+ ...a,
124
+ ...stateVariables[
125
+ stateVariables[c.componentName].replacements[0].componentName
126
+ ].replacements.map(
127
+ (y) => stateVariables[y.componentName].stateValues.value,
128
+ ),
129
+ ],
130
+ [],
131
+ );
132
+ expect(samples.length).eq(400);
133
+
134
+ for (let sample of samples) {
135
+ expect(sample).gt(0);
136
+ expect(sample).lte(8);
137
+ }
138
+
139
+ let meanX = me.math.mean(samples);
140
+ let varX = me.math.variance(samples, "uncorrected");
141
+
142
+ expect(meanX).closeTo(4, 0.5);
143
+ expect(varX).closeTo(8 ** 2 / 12, 0.8);
144
+
145
+ let firstSample =
146
+ stateVariables[
147
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
148
+ .replacements[0].componentName
149
+ ];
150
+ expect(firstSample.stateValues.mean).closeTo(4, 1e-10);
151
+ expect(firstSample.stateValues.variance).closeTo(8 ** 2 / 12, 1e-10);
152
+ expect(firstSample.stateValues.standardDeviation).closeTo(
153
+ Math.sqrt(8 ** 2 / 12),
154
+ 1e-10,
155
+ );
156
+
157
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
158
+ (a, c) => [
159
+ ...a,
160
+ ...stateVariables[
161
+ stateVariables[c.componentName].replacements[0].componentName
162
+ ].replacements.map(
163
+ (y) => stateVariables[y.componentName].stateValues.value,
164
+ ),
165
+ ],
166
+ [],
167
+ );
168
+ expect(copiedSamples).eqls(samples);
169
+
170
+ let copiedCopiedSamples = stateVariables[
171
+ stateVariables["/p"].activeChildren[0].componentName
172
+ ].activeChildren.map(
173
+ (x) => stateVariables[x.componentName].stateValues.value,
174
+ );
175
+ expect(copiedCopiedSamples).eqls(samples);
176
+ });
177
+ });
178
+
179
+ it("sample five uniform random numbers from -5 to -4, only from specified", () => {
180
+ cy.window().then(async (win) => {
181
+ win.postMessage(
182
+ {
183
+ doenetML: `
184
+ <text>a</text>
185
+ <p><aslist>
186
+ <map>
187
+ <template><sampleRandomNumbers type="uniform" numSamples="5" from="-5" /></template>
188
+ <sources><sequence length="80" /></sources>
189
+ </map>
190
+ </aslist></p>
191
+
192
+ <p><aslist>
193
+ <copy target="_map1" />
194
+ </aslist></p>
195
+
196
+ <copy target="_p1" assignNames = "p" />
197
+ `,
198
+ },
199
+ "*",
200
+ );
201
+ });
202
+
203
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
204
+
205
+ cy.window().then(async (win) => {
206
+ let stateVariables = await win.returnAllStateVariables1();
207
+
208
+ let samples = stateVariables["/_map1"].replacements.reduce(
209
+ (a, c) => [
210
+ ...a,
211
+ ...stateVariables[
212
+ stateVariables[c.componentName].replacements[0].componentName
213
+ ].replacements.map(
214
+ (y) => stateVariables[y.componentName].stateValues.value,
215
+ ),
216
+ ],
217
+ [],
218
+ );
219
+ expect(samples.length).eq(400);
220
+
221
+ for (let sample of samples) {
222
+ expect(sample).gt(-5);
223
+ expect(sample).lte(-4);
224
+ }
225
+
226
+ let meanX = me.math.mean(samples);
227
+ let varX = me.math.variance(samples, "uncorrected");
228
+
229
+ expect(meanX).closeTo(-4.5, 0.05);
230
+ expect(varX).closeTo(1 / 12, 0.015);
231
+
232
+ let firstSample =
233
+ stateVariables[
234
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
235
+ .replacements[0].componentName
236
+ ];
237
+ expect(firstSample.stateValues.mean).closeTo(-4.5, 1e-10);
238
+ expect(firstSample.stateValues.variance).closeTo(1 / 12, 1e-10);
239
+ expect(firstSample.stateValues.standardDeviation).closeTo(
240
+ Math.sqrt(1 / 12),
241
+ 1e-10,
242
+ );
243
+
244
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
245
+ (a, c) => [
246
+ ...a,
247
+ ...stateVariables[
248
+ stateVariables[c.componentName].replacements[0].componentName
249
+ ].replacements.map(
250
+ (y) => stateVariables[y.componentName].stateValues.value,
251
+ ),
252
+ ],
253
+ [],
254
+ );
255
+ expect(copiedSamples).eqls(samples);
256
+
257
+ let copiedCopiedSamples = stateVariables[
258
+ stateVariables["/p"].activeChildren[0].componentName
259
+ ].activeChildren.map(
260
+ (x) => stateVariables[x.componentName].stateValues.value,
261
+ );
262
+ expect(copiedCopiedSamples).eqls(samples);
263
+ });
264
+ });
265
+
266
+ it("sample ten uniform random numbers from -4 to -2", () => {
267
+ cy.window().then(async (win) => {
268
+ win.postMessage(
269
+ {
270
+ doenetML: `
271
+ <text>a</text>
272
+ <p><aslist>
273
+ <map>
274
+ <template><sampleRandomNumbers numSamples="10" from="-4" to="-2" /></template>
275
+ <sources><sequence length="40" /></sources>
276
+ </map>
277
+ </aslist></p>
278
+
279
+ <p><aslist>
280
+ <copy target="_map1" />
281
+ </aslist></p>
282
+
283
+ <copy target="_p1" assignNames = "p" />
284
+ `,
285
+ },
286
+ "*",
287
+ );
288
+ });
289
+
290
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
291
+
292
+ cy.window().then(async (win) => {
293
+ let stateVariables = await win.returnAllStateVariables1();
294
+
295
+ let samples = stateVariables["/_map1"].replacements.reduce(
296
+ (a, c) => [
297
+ ...a,
298
+ ...stateVariables[
299
+ stateVariables[c.componentName].replacements[0].componentName
300
+ ].replacements.map(
301
+ (y) => stateVariables[y.componentName].stateValues.value,
302
+ ),
303
+ ],
304
+ [],
305
+ );
306
+ expect(samples.length).eq(400);
307
+
308
+ for (let sample of samples) {
309
+ expect(sample).gt(-4);
310
+ expect(sample).lte(-2);
311
+ }
312
+
313
+ let meanX = me.math.mean(samples);
314
+ let varX = me.math.variance(samples, "uncorrected");
315
+
316
+ expect(meanX).closeTo(-3, 0.5);
317
+ expect(varX).closeTo(2 ** 2 / 12, 0.5);
318
+
319
+ let firstSample =
320
+ stateVariables[
321
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
322
+ .replacements[0].componentName
323
+ ];
324
+ expect(firstSample.stateValues.mean).closeTo(-3, 1e-10);
325
+ expect(firstSample.stateValues.variance).closeTo(2 ** 2 / 12, 1e-10);
326
+ expect(firstSample.stateValues.standardDeviation).closeTo(
327
+ Math.sqrt(2 ** 2 / 12),
328
+ 1e-10,
329
+ );
330
+
331
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
332
+ (a, c) => [
333
+ ...a,
334
+ ...stateVariables[
335
+ stateVariables[c.componentName].replacements[0].componentName
336
+ ].replacements.map(
337
+ (y) => stateVariables[y.componentName].stateValues.value,
338
+ ),
339
+ ],
340
+ [],
341
+ );
342
+ expect(copiedSamples).eqls(samples);
343
+
344
+ let copiedCopiedSamples = stateVariables[
345
+ stateVariables["/p"].activeChildren[0].componentName
346
+ ].activeChildren.map(
347
+ (x) => stateVariables[x.componentName].stateValues.value,
348
+ );
349
+ expect(copiedCopiedSamples).eqls(samples);
350
+ });
351
+ });
352
+
353
+ it("sample ten uniform random numbers from -2 to -4", () => {
354
+ cy.window().then(async (win) => {
355
+ win.postMessage(
356
+ {
357
+ doenetML: `
358
+ <text>a</text>
359
+ <p><aslist>
360
+ <map>
361
+ <template><sampleRandomNumbers numSamples="10" from="-2" to="-4" /></template>
362
+ <sources><sequence length="40" /></sources>
363
+ </map>
364
+ </aslist></p>
365
+
366
+ <p><aslist>
367
+ <copy target="_map1" />
368
+ </aslist></p>
369
+
370
+ <copy target="_p1" assignNames = "p" />
371
+ `,
372
+ },
373
+ "*",
374
+ );
375
+ });
376
+
377
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
378
+
379
+ cy.window().then(async (win) => {
380
+ let stateVariables = await win.returnAllStateVariables1();
381
+
382
+ let samples = stateVariables["/_map1"].replacements.reduce(
383
+ (a, c) => [
384
+ ...a,
385
+ ...stateVariables[
386
+ stateVariables[c.componentName].replacements[0].componentName
387
+ ].replacements.map(
388
+ (y) => stateVariables[y.componentName].stateValues.value,
389
+ ),
390
+ ],
391
+ [],
392
+ );
393
+ expect(samples.length).eq(400);
394
+
395
+ for (let sample of samples) {
396
+ expect(sample).gt(-4);
397
+ expect(sample).lte(-2);
398
+ }
399
+
400
+ let meanX = me.math.mean(samples);
401
+ let varX = me.math.variance(samples, "uncorrected");
402
+
403
+ expect(meanX).closeTo(-3, 0.5);
404
+ expect(varX).closeTo(2 ** 2 / 12, 0.5);
405
+
406
+ let firstSample =
407
+ stateVariables[
408
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
409
+ .replacements[0].componentName
410
+ ];
411
+ expect(firstSample.stateValues.mean).closeTo(-3, 1e-10);
412
+ expect(firstSample.stateValues.variance).closeTo(2 ** 2 / 12, 1e-10);
413
+ expect(firstSample.stateValues.standardDeviation).closeTo(
414
+ Math.sqrt(2 ** 2 / 12),
415
+ 1e-10,
416
+ );
417
+
418
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
419
+ (a, c) => [
420
+ ...a,
421
+ ...stateVariables[
422
+ stateVariables[c.componentName].replacements[0].componentName
423
+ ].replacements.map(
424
+ (y) => stateVariables[y.componentName].stateValues.value,
425
+ ),
426
+ ],
427
+ [],
428
+ );
429
+ expect(copiedSamples).eqls(samples);
430
+
431
+ let copiedCopiedSamples = stateVariables[
432
+ stateVariables["/p"].activeChildren[0].componentName
433
+ ].activeChildren.map(
434
+ (x) => stateVariables[x.componentName].stateValues.value,
435
+ );
436
+ expect(copiedCopiedSamples).eqls(samples);
437
+ });
438
+ });
439
+
440
+ it("sample twenty continuous standard normals, no parameters", () => {
441
+ cy.window().then(async (win) => {
442
+ win.postMessage(
443
+ {
444
+ doenetML: `
445
+ <text>a</text>
446
+ <p><aslist>
447
+ <map>
448
+ <template><sampleRandomNumbers type="gaussian" numSamples="20" /></template>
449
+ <sources><sequence length="20" /></sources>
450
+ </map>
451
+ </aslist></p>
452
+
453
+ <p><aslist>
454
+ <copy target="_map1" />
455
+ </aslist></p>
456
+
457
+ <copy target="_p1" assignNames = "p" />
458
+ `,
459
+ },
460
+ "*",
461
+ );
462
+ });
463
+
464
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
465
+
466
+ cy.window().then(async (win) => {
467
+ let stateVariables = await win.returnAllStateVariables1();
468
+
469
+ let samples = stateVariables["/_map1"].replacements.reduce(
470
+ (a, c) => [
471
+ ...a,
472
+ ...stateVariables[
473
+ stateVariables[c.componentName].replacements[0].componentName
474
+ ].replacements.map(
475
+ (y) => stateVariables[y.componentName].stateValues.value,
476
+ ),
477
+ ],
478
+ [],
479
+ );
480
+ expect(samples.length).eq(400);
481
+
482
+ let meanX = me.math.mean(samples);
483
+ let varX = me.math.variance(samples, "uncorrected");
484
+
485
+ expect(meanX).closeTo(0, 0.15);
486
+ expect(varX).closeTo(1, 0.2);
487
+
488
+ let firstSample =
489
+ stateVariables[
490
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
491
+ .replacements[0].componentName
492
+ ];
493
+ expect(firstSample.stateValues.mean).closeTo(0, 1e-10);
494
+ expect(firstSample.stateValues.variance).closeTo(1, 1e-10);
495
+ expect(firstSample.stateValues.standardDeviation).closeTo(
496
+ Math.sqrt(1),
497
+ 1e-10,
498
+ );
499
+
500
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
501
+ (a, c) => [
502
+ ...a,
503
+ ...stateVariables[
504
+ stateVariables[c.componentName].replacements[0].componentName
505
+ ].replacements.map(
506
+ (y) => stateVariables[y.componentName].stateValues.value,
507
+ ),
508
+ ],
509
+ [],
510
+ );
511
+ expect(copiedSamples).eqls(samples);
512
+
513
+ let copiedCopiedSamples = stateVariables[
514
+ stateVariables["/p"].activeChildren[0].componentName
515
+ ].activeChildren.map(
516
+ (x) => stateVariables[x.componentName].stateValues.value,
517
+ );
518
+ expect(copiedCopiedSamples).eqls(samples);
519
+ });
520
+ });
521
+
522
+ it("sample five continuous standard normals, unspecified mean 0, standard deviation 10", () => {
523
+ cy.window().then(async (win) => {
524
+ win.postMessage(
525
+ {
526
+ doenetML: `
527
+ <text>a</text>
528
+ <p><aslist>
529
+ <map>
530
+ <template><sampleRandomNumbers type="gaussian" numSamples="5" standardDeviation="10" /></template>
531
+ <sources><sequence length="80" /></sources>
532
+ </map>
533
+ </aslist></p>
534
+
535
+ <p><aslist>
536
+ <copy target="_map1" />
537
+ </aslist></p>
538
+
539
+ <copy target="_p1" assignNames = "p" />
540
+ `,
541
+ },
542
+ "*",
543
+ );
544
+ });
545
+
546
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
547
+
548
+ cy.window().then(async (win) => {
549
+ let stateVariables = await win.returnAllStateVariables1();
550
+
551
+ let samples = stateVariables["/_map1"].replacements.reduce(
552
+ (a, c) => [
553
+ ...a,
554
+ ...stateVariables[
555
+ stateVariables[c.componentName].replacements[0].componentName
556
+ ].replacements.map(
557
+ (y) => stateVariables[y.componentName].stateValues.value,
558
+ ),
559
+ ],
560
+ [],
561
+ );
562
+ expect(samples.length).eq(400);
563
+
564
+ let meanX = me.math.mean(samples);
565
+ let varX = me.math.variance(samples, "uncorrected");
566
+
567
+ expect(meanX).closeTo(0, 2);
568
+ expect(varX).closeTo(100, 25);
569
+
570
+ let firstSample =
571
+ stateVariables[
572
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
573
+ .replacements[0].componentName
574
+ ];
575
+ expect(firstSample.stateValues.mean).closeTo(0, 1e-10);
576
+ expect(firstSample.stateValues.variance).closeTo(100, 1e-10);
577
+ expect(firstSample.stateValues.standardDeviation).closeTo(
578
+ Math.sqrt(100),
579
+ 1e-10,
580
+ );
581
+
582
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
583
+ (a, c) => [
584
+ ...a,
585
+ ...stateVariables[
586
+ stateVariables[c.componentName].replacements[0].componentName
587
+ ].replacements.map(
588
+ (y) => stateVariables[y.componentName].stateValues.value,
589
+ ),
590
+ ],
591
+ [],
592
+ );
593
+ expect(copiedSamples).eqls(samples);
594
+
595
+ let copiedCopiedSamples = stateVariables[
596
+ stateVariables["/p"].activeChildren[0].componentName
597
+ ].activeChildren.map(
598
+ (x) => stateVariables[x.componentName].stateValues.value,
599
+ );
600
+ expect(copiedCopiedSamples).eqls(samples);
601
+ });
602
+ });
603
+
604
+ it("sample single continuous standard normal, mean -50, unspecified standard deviation 1", () => {
605
+ cy.window().then(async (win) => {
606
+ win.postMessage(
607
+ {
608
+ doenetML: `
609
+ <text>a</text>
610
+ <p><aslist>
611
+ <map>
612
+ <template><sampleRandomNumbers type="gaussian" mean="-50" /></template>
613
+ <sources><sequence length="400" /></sources>
614
+ </map>
615
+ </aslist></p>
616
+
617
+ <p><aslist>
618
+ <copy target="_map1" />
619
+ </aslist></p>
620
+
621
+ <copy target="_p1" assignNames = "p" />
622
+ `,
623
+ },
624
+ "*",
625
+ );
626
+ });
627
+
628
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
629
+
630
+ cy.window().then(async (win) => {
631
+ let stateVariables = await win.returnAllStateVariables1();
632
+
633
+ let samples = stateVariables["/_map1"].replacements.reduce(
634
+ (a, c) => [
635
+ ...a,
636
+ ...stateVariables[
637
+ stateVariables[c.componentName].replacements[0].componentName
638
+ ].replacements.map(
639
+ (y) => stateVariables[y.componentName].stateValues.value,
640
+ ),
641
+ ],
642
+ [],
643
+ );
644
+ expect(samples.length).eq(400);
645
+
646
+ let meanX = me.math.mean(samples);
647
+ let varX = me.math.variance(samples, "uncorrected");
648
+
649
+ expect(meanX).closeTo(-50, 0.2);
650
+ expect(varX).closeTo(1, 0.3);
651
+
652
+ let firstSample =
653
+ stateVariables[
654
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
655
+ .replacements[0].componentName
656
+ ];
657
+ expect(firstSample.stateValues.mean).closeTo(-50, 1e-10);
658
+ expect(firstSample.stateValues.variance).closeTo(1, 1e-10);
659
+ expect(firstSample.stateValues.standardDeviation).closeTo(
660
+ Math.sqrt(1),
661
+ 1e-10,
662
+ );
663
+
664
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
665
+ (a, c) => [
666
+ ...a,
667
+ ...stateVariables[
668
+ stateVariables[c.componentName].replacements[0].componentName
669
+ ].replacements.map(
670
+ (y) => stateVariables[y.componentName].stateValues.value,
671
+ ),
672
+ ],
673
+ [],
674
+ );
675
+ expect(copiedSamples).eqls(samples);
676
+
677
+ let copiedCopiedSamples = stateVariables[
678
+ stateVariables["/p"].activeChildren[0].componentName
679
+ ].activeChildren.map(
680
+ (x) => stateVariables[x.componentName].stateValues.value,
681
+ );
682
+ expect(copiedCopiedSamples).eqls(samples);
683
+ });
684
+ });
685
+
686
+ it("sample twenty continuous standard normals, mean 100, standard deviation 10", () => {
687
+ cy.window().then(async (win) => {
688
+ win.postMessage(
689
+ {
690
+ doenetML: `
691
+ <text>a</text>
692
+ <p><aslist>
693
+ <map>
694
+ <template><sampleRandomNumbers type="gaussian" numSamples="20" mean="100" standardDeviation="10" /></template>
695
+ <sources><sequence length="20" /></sources>
696
+ </map>
697
+ </aslist></p>
698
+
699
+ <p><aslist>
700
+ <copy target="_map1" />
701
+ </aslist></p>
702
+
703
+ <copy target="_p1" assignNames = "p" />
704
+ `,
705
+ },
706
+ "*",
707
+ );
708
+ });
709
+
710
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
711
+
712
+ cy.window().then(async (win) => {
713
+ let stateVariables = await win.returnAllStateVariables1();
714
+
715
+ let samples = stateVariables["/_map1"].replacements.reduce(
716
+ (a, c) => [
717
+ ...a,
718
+ ...stateVariables[
719
+ stateVariables[c.componentName].replacements[0].componentName
720
+ ].replacements.map(
721
+ (y) => stateVariables[y.componentName].stateValues.value,
722
+ ),
723
+ ],
724
+ [],
725
+ );
726
+ expect(samples.length).eq(400);
727
+
728
+ let meanX = me.math.mean(samples);
729
+ let varX = me.math.variance(samples, "uncorrected");
730
+
731
+ expect(meanX).closeTo(100, 2);
732
+ expect(varX).closeTo(100, 30);
733
+
734
+ let firstSample =
735
+ stateVariables[
736
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
737
+ .replacements[0].componentName
738
+ ];
739
+ expect(firstSample.stateValues.mean).closeTo(100, 1e-10);
740
+ expect(firstSample.stateValues.variance).closeTo(100, 1e-10);
741
+ expect(firstSample.stateValues.standardDeviation).closeTo(
742
+ Math.sqrt(100),
743
+ 1e-10,
744
+ );
745
+
746
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
747
+ (a, c) => [
748
+ ...a,
749
+ ...stateVariables[
750
+ stateVariables[c.componentName].replacements[0].componentName
751
+ ].replacements.map(
752
+ (y) => stateVariables[y.componentName].stateValues.value,
753
+ ),
754
+ ],
755
+ [],
756
+ );
757
+ expect(copiedSamples).eqls(samples);
758
+
759
+ let copiedCopiedSamples = stateVariables[
760
+ stateVariables["/p"].activeChildren[0].componentName
761
+ ].activeChildren.map(
762
+ (x) => stateVariables[x.componentName].stateValues.value,
763
+ );
764
+ expect(copiedCopiedSamples).eqls(samples);
765
+ });
766
+ });
767
+
768
+ it("sample twenty continuous standard normals, mean -3, variance 0.01", () => {
769
+ cy.window().then(async (win) => {
770
+ win.postMessage(
771
+ {
772
+ doenetML: `
773
+ <text>a</text>
774
+ <p><aslist>
775
+ <map>
776
+ <template><sampleRandomNumbers type="gaussian" numSamples="20" mean="-3" variance="0.01" /></template>
777
+ <sources><sequence length="20" /></sources>
778
+ </map>
779
+ </aslist></p>
780
+
781
+ <p><aslist>
782
+ <copy target="_map1" />
783
+ </aslist></p>
784
+
785
+ <copy target="_p1" assignNames = "p" />
786
+ `,
787
+ },
788
+ "*",
789
+ );
790
+ });
791
+
792
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
793
+
794
+ cy.window().then(async (win) => {
795
+ let stateVariables = await win.returnAllStateVariables1();
796
+
797
+ let samples = stateVariables["/_map1"].replacements.reduce(
798
+ (a, c) => [
799
+ ...a,
800
+ ...stateVariables[
801
+ stateVariables[c.componentName].replacements[0].componentName
802
+ ].replacements.map(
803
+ (y) => stateVariables[y.componentName].stateValues.value,
804
+ ),
805
+ ],
806
+ [],
807
+ );
808
+ expect(samples.length).eq(400);
809
+
810
+ let meanX = me.math.mean(samples);
811
+ let varX = me.math.variance(samples, "uncorrected");
812
+
813
+ expect(meanX).closeTo(-3, 0.1);
814
+ expect(varX).closeTo(0.01, 0.002);
815
+
816
+ let firstSample =
817
+ stateVariables[
818
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
819
+ .replacements[0].componentName
820
+ ];
821
+ expect(firstSample.stateValues.mean).closeTo(-3, 1e-10);
822
+ expect(firstSample.stateValues.variance).closeTo(0.01, 1e-10);
823
+ expect(firstSample.stateValues.standardDeviation).closeTo(
824
+ Math.sqrt(0.01),
825
+ 1e-10,
826
+ );
827
+
828
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
829
+ (a, c) => [
830
+ ...a,
831
+ ...stateVariables[
832
+ stateVariables[c.componentName].replacements[0].componentName
833
+ ].replacements.map(
834
+ (y) => stateVariables[y.componentName].stateValues.value,
835
+ ),
836
+ ],
837
+ [],
838
+ );
839
+ expect(copiedSamples).eqls(samples);
840
+
841
+ let copiedCopiedSamples = stateVariables[
842
+ stateVariables["/p"].activeChildren[0].componentName
843
+ ].activeChildren.map(
844
+ (x) => stateVariables[x.componentName].stateValues.value,
845
+ );
846
+ expect(copiedCopiedSamples).eqls(samples);
847
+ });
848
+ });
849
+
850
+ it("sample single discrete uniform, no parameters, integer from 0 to 1", () => {
851
+ cy.window().then(async (win) => {
852
+ win.postMessage(
853
+ {
854
+ doenetML: `
855
+ <text>a</text>
856
+ <p><aslist>
857
+ <map>
858
+ <template><sampleRandomNumbers type="discreteUniform" /></template>
859
+ <sources><sequence length="400" /></sources>
860
+ </map>
861
+ </aslist></p>
862
+
863
+ <p><aslist>
864
+ <copy target="_map1" />
865
+ </aslist></p>
866
+
867
+ <copy target="_p1" assignNames = "p" />
868
+ `,
869
+ },
870
+ "*",
871
+ );
872
+ });
873
+
874
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
875
+
876
+ cy.window().then(async (win) => {
877
+ let stateVariables = await win.returnAllStateVariables1();
878
+
879
+ let samples = stateVariables["/_map1"].replacements.reduce(
880
+ (a, c) => [
881
+ ...a,
882
+ ...stateVariables[
883
+ stateVariables[c.componentName].replacements[0].componentName
884
+ ].replacements.map(
885
+ (y) => stateVariables[y.componentName].stateValues.value,
886
+ ),
887
+ ],
888
+ [],
889
+ );
890
+ expect(samples.length).eq(400);
891
+
892
+ for (let sample of samples) {
893
+ expect([0, 1].includes(sample)).eq(true);
894
+ }
895
+
896
+ let meanX = me.math.mean(samples);
897
+ let varX = me.math.variance(samples, "uncorrected");
898
+
899
+ expect(meanX).closeTo(0.5, 0.1);
900
+ expect(varX).closeTo((2 ** 2 - 1) / 12, 0.1);
901
+
902
+ let firstSample =
903
+ stateVariables[
904
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
905
+ .replacements[0].componentName
906
+ ];
907
+ expect(firstSample.stateValues.mean).closeTo(0.5, 1e-10);
908
+ expect(firstSample.stateValues.variance).closeTo(
909
+ (2 ** 2 - 1) / 12,
910
+ 1e-10,
911
+ );
912
+ expect(firstSample.stateValues.standardDeviation).closeTo(
913
+ Math.sqrt((2 ** 2 - 1) / 12),
914
+ 1e-10,
915
+ );
916
+
917
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
918
+ (a, c) => [
919
+ ...a,
920
+ ...stateVariables[
921
+ stateVariables[c.componentName].replacements[0].componentName
922
+ ].replacements.map(
923
+ (y) => stateVariables[y.componentName].stateValues.value,
924
+ ),
925
+ ],
926
+ [],
927
+ );
928
+ expect(copiedSamples).eqls(samples);
929
+
930
+ let copiedCopiedSamples = stateVariables[
931
+ stateVariables["/p"].activeChildren[0].componentName
932
+ ].activeChildren.map(
933
+ (x) => stateVariables[x.componentName].stateValues.value,
934
+ );
935
+ expect(copiedCopiedSamples).eqls(samples);
936
+ });
937
+ });
938
+
939
+ it("sample single discrete uniform, from 0.5 to 5.5, only to specified", () => {
940
+ cy.window().then(async (win) => {
941
+ win.postMessage(
942
+ {
943
+ doenetML: `
944
+ <text>a</text>
945
+ <p><aslist>
946
+ <map>
947
+ <template><sampleRandomNumbers type="discreteUniform" to="5.5" /></template>
948
+ <sources><sequence length="400" /></sources>
949
+ </map>
950
+ </aslist></p>
951
+
952
+ <p><aslist>
953
+ <copy target="_map1" />
954
+ </aslist></p>
955
+
956
+ <copy target="_p1" assignNames = "p" />
957
+ `,
958
+ },
959
+ "*",
960
+ );
961
+ });
962
+
963
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
964
+
965
+ cy.window().then(async (win) => {
966
+ let stateVariables = await win.returnAllStateVariables1();
967
+
968
+ let samples = stateVariables["/_map1"].replacements.reduce(
969
+ (a, c) => [
970
+ ...a,
971
+ ...stateVariables[
972
+ stateVariables[c.componentName].replacements[0].componentName
973
+ ].replacements.map(
974
+ (y) => stateVariables[y.componentName].stateValues.value,
975
+ ),
976
+ ],
977
+ [],
978
+ );
979
+ expect(samples.length).eq(400);
980
+
981
+ for (let sample of samples) {
982
+ expect([0.5, 1.5, 2.5, 3.5, 4.5, 5.5].includes(sample)).eq(true);
983
+ }
984
+
985
+ let meanX = me.math.mean(samples);
986
+ let varX = me.math.variance(samples, "uncorrected");
987
+
988
+ expect(meanX).closeTo(3, 0.3);
989
+ expect(varX).closeTo((6 ** 2 - 1) / 12, 0.5);
990
+
991
+ let firstSample =
992
+ stateVariables[
993
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
994
+ .replacements[0].componentName
995
+ ];
996
+ expect(firstSample.stateValues.mean).closeTo(3, 1e-10);
997
+ expect(firstSample.stateValues.variance).closeTo(
998
+ (6 ** 2 - 1) / 12,
999
+ 1e-10,
1000
+ );
1001
+ expect(firstSample.stateValues.standardDeviation).closeTo(
1002
+ Math.sqrt((6 ** 2 - 1) / 12),
1003
+ 1e-10,
1004
+ );
1005
+
1006
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
1007
+ (a, c) => [
1008
+ ...a,
1009
+ ...stateVariables[
1010
+ stateVariables[c.componentName].replacements[0].componentName
1011
+ ].replacements.map(
1012
+ (y) => stateVariables[y.componentName].stateValues.value,
1013
+ ),
1014
+ ],
1015
+ [],
1016
+ );
1017
+ expect(copiedSamples).eqls(samples);
1018
+
1019
+ let copiedCopiedSamples = stateVariables[
1020
+ stateVariables["/p"].activeChildren[0].componentName
1021
+ ].activeChildren.map(
1022
+ (x) => stateVariables[x.componentName].stateValues.value,
1023
+ );
1024
+ expect(copiedCopiedSamples).eqls(samples);
1025
+ });
1026
+ });
1027
+
1028
+ it("sample single discrete uniform, from 8.5 to 9.5, only from specified", () => {
1029
+ cy.window().then(async (win) => {
1030
+ win.postMessage(
1031
+ {
1032
+ doenetML: `
1033
+ <text>a</text>
1034
+ <p><aslist>
1035
+ <map>
1036
+ <template><sampleRandomNumbers type="discreteUniform" from="8.5" /></template>
1037
+ <sources><sequence length="400" /></sources>
1038
+ </map>
1039
+ </aslist></p>
1040
+
1041
+ <p><aslist>
1042
+ <copy target="_map1" />
1043
+ </aslist></p>
1044
+
1045
+ <copy target="_p1" assignNames = "p" />
1046
+ `,
1047
+ },
1048
+ "*",
1049
+ );
1050
+ });
1051
+
1052
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
1053
+
1054
+ cy.window().then(async (win) => {
1055
+ let stateVariables = await win.returnAllStateVariables1();
1056
+
1057
+ let samples = stateVariables["/_map1"].replacements.reduce(
1058
+ (a, c) => [
1059
+ ...a,
1060
+ ...stateVariables[
1061
+ stateVariables[c.componentName].replacements[0].componentName
1062
+ ].replacements.map(
1063
+ (y) => stateVariables[y.componentName].stateValues.value,
1064
+ ),
1065
+ ],
1066
+ [],
1067
+ );
1068
+ expect(samples.length).eq(400);
1069
+
1070
+ for (let sample of samples) {
1071
+ expect([8.5, 9.5].includes(sample)).eq(true);
1072
+ }
1073
+
1074
+ let meanX = me.math.mean(samples);
1075
+ let varX = me.math.variance(samples, "uncorrected");
1076
+
1077
+ expect(meanX).closeTo(9, 0.1);
1078
+ expect(varX).closeTo((2 ** 2 - 1) / 12, 0.05);
1079
+
1080
+ let firstSample =
1081
+ stateVariables[
1082
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
1083
+ .replacements[0].componentName
1084
+ ];
1085
+ expect(firstSample.stateValues.mean).closeTo(9, 1e-10);
1086
+ expect(firstSample.stateValues.variance).closeTo(
1087
+ (2 ** 2 - 1) / 12,
1088
+ 1e-10,
1089
+ );
1090
+ expect(firstSample.stateValues.standardDeviation).closeTo(
1091
+ Math.sqrt((2 ** 2 - 1) / 12),
1092
+ 1e-10,
1093
+ );
1094
+
1095
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
1096
+ (a, c) => [
1097
+ ...a,
1098
+ ...stateVariables[
1099
+ stateVariables[c.componentName].replacements[0].componentName
1100
+ ].replacements.map(
1101
+ (y) => stateVariables[y.componentName].stateValues.value,
1102
+ ),
1103
+ ],
1104
+ [],
1105
+ );
1106
+ expect(copiedSamples).eqls(samples);
1107
+
1108
+ let copiedCopiedSamples = stateVariables[
1109
+ stateVariables["/p"].activeChildren[0].componentName
1110
+ ].activeChildren.map(
1111
+ (x) => stateVariables[x.componentName].stateValues.value,
1112
+ );
1113
+ expect(copiedCopiedSamples).eqls(samples);
1114
+ });
1115
+ });
1116
+
1117
+ it("sample five integers from -3 to 5", () => {
1118
+ cy.window().then(async (win) => {
1119
+ win.postMessage(
1120
+ {
1121
+ doenetML: `
1122
+ <text>a</text>
1123
+ <p><aslist>
1124
+ <map>
1125
+ <template><sampleRandomNumbers type="discreteUniform" from="-3" to="5" numSamples="5" /></template>
1126
+ <sources><sequence length="80" /></sources>
1127
+ </map>
1128
+ </aslist></p>
1129
+
1130
+ <p><aslist>
1131
+ <copy target="_map1" />
1132
+ </aslist></p>
1133
+
1134
+ <copy target="_p1" assignNames = "p" />
1135
+ `,
1136
+ },
1137
+ "*",
1138
+ );
1139
+ });
1140
+
1141
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
1142
+
1143
+ cy.window().then(async (win) => {
1144
+ let stateVariables = await win.returnAllStateVariables1();
1145
+
1146
+ let samples = stateVariables["/_map1"].replacements.reduce(
1147
+ (a, c) => [
1148
+ ...a,
1149
+ ...stateVariables[
1150
+ stateVariables[c.componentName].replacements[0].componentName
1151
+ ].replacements.map(
1152
+ (y) => stateVariables[y.componentName].stateValues.value,
1153
+ ),
1154
+ ],
1155
+ [],
1156
+ );
1157
+ expect(samples.length).eq(400);
1158
+
1159
+ for (let sample of samples) {
1160
+ expect([-3, -2, -1, 0, 1, 2, 3, 4, 5].includes(sample)).eq(true);
1161
+ }
1162
+
1163
+ let meanX = me.math.mean(samples);
1164
+ let varX = me.math.variance(samples, "uncorrected");
1165
+
1166
+ expect(meanX).closeTo(1, 0.5);
1167
+ expect(varX).closeTo((9 ** 2 - 1) / 12, 1);
1168
+
1169
+ let firstSample =
1170
+ stateVariables[
1171
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
1172
+ .replacements[0].componentName
1173
+ ];
1174
+ expect(firstSample.stateValues.mean).closeTo(1, 1e-10);
1175
+ expect(firstSample.stateValues.variance).closeTo(
1176
+ (9 ** 2 - 1) / 12,
1177
+ 1e-10,
1178
+ );
1179
+ expect(firstSample.stateValues.standardDeviation).closeTo(
1180
+ Math.sqrt((9 ** 2 - 1) / 12),
1181
+ 1e-10,
1182
+ );
1183
+
1184
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
1185
+ (a, c) => [
1186
+ ...a,
1187
+ ...stateVariables[
1188
+ stateVariables[c.componentName].replacements[0].componentName
1189
+ ].replacements.map(
1190
+ (y) => stateVariables[y.componentName].stateValues.value,
1191
+ ),
1192
+ ],
1193
+ [],
1194
+ );
1195
+ expect(copiedSamples).eqls(samples);
1196
+
1197
+ let copiedCopiedSamples = stateVariables[
1198
+ stateVariables["/p"].activeChildren[0].componentName
1199
+ ].activeChildren.map(
1200
+ (x) => stateVariables[x.componentName].stateValues.value,
1201
+ );
1202
+ expect(copiedCopiedSamples).eqls(samples);
1203
+ });
1204
+ });
1205
+
1206
+ it("sample five integers from 5 to -3 gives nothing", () => {
1207
+ cy.window().then(async (win) => {
1208
+ win.postMessage(
1209
+ {
1210
+ doenetML: `
1211
+ <text>a</text>
1212
+ <p><aslist>
1213
+ <map>
1214
+ <template><sampleRandomNumbers type="discreteUniform" from="5" to="-3" numSamples="5" /></template>
1215
+ <sources><sequence length="80" /></sources>
1216
+ </map>
1217
+ </aslist></p>
1218
+
1219
+ <p><aslist>
1220
+ <copy target="_map1" />
1221
+ </aslist></p>
1222
+
1223
+ <copy target="_p1" assignNames = "p" />
1224
+ `,
1225
+ },
1226
+ "*",
1227
+ );
1228
+ });
1229
+
1230
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
1231
+
1232
+ cy.window().then(async (win) => {
1233
+ let stateVariables = await win.returnAllStateVariables1();
1234
+
1235
+ let samples = stateVariables["/_map1"].replacements.reduce(
1236
+ (a, c) => [
1237
+ ...a,
1238
+ ...stateVariables[
1239
+ stateVariables[c.componentName].replacements[0].componentName
1240
+ ].replacements.map(
1241
+ (y) => stateVariables[y.componentName].stateValues.value,
1242
+ ),
1243
+ ],
1244
+ [],
1245
+ );
1246
+ expect(samples.length).eq(0);
1247
+
1248
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
1249
+ (a, c) => [
1250
+ ...a,
1251
+ ...stateVariables[
1252
+ stateVariables[c.componentName].replacements[0].componentName
1253
+ ].replacements.map(
1254
+ (y) => stateVariables[y.componentName].stateValues.value,
1255
+ ),
1256
+ ],
1257
+ [],
1258
+ );
1259
+ expect(copiedSamples).eqls(samples);
1260
+
1261
+ let copiedCopiedSamples = stateVariables[
1262
+ stateVariables["/p"].activeChildren[0].componentName
1263
+ ].activeChildren.map(
1264
+ (x) => stateVariables[x.componentName].stateValues.value,
1265
+ );
1266
+ expect(copiedCopiedSamples).eqls(samples);
1267
+ });
1268
+ });
1269
+
1270
+ it("sample 10 odd integers from -3 to 5", () => {
1271
+ cy.window().then(async (win) => {
1272
+ win.postMessage(
1273
+ {
1274
+ doenetML: `
1275
+ <text>a</text>
1276
+ <p><aslist>
1277
+ <map>
1278
+ <template><sampleRandomNumbers type="discreteUniform" from="-3" to="5" numSamples="10" step="2" /></template>
1279
+ <sources><sequence length="40" /></sources>
1280
+ </map>
1281
+ </aslist></p>
1282
+
1283
+ <p><aslist>
1284
+ <copy target="_map1" />
1285
+ </aslist></p>
1286
+
1287
+ <copy target="_p1" assignNames = "p" />
1288
+ `,
1289
+ },
1290
+ "*",
1291
+ );
1292
+ });
1293
+
1294
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
1295
+
1296
+ cy.window().then(async (win) => {
1297
+ let stateVariables = await win.returnAllStateVariables1();
1298
+
1299
+ let samples = stateVariables["/_map1"].replacements.reduce(
1300
+ (a, c) => [
1301
+ ...a,
1302
+ ...stateVariables[
1303
+ stateVariables[c.componentName].replacements[0].componentName
1304
+ ].replacements.map(
1305
+ (y) => stateVariables[y.componentName].stateValues.value,
1306
+ ),
1307
+ ],
1308
+ [],
1309
+ );
1310
+ expect(samples.length).eq(400);
1311
+
1312
+ for (let sample of samples) {
1313
+ expect([-3, -1, 1, 3, 5].includes(sample)).eq(true);
1314
+ }
1315
+
1316
+ let meanX = me.math.mean(samples);
1317
+ let varX = me.math.variance(samples, "uncorrected");
1318
+
1319
+ expect(meanX).closeTo(1, 0.5);
1320
+ expect(varX).closeTo(((5 ** 2 - 1) * 2 ** 2) / 12, 1);
1321
+
1322
+ let firstSample =
1323
+ stateVariables[
1324
+ stateVariables[stateVariables["/_map1"].replacements[0].componentName]
1325
+ .replacements[0].componentName
1326
+ ];
1327
+ expect(firstSample.stateValues.mean).closeTo(1, 1e-10);
1328
+ expect(firstSample.stateValues.variance).closeTo(
1329
+ ((5 ** 2 - 1) * 2 ** 2) / 12,
1330
+ 1e-10,
1331
+ );
1332
+ expect(firstSample.stateValues.standardDeviation).closeTo(
1333
+ Math.sqrt(((5 ** 2 - 1) * 2 ** 2) / 12),
1334
+ 1e-10,
1335
+ );
1336
+
1337
+ let copiedSamples = stateVariables["/_copy1"].replacements.reduce(
1338
+ (a, c) => [
1339
+ ...a,
1340
+ ...stateVariables[
1341
+ stateVariables[c.componentName].replacements[0].componentName
1342
+ ].replacements.map(
1343
+ (y) => stateVariables[y.componentName].stateValues.value,
1344
+ ),
1345
+ ],
1346
+ [],
1347
+ );
1348
+ expect(copiedSamples).eqls(samples);
1349
+
1350
+ let copiedCopiedSamples = stateVariables[
1351
+ stateVariables["/p"].activeChildren[0].componentName
1352
+ ].activeChildren.map(
1353
+ (x) => stateVariables[x.componentName].stateValues.value,
1354
+ );
1355
+ expect(copiedCopiedSamples).eqls(samples);
1356
+ });
1357
+ });
1358
+
1359
+ it("sampled number does change dynamically", () => {
1360
+ cy.window().then(async (win) => {
1361
+ win.postMessage(
1362
+ {
1363
+ doenetML: `
1364
+ <text>a</text>
1365
+ <mathinput prefill="50" name="numSamples"/>
1366
+ <mathinput prefill="10" name="maxnum"/>
1367
+ <p><aslist>
1368
+ <sampleRandomNumbers name="sample1" to="$maxnum" numSamples="$numSamples" />
1369
+ </aslist></p>
1370
+
1371
+ <mathinput prefill="180" name="numSamples2"/>
1372
+ <mathinput prefill="4" name="standardDeviation"/>
1373
+ <p><aslist>
1374
+ <sampleRandomNumbers type="gaussian" name="sample2" standardDeviation="$standardDeviation" numSamples="$numSamples2" />
1375
+ </aslist></p>
1376
+ <p>
1377
+ <copy prop="value" target="numSamples2" assignNames="numSamples2a" />
1378
+ <copy prop="value" target="standardDeviation" assignNames="standardDeviationa" />
1379
+ </p>
1380
+ `,
1381
+ },
1382
+ "*",
1383
+ );
1384
+ });
1385
+
1386
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
1387
+
1388
+ let sample1numbers, sample2numbers;
1389
+ let sample1numbersb, sample2numbersb;
1390
+ let sample1numbersc, sample2numbersc;
1391
+
1392
+ cy.window().then(async (win) => {
1393
+ let stateVariables = await win.returnAllStateVariables1();
1394
+ sample1numbers = stateVariables["/sample1"].replacements.map(
1395
+ (x) => stateVariables[x.componentName].stateValues.value,
1396
+ );
1397
+ sample2numbers = stateVariables["/sample2"].replacements.map(
1398
+ (x) => stateVariables[x.componentName].stateValues.value,
1399
+ );
1400
+ expect(sample1numbers.length).eq(50);
1401
+ expect(sample2numbers.length).eq(180);
1402
+
1403
+ for (let num of sample1numbers) {
1404
+ expect(num).gte(0);
1405
+ expect(num).lt(10);
1406
+ }
1407
+
1408
+ expect(me.math.mean(sample1numbers)).closeTo(5, 2);
1409
+ expect(me.math.variance(sample1numbers, "uncorrected")).closeTo(
1410
+ 10 ** 2 / 12,
1411
+ 3,
1412
+ );
1413
+
1414
+ expect(me.math.mean(sample2numbers)).closeTo(0, 1);
1415
+ expect(me.math.variance(sample2numbers, "uncorrected")).closeTo(16, 8);
1416
+ });
1417
+
1418
+ cy.log("Get new samples when change number of samples");
1419
+ cy.get(cesc("#\\/numSamples") + " textarea").type(
1420
+ `{end}{backspace}{backspace}70{enter}`,
1421
+ { force: true },
1422
+ );
1423
+ cy.get(cesc("#\\/numSamples2") + " textarea").type(
1424
+ `{ctrl+home}{shift+end}{backspace}160{enter}`,
1425
+ { force: true },
1426
+ );
1427
+ cy.get(cesc("#\\/numSamples2a")).should("contain.text", "160");
1428
+
1429
+ cy.window().then(async (win) => {
1430
+ let stateVariables = await win.returnAllStateVariables1();
1431
+ sample1numbersb = stateVariables["/sample1"].replacements.map(
1432
+ (x) => stateVariables[x.componentName].stateValues.value,
1433
+ );
1434
+ sample2numbersb = stateVariables["/sample2"].replacements
1435
+ .slice(
1436
+ 0,
1437
+ stateVariables["/sample2"].replacements.length -
1438
+ stateVariables["/sample2"].replacementsToWithhold,
1439
+ )
1440
+ .map((x) => stateVariables[x.componentName].stateValues.value);
1441
+ expect(sample1numbersb.length).eq(70);
1442
+ expect(sample2numbersb.length).eq(160);
1443
+
1444
+ for (let num of sample1numbersb) {
1445
+ expect(num).gte(0);
1446
+ expect(num).lt(10);
1447
+ }
1448
+
1449
+ expect(me.math.mean(sample1numbersb)).closeTo(5, 2);
1450
+ expect(me.math.variance(sample1numbersb, "uncorrected")).closeTo(
1451
+ 10 ** 2 / 12,
1452
+ 4,
1453
+ );
1454
+
1455
+ expect(me.math.mean(sample2numbersb)).closeTo(0, 1);
1456
+ expect(me.math.variance(sample2numbersb, "uncorrected")).closeTo(16, 6);
1457
+
1458
+ for (let ind = 0; ind < 10; ind++) {
1459
+ expect(sample1numbersb[ind]).not.eq(sample1numbers[ind]);
1460
+ }
1461
+ for (let ind = 0; ind < 10; ind++) {
1462
+ expect(sample2numbersb[ind]).not.eq(sample2numbers[ind]);
1463
+ }
1464
+ });
1465
+
1466
+ cy.log("Get new samples when sample parameters");
1467
+ cy.get(cesc("#\\/maxnum") + " textarea").type(
1468
+ `{end}{backspace}{backspace}4{enter}`,
1469
+ { force: true },
1470
+ );
1471
+ cy.get(cesc("#\\/standardDeviation") + " textarea").type(
1472
+ `{end}{backspace}{backspace}18{enter}`,
1473
+ { force: true },
1474
+ );
1475
+ cy.get(cesc("#\\/standardDeviationa")).should("contain.text", "18");
1476
+
1477
+ cy.window().then(async (win) => {
1478
+ let stateVariables = await win.returnAllStateVariables1();
1479
+ sample1numbersc = stateVariables["/sample1"].replacements.map(
1480
+ (x) => stateVariables[x.componentName].stateValues.value,
1481
+ );
1482
+ sample2numbersc = stateVariables["/sample2"].replacements
1483
+ .slice(
1484
+ 0,
1485
+ stateVariables["/sample2"].replacements.length -
1486
+ stateVariables["/sample2"].replacementsToWithhold,
1487
+ )
1488
+ .map((x) => stateVariables[x.componentName].stateValues.value);
1489
+ expect(sample1numbersc.length).eq(70);
1490
+ expect(sample2numbersc.length).eq(160);
1491
+
1492
+ for (let num of sample1numbersc) {
1493
+ expect(num).gte(0);
1494
+ expect(num).lt(4);
1495
+ }
1496
+ expect(me.math.mean(sample1numbersc)).closeTo(2, 1);
1497
+ expect(me.math.variance(sample1numbersc, "uncorrected")).closeTo(
1498
+ 4 ** 2 / 12,
1499
+ 1,
1500
+ );
1501
+
1502
+ expect(me.math.mean(sample2numbersc)).closeTo(0, 6);
1503
+ expect(me.math.variance(sample2numbersc, "uncorrected")).closeTo(
1504
+ 18 ** 2,
1505
+ 120,
1506
+ );
1507
+
1508
+ for (let ind = 0; ind < 10; ind++) {
1509
+ expect(sample1numbersc[ind]).not.eq(sample1numbersb[ind]);
1510
+ }
1511
+ for (let ind = 0; ind < 10; ind++) {
1512
+ expect(sample2numbersc[ind]).not.eq(sample2numbersb[ind]);
1513
+ }
1514
+ });
1515
+ });
1516
+
1517
+ it("random number doesn't resample in dynamic map", () => {
1518
+ cy.window().then(async (win) => {
1519
+ win.postMessage(
1520
+ {
1521
+ doenetML: `
1522
+ <text>a</text>
1523
+ How many numbers do you want? <mathinput />
1524
+ <p name="p1"><aslist>
1525
+ <map assignnames="a b c d e f">
1526
+ <template newNamespace>
1527
+ <sampleRandomNumbers assignnames="n" />
1528
+ </template>
1529
+ <sources>
1530
+ <sequence length="$_mathinput1" />
1531
+ </sources>
1532
+ </map>
1533
+ </aslist></p>
1534
+
1535
+ <p name="p2"><aslist><copy target="_map1" /></aslist></p>
1536
+ <p name="p3"><copy target="_aslist1" /></p>
1537
+
1538
+ <copy name="p4" target="p1" />
1539
+ <copy name="p5" target="p2" />
1540
+ <copy name="p6" target="p3" />
1541
+
1542
+ <copy name="p7" target="p4" />
1543
+ <copy name="p8" target="p5" />
1544
+ <copy name="p9" target="p6" />
1545
+ <p><copy prop="value" target="_mathinput1" assignNames="m1" /></p>
1546
+ `,
1547
+ },
1548
+ "*",
1549
+ );
1550
+ });
1551
+
1552
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
1553
+
1554
+ let samplednumbers = [];
1555
+
1556
+ cy.log("initially nothing");
1557
+ cy.window().then(async (win) => {
1558
+ let stateVariables = await win.returnAllStateVariables1();
1559
+ expect(
1560
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
1561
+ .activeChildren.length,
1562
+ ).eq(0);
1563
+ expect(
1564
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
1565
+ .activeChildren.length,
1566
+ ).eq(0);
1567
+ expect(
1568
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
1569
+ .activeChildren.length,
1570
+ ).eq(0);
1571
+ expect(
1572
+ stateVariables[
1573
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
1574
+ .activeChildren[0].componentName
1575
+ ].activeChildren.length,
1576
+ ).eq(0);
1577
+ expect(
1578
+ stateVariables[
1579
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
1580
+ .activeChildren[0].componentName
1581
+ ].activeChildren.length,
1582
+ ).eq(0);
1583
+ expect(
1584
+ stateVariables[
1585
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
1586
+ .activeChildren[0].componentName
1587
+ ].activeChildren.length,
1588
+ ).eq(0);
1589
+ expect(
1590
+ stateVariables[
1591
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
1592
+ .activeChildren[0].componentName
1593
+ ].activeChildren.length,
1594
+ ).eq(0);
1595
+ expect(
1596
+ stateVariables[
1597
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
1598
+ .activeChildren[0].componentName
1599
+ ].activeChildren.length,
1600
+ ).eq(0);
1601
+ expect(
1602
+ stateVariables[
1603
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
1604
+ .activeChildren[0].componentName
1605
+ ].activeChildren.length,
1606
+ ).eq(0);
1607
+ });
1608
+
1609
+ cy.log("sample one number");
1610
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
1611
+ `{end}{backspace}1{enter}`,
1612
+ { force: true },
1613
+ );
1614
+ cy.get(cesc("#\\/m1")).should("contain.text", "1");
1615
+ cy.window().then(async (win) => {
1616
+ let stateVariables = await win.returnAllStateVariables1();
1617
+ let n1 = stateVariables["/a/n"].stateValues.value;
1618
+ samplednumbers.push(n1);
1619
+ expect(
1620
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
1621
+ .activeChildren.length,
1622
+ ).eq(1);
1623
+ expect(
1624
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
1625
+ .activeChildren.length,
1626
+ ).eq(1);
1627
+ expect(
1628
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
1629
+ .activeChildren.length,
1630
+ ).eq(1);
1631
+ expect(
1632
+ stateVariables[
1633
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
1634
+ .activeChildren[0].componentName
1635
+ ].activeChildren.length,
1636
+ ).eq(1);
1637
+ expect(
1638
+ stateVariables[
1639
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
1640
+ .activeChildren[0].componentName
1641
+ ].activeChildren.length,
1642
+ ).eq(1);
1643
+ expect(
1644
+ stateVariables[
1645
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
1646
+ .activeChildren[0].componentName
1647
+ ].activeChildren.length,
1648
+ ).eq(1);
1649
+ expect(
1650
+ stateVariables[
1651
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
1652
+ .activeChildren[0].componentName
1653
+ ].activeChildren.length,
1654
+ ).eq(1);
1655
+ expect(
1656
+ stateVariables[
1657
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
1658
+ .activeChildren[0].componentName
1659
+ ].activeChildren.length,
1660
+ ).eq(1);
1661
+ expect(
1662
+ stateVariables[
1663
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
1664
+ .activeChildren[0].componentName
1665
+ ].activeChildren.length,
1666
+ ).eq(1);
1667
+ for (let ind = 0; ind < 1; ind++) {
1668
+ expect(
1669
+ stateVariables[
1670
+ stateVariables[
1671
+ stateVariables["/p1"].activeChildren[0].componentName
1672
+ ].activeChildren[ind].componentName
1673
+ ].stateValues.value,
1674
+ ).eq(samplednumbers[ind]);
1675
+ expect(
1676
+ stateVariables[
1677
+ stateVariables[
1678
+ stateVariables["/p2"].activeChildren[0].componentName
1679
+ ].activeChildren[ind].componentName
1680
+ ].stateValues.value,
1681
+ ).eq(samplednumbers[ind]);
1682
+ expect(
1683
+ stateVariables[
1684
+ stateVariables[
1685
+ stateVariables["/p3"].activeChildren[0].componentName
1686
+ ].activeChildren[ind].componentName
1687
+ ].stateValues.value,
1688
+ ).eq(samplednumbers[ind]);
1689
+ expect(
1690
+ stateVariables[
1691
+ stateVariables[
1692
+ stateVariables[
1693
+ stateVariables["/p4"].replacements[0].componentName
1694
+ ].activeChildren[0].componentName
1695
+ ].activeChildren[ind].componentName
1696
+ ].stateValues.value,
1697
+ ).eq(samplednumbers[ind]);
1698
+ expect(
1699
+ stateVariables[
1700
+ stateVariables[
1701
+ stateVariables[
1702
+ stateVariables["/p5"].replacements[0].componentName
1703
+ ].activeChildren[0].componentName
1704
+ ].activeChildren[ind].componentName
1705
+ ].stateValues.value,
1706
+ ).eq(samplednumbers[ind]);
1707
+ expect(
1708
+ stateVariables[
1709
+ stateVariables[
1710
+ stateVariables[
1711
+ stateVariables["/p6"].replacements[0].componentName
1712
+ ].activeChildren[0].componentName
1713
+ ].activeChildren[ind].componentName
1714
+ ].stateValues.value,
1715
+ ).eq(samplednumbers[ind]);
1716
+ expect(
1717
+ stateVariables[
1718
+ stateVariables[
1719
+ stateVariables[
1720
+ stateVariables["/p7"].replacements[0].componentName
1721
+ ].activeChildren[0].componentName
1722
+ ].activeChildren[ind].componentName
1723
+ ].stateValues.value,
1724
+ ).eq(samplednumbers[ind]);
1725
+ expect(
1726
+ stateVariables[
1727
+ stateVariables[
1728
+ stateVariables[
1729
+ stateVariables["/p8"].replacements[0].componentName
1730
+ ].activeChildren[0].componentName
1731
+ ].activeChildren[ind].componentName
1732
+ ].stateValues.value,
1733
+ ).eq(samplednumbers[ind]);
1734
+ expect(
1735
+ stateVariables[
1736
+ stateVariables[
1737
+ stateVariables[
1738
+ stateVariables["/p9"].replacements[0].componentName
1739
+ ].activeChildren[0].componentName
1740
+ ].activeChildren[ind].componentName
1741
+ ].stateValues.value,
1742
+ ).eq(samplednumbers[ind]);
1743
+ }
1744
+ });
1745
+
1746
+ cy.log("go back to nothing");
1747
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
1748
+ `{end}{backspace}0{enter}`,
1749
+ { force: true },
1750
+ );
1751
+ cy.get(cesc("#\\/m1")).should("contain.text", "0");
1752
+ cy.window().then(async (win) => {
1753
+ let stateVariables = await win.returnAllStateVariables1();
1754
+ expect(
1755
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
1756
+ .activeChildren.length,
1757
+ ).eq(0);
1758
+ expect(
1759
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
1760
+ .activeChildren.length,
1761
+ ).eq(0);
1762
+ expect(
1763
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
1764
+ .activeChildren.length,
1765
+ ).eq(0);
1766
+ expect(
1767
+ stateVariables[
1768
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
1769
+ .activeChildren[0].componentName
1770
+ ].activeChildren.length,
1771
+ ).eq(0);
1772
+ expect(
1773
+ stateVariables[
1774
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
1775
+ .activeChildren[0].componentName
1776
+ ].activeChildren.length,
1777
+ ).eq(0);
1778
+ expect(
1779
+ stateVariables[
1780
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
1781
+ .activeChildren[0].componentName
1782
+ ].activeChildren.length,
1783
+ ).eq(0);
1784
+ expect(
1785
+ stateVariables[
1786
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
1787
+ .activeChildren[0].componentName
1788
+ ].activeChildren.length,
1789
+ ).eq(0);
1790
+ expect(
1791
+ stateVariables[
1792
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
1793
+ .activeChildren[0].componentName
1794
+ ].activeChildren.length,
1795
+ ).eq(0);
1796
+ expect(
1797
+ stateVariables[
1798
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
1799
+ .activeChildren[0].componentName
1800
+ ].activeChildren.length,
1801
+ ).eq(0);
1802
+ });
1803
+
1804
+ cy.log("get same number back");
1805
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
1806
+ `{end}{backspace}1{enter}`,
1807
+ { force: true },
1808
+ );
1809
+ cy.get(cesc("#\\/m1")).should("contain.text", "1");
1810
+ cy.window().then(async (win) => {
1811
+ let stateVariables = await win.returnAllStateVariables1();
1812
+ let n1 = stateVariables["/a/n"].stateValues.value;
1813
+ expect(n1).eq(samplednumbers[0]);
1814
+ expect(
1815
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
1816
+ .activeChildren.length,
1817
+ ).eq(1);
1818
+ expect(
1819
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
1820
+ .activeChildren.length,
1821
+ ).eq(1);
1822
+ expect(
1823
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
1824
+ .activeChildren.length,
1825
+ ).eq(1);
1826
+ expect(
1827
+ stateVariables[
1828
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
1829
+ .activeChildren[0].componentName
1830
+ ].activeChildren.length,
1831
+ ).eq(1);
1832
+ expect(
1833
+ stateVariables[
1834
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
1835
+ .activeChildren[0].componentName
1836
+ ].activeChildren.length,
1837
+ ).eq(1);
1838
+ expect(
1839
+ stateVariables[
1840
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
1841
+ .activeChildren[0].componentName
1842
+ ].activeChildren.length,
1843
+ ).eq(1);
1844
+ expect(
1845
+ stateVariables[
1846
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
1847
+ .activeChildren[0].componentName
1848
+ ].activeChildren.length,
1849
+ ).eq(1);
1850
+ expect(
1851
+ stateVariables[
1852
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
1853
+ .activeChildren[0].componentName
1854
+ ].activeChildren.length,
1855
+ ).eq(1);
1856
+ expect(
1857
+ stateVariables[
1858
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
1859
+ .activeChildren[0].componentName
1860
+ ].activeChildren.length,
1861
+ ).eq(1);
1862
+
1863
+ for (let ind = 0; ind < 1; ind++) {
1864
+ expect(
1865
+ stateVariables[
1866
+ stateVariables[
1867
+ stateVariables["/p1"].activeChildren[0].componentName
1868
+ ].activeChildren[ind].componentName
1869
+ ].stateValues.value,
1870
+ ).eq(samplednumbers[ind]);
1871
+ expect(
1872
+ stateVariables[
1873
+ stateVariables[
1874
+ stateVariables["/p2"].activeChildren[0].componentName
1875
+ ].activeChildren[ind].componentName
1876
+ ].stateValues.value,
1877
+ ).eq(samplednumbers[ind]);
1878
+ expect(
1879
+ stateVariables[
1880
+ stateVariables[
1881
+ stateVariables["/p3"].activeChildren[0].componentName
1882
+ ].activeChildren[ind].componentName
1883
+ ].stateValues.value,
1884
+ ).eq(samplednumbers[ind]);
1885
+ expect(
1886
+ stateVariables[
1887
+ stateVariables[
1888
+ stateVariables[
1889
+ stateVariables["/p4"].replacements[0].componentName
1890
+ ].activeChildren[0].componentName
1891
+ ].activeChildren[ind].componentName
1892
+ ].stateValues.value,
1893
+ ).eq(samplednumbers[ind]);
1894
+ expect(
1895
+ stateVariables[
1896
+ stateVariables[
1897
+ stateVariables[
1898
+ stateVariables["/p5"].replacements[0].componentName
1899
+ ].activeChildren[0].componentName
1900
+ ].activeChildren[ind].componentName
1901
+ ].stateValues.value,
1902
+ ).eq(samplednumbers[ind]);
1903
+ expect(
1904
+ stateVariables[
1905
+ stateVariables[
1906
+ stateVariables[
1907
+ stateVariables["/p6"].replacements[0].componentName
1908
+ ].activeChildren[0].componentName
1909
+ ].activeChildren[ind].componentName
1910
+ ].stateValues.value,
1911
+ ).eq(samplednumbers[ind]);
1912
+ expect(
1913
+ stateVariables[
1914
+ stateVariables[
1915
+ stateVariables[
1916
+ stateVariables["/p7"].replacements[0].componentName
1917
+ ].activeChildren[0].componentName
1918
+ ].activeChildren[ind].componentName
1919
+ ].stateValues.value,
1920
+ ).eq(samplednumbers[ind]);
1921
+ expect(
1922
+ stateVariables[
1923
+ stateVariables[
1924
+ stateVariables[
1925
+ stateVariables["/p8"].replacements[0].componentName
1926
+ ].activeChildren[0].componentName
1927
+ ].activeChildren[ind].componentName
1928
+ ].stateValues.value,
1929
+ ).eq(samplednumbers[ind]);
1930
+ expect(
1931
+ stateVariables[
1932
+ stateVariables[
1933
+ stateVariables[
1934
+ stateVariables["/p9"].replacements[0].componentName
1935
+ ].activeChildren[0].componentName
1936
+ ].activeChildren[ind].componentName
1937
+ ].stateValues.value,
1938
+ ).eq(samplednumbers[ind]);
1939
+ }
1940
+ });
1941
+
1942
+ cy.log("get two more samples");
1943
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
1944
+ `{end}{backspace}3{enter}`,
1945
+ { force: true },
1946
+ );
1947
+ cy.get(cesc("#\\/m1")).should("contain.text", "3");
1948
+ cy.window().then(async (win) => {
1949
+ let stateVariables = await win.returnAllStateVariables1();
1950
+ let n1 = stateVariables["/a/n"].stateValues.value;
1951
+ let n2 = stateVariables["/b/n"].stateValues.value;
1952
+ let n3 = stateVariables["/c/n"].stateValues.value;
1953
+ expect(n1).eq(samplednumbers[0]);
1954
+ samplednumbers.push(n2);
1955
+ samplednumbers.push(n3);
1956
+ expect(
1957
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
1958
+ .activeChildren.length,
1959
+ ).eq(3);
1960
+ expect(
1961
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
1962
+ .activeChildren.length,
1963
+ ).eq(3);
1964
+ expect(
1965
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
1966
+ .activeChildren.length,
1967
+ ).eq(3);
1968
+ expect(
1969
+ stateVariables[
1970
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
1971
+ .activeChildren[0].componentName
1972
+ ].activeChildren.length,
1973
+ ).eq(3);
1974
+ expect(
1975
+ stateVariables[
1976
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
1977
+ .activeChildren[0].componentName
1978
+ ].activeChildren.length,
1979
+ ).eq(3);
1980
+ expect(
1981
+ stateVariables[
1982
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
1983
+ .activeChildren[0].componentName
1984
+ ].activeChildren.length,
1985
+ ).eq(3);
1986
+ expect(
1987
+ stateVariables[
1988
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
1989
+ .activeChildren[0].componentName
1990
+ ].activeChildren.length,
1991
+ ).eq(3);
1992
+ expect(
1993
+ stateVariables[
1994
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
1995
+ .activeChildren[0].componentName
1996
+ ].activeChildren.length,
1997
+ ).eq(3);
1998
+ expect(
1999
+ stateVariables[
2000
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
2001
+ .activeChildren[0].componentName
2002
+ ].activeChildren.length,
2003
+ ).eq(3);
2004
+ for (let ind = 0; ind < 3; ind++) {
2005
+ expect(
2006
+ stateVariables[
2007
+ stateVariables[
2008
+ stateVariables["/p1"].activeChildren[0].componentName
2009
+ ].activeChildren[ind].componentName
2010
+ ].stateValues.value,
2011
+ ).eq(samplednumbers[ind]);
2012
+ expect(
2013
+ stateVariables[
2014
+ stateVariables[
2015
+ stateVariables["/p2"].activeChildren[0].componentName
2016
+ ].activeChildren[ind].componentName
2017
+ ].stateValues.value,
2018
+ ).eq(samplednumbers[ind]);
2019
+ expect(
2020
+ stateVariables[
2021
+ stateVariables[
2022
+ stateVariables["/p3"].activeChildren[0].componentName
2023
+ ].activeChildren[ind].componentName
2024
+ ].stateValues.value,
2025
+ ).eq(samplednumbers[ind]);
2026
+ expect(
2027
+ stateVariables[
2028
+ stateVariables[
2029
+ stateVariables[
2030
+ stateVariables["/p4"].replacements[0].componentName
2031
+ ].activeChildren[0].componentName
2032
+ ].activeChildren[ind].componentName
2033
+ ].stateValues.value,
2034
+ ).eq(samplednumbers[ind]);
2035
+ expect(
2036
+ stateVariables[
2037
+ stateVariables[
2038
+ stateVariables[
2039
+ stateVariables["/p5"].replacements[0].componentName
2040
+ ].activeChildren[0].componentName
2041
+ ].activeChildren[ind].componentName
2042
+ ].stateValues.value,
2043
+ ).eq(samplednumbers[ind]);
2044
+ expect(
2045
+ stateVariables[
2046
+ stateVariables[
2047
+ stateVariables[
2048
+ stateVariables["/p6"].replacements[0].componentName
2049
+ ].activeChildren[0].componentName
2050
+ ].activeChildren[ind].componentName
2051
+ ].stateValues.value,
2052
+ ).eq(samplednumbers[ind]);
2053
+ expect(
2054
+ stateVariables[
2055
+ stateVariables[
2056
+ stateVariables[
2057
+ stateVariables["/p7"].replacements[0].componentName
2058
+ ].activeChildren[0].componentName
2059
+ ].activeChildren[ind].componentName
2060
+ ].stateValues.value,
2061
+ ).eq(samplednumbers[ind]);
2062
+ expect(
2063
+ stateVariables[
2064
+ stateVariables[
2065
+ stateVariables[
2066
+ stateVariables["/p8"].replacements[0].componentName
2067
+ ].activeChildren[0].componentName
2068
+ ].activeChildren[ind].componentName
2069
+ ].stateValues.value,
2070
+ ).eq(samplednumbers[ind]);
2071
+ expect(
2072
+ stateVariables[
2073
+ stateVariables[
2074
+ stateVariables[
2075
+ stateVariables["/p9"].replacements[0].componentName
2076
+ ].activeChildren[0].componentName
2077
+ ].activeChildren[ind].componentName
2078
+ ].stateValues.value,
2079
+ ).eq(samplednumbers[ind]);
2080
+ }
2081
+ });
2082
+
2083
+ cy.log("go back to nothing");
2084
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
2085
+ `{end}{backspace}0{enter}`,
2086
+ { force: true },
2087
+ );
2088
+ cy.get(cesc("#\\/m1")).should("contain.text", "0");
2089
+ cy.window().then(async (win) => {
2090
+ let stateVariables = await win.returnAllStateVariables1();
2091
+ expect(
2092
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
2093
+ .activeChildren.length,
2094
+ ).eq(0);
2095
+ expect(
2096
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
2097
+ .activeChildren.length,
2098
+ ).eq(0);
2099
+ expect(
2100
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
2101
+ .activeChildren.length,
2102
+ ).eq(0);
2103
+ expect(
2104
+ stateVariables[
2105
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
2106
+ .activeChildren[0].componentName
2107
+ ].activeChildren.length,
2108
+ ).eq(0);
2109
+ expect(
2110
+ stateVariables[
2111
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
2112
+ .activeChildren[0].componentName
2113
+ ].activeChildren.length,
2114
+ ).eq(0);
2115
+ expect(
2116
+ stateVariables[
2117
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
2118
+ .activeChildren[0].componentName
2119
+ ].activeChildren.length,
2120
+ ).eq(0);
2121
+ expect(
2122
+ stateVariables[
2123
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
2124
+ .activeChildren[0].componentName
2125
+ ].activeChildren.length,
2126
+ ).eq(0);
2127
+ expect(
2128
+ stateVariables[
2129
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
2130
+ .activeChildren[0].componentName
2131
+ ].activeChildren.length,
2132
+ ).eq(0);
2133
+ expect(
2134
+ stateVariables[
2135
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
2136
+ .activeChildren[0].componentName
2137
+ ].activeChildren.length,
2138
+ ).eq(0);
2139
+ });
2140
+
2141
+ cy.log("get first two numbers back");
2142
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
2143
+ `{end}{backspace}2{enter}`,
2144
+ { force: true },
2145
+ );
2146
+ cy.get(cesc("#\\/m1")).should("contain.text", "2");
2147
+ cy.window().then(async (win) => {
2148
+ let stateVariables = await win.returnAllStateVariables1();
2149
+ let n1 = stateVariables["/a/n"].stateValues.value;
2150
+ let n2 = stateVariables["/b/n"].stateValues.value;
2151
+ expect(n1).eq(samplednumbers[0]);
2152
+ expect(n2).eq(samplednumbers[1]);
2153
+ expect(
2154
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
2155
+ .activeChildren.length,
2156
+ ).eq(2);
2157
+ expect(
2158
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
2159
+ .activeChildren.length,
2160
+ ).eq(2);
2161
+ expect(
2162
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
2163
+ .activeChildren.length,
2164
+ ).eq(2);
2165
+ expect(
2166
+ stateVariables[
2167
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
2168
+ .activeChildren[0].componentName
2169
+ ].activeChildren.length,
2170
+ ).eq(2);
2171
+ expect(
2172
+ stateVariables[
2173
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
2174
+ .activeChildren[0].componentName
2175
+ ].activeChildren.length,
2176
+ ).eq(2);
2177
+ expect(
2178
+ stateVariables[
2179
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
2180
+ .activeChildren[0].componentName
2181
+ ].activeChildren.length,
2182
+ ).eq(2);
2183
+ expect(
2184
+ stateVariables[
2185
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
2186
+ .activeChildren[0].componentName
2187
+ ].activeChildren.length,
2188
+ ).eq(2);
2189
+ expect(
2190
+ stateVariables[
2191
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
2192
+ .activeChildren[0].componentName
2193
+ ].activeChildren.length,
2194
+ ).eq(2);
2195
+ expect(
2196
+ stateVariables[
2197
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
2198
+ .activeChildren[0].componentName
2199
+ ].activeChildren.length,
2200
+ ).eq(2);
2201
+
2202
+ for (let ind = 0; ind < 2; ind++) {
2203
+ expect(
2204
+ stateVariables[
2205
+ stateVariables[
2206
+ stateVariables["/p1"].activeChildren[0].componentName
2207
+ ].activeChildren[ind].componentName
2208
+ ].stateValues.value,
2209
+ ).eq(samplednumbers[ind]);
2210
+ expect(
2211
+ stateVariables[
2212
+ stateVariables[
2213
+ stateVariables["/p2"].activeChildren[0].componentName
2214
+ ].activeChildren[ind].componentName
2215
+ ].stateValues.value,
2216
+ ).eq(samplednumbers[ind]);
2217
+ expect(
2218
+ stateVariables[
2219
+ stateVariables[
2220
+ stateVariables["/p3"].activeChildren[0].componentName
2221
+ ].activeChildren[ind].componentName
2222
+ ].stateValues.value,
2223
+ ).eq(samplednumbers[ind]);
2224
+ expect(
2225
+ stateVariables[
2226
+ stateVariables[
2227
+ stateVariables[
2228
+ stateVariables["/p4"].replacements[0].componentName
2229
+ ].activeChildren[0].componentName
2230
+ ].activeChildren[ind].componentName
2231
+ ].stateValues.value,
2232
+ ).eq(samplednumbers[ind]);
2233
+ expect(
2234
+ stateVariables[
2235
+ stateVariables[
2236
+ stateVariables[
2237
+ stateVariables["/p5"].replacements[0].componentName
2238
+ ].activeChildren[0].componentName
2239
+ ].activeChildren[ind].componentName
2240
+ ].stateValues.value,
2241
+ ).eq(samplednumbers[ind]);
2242
+ expect(
2243
+ stateVariables[
2244
+ stateVariables[
2245
+ stateVariables[
2246
+ stateVariables["/p6"].replacements[0].componentName
2247
+ ].activeChildren[0].componentName
2248
+ ].activeChildren[ind].componentName
2249
+ ].stateValues.value,
2250
+ ).eq(samplednumbers[ind]);
2251
+ expect(
2252
+ stateVariables[
2253
+ stateVariables[
2254
+ stateVariables[
2255
+ stateVariables["/p7"].replacements[0].componentName
2256
+ ].activeChildren[0].componentName
2257
+ ].activeChildren[ind].componentName
2258
+ ].stateValues.value,
2259
+ ).eq(samplednumbers[ind]);
2260
+ expect(
2261
+ stateVariables[
2262
+ stateVariables[
2263
+ stateVariables[
2264
+ stateVariables["/p8"].replacements[0].componentName
2265
+ ].activeChildren[0].componentName
2266
+ ].activeChildren[ind].componentName
2267
+ ].stateValues.value,
2268
+ ).eq(samplednumbers[ind]);
2269
+ expect(
2270
+ stateVariables[
2271
+ stateVariables[
2272
+ stateVariables[
2273
+ stateVariables["/p9"].replacements[0].componentName
2274
+ ].activeChildren[0].componentName
2275
+ ].activeChildren[ind].componentName
2276
+ ].stateValues.value,
2277
+ ).eq(samplednumbers[ind]);
2278
+ }
2279
+ });
2280
+
2281
+ cy.log("get six total samples");
2282
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
2283
+ `{end}{backspace}6{enter}`,
2284
+ { force: true },
2285
+ );
2286
+ cy.get(cesc("#\\/m1")).should("contain.text", "6");
2287
+ cy.window().then(async (win) => {
2288
+ let stateVariables = await win.returnAllStateVariables1();
2289
+ let n1 = stateVariables["/a/n"].stateValues.value;
2290
+ let n2 = stateVariables["/b/n"].stateValues.value;
2291
+ let n3 = stateVariables["/c/n"].stateValues.value;
2292
+ let n4 = stateVariables["/d/n"].stateValues.value;
2293
+ let n5 = stateVariables["/e/n"].stateValues.value;
2294
+ let n6 = stateVariables["/f/n"].stateValues.value;
2295
+ expect(n1).eq(samplednumbers[0]);
2296
+ expect(n2).eq(samplednumbers[1]);
2297
+ expect(n3).eq(samplednumbers[2]);
2298
+ samplednumbers.push(n4);
2299
+ samplednumbers.push(n5);
2300
+ samplednumbers.push(n6);
2301
+ expect(
2302
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
2303
+ .activeChildren.length,
2304
+ ).eq(6);
2305
+ expect(
2306
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
2307
+ .activeChildren.length,
2308
+ ).eq(6);
2309
+ expect(
2310
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
2311
+ .activeChildren.length,
2312
+ ).eq(6);
2313
+ expect(
2314
+ stateVariables[
2315
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
2316
+ .activeChildren[0].componentName
2317
+ ].activeChildren.length,
2318
+ ).eq(6);
2319
+ expect(
2320
+ stateVariables[
2321
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
2322
+ .activeChildren[0].componentName
2323
+ ].activeChildren.length,
2324
+ ).eq(6);
2325
+ expect(
2326
+ stateVariables[
2327
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
2328
+ .activeChildren[0].componentName
2329
+ ].activeChildren.length,
2330
+ ).eq(6);
2331
+ expect(
2332
+ stateVariables[
2333
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
2334
+ .activeChildren[0].componentName
2335
+ ].activeChildren.length,
2336
+ ).eq(6);
2337
+ expect(
2338
+ stateVariables[
2339
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
2340
+ .activeChildren[0].componentName
2341
+ ].activeChildren.length,
2342
+ ).eq(6);
2343
+ expect(
2344
+ stateVariables[
2345
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
2346
+ .activeChildren[0].componentName
2347
+ ].activeChildren.length,
2348
+ ).eq(6);
2349
+ for (let ind = 0; ind < 6; ind++) {
2350
+ expect(
2351
+ stateVariables[
2352
+ stateVariables[
2353
+ stateVariables["/p1"].activeChildren[0].componentName
2354
+ ].activeChildren[ind].componentName
2355
+ ].stateValues.value,
2356
+ ).eq(samplednumbers[ind]);
2357
+ expect(
2358
+ stateVariables[
2359
+ stateVariables[
2360
+ stateVariables["/p2"].activeChildren[0].componentName
2361
+ ].activeChildren[ind].componentName
2362
+ ].stateValues.value,
2363
+ ).eq(samplednumbers[ind]);
2364
+ expect(
2365
+ stateVariables[
2366
+ stateVariables[
2367
+ stateVariables["/p3"].activeChildren[0].componentName
2368
+ ].activeChildren[ind].componentName
2369
+ ].stateValues.value,
2370
+ ).eq(samplednumbers[ind]);
2371
+ expect(
2372
+ stateVariables[
2373
+ stateVariables[
2374
+ stateVariables[
2375
+ stateVariables["/p4"].replacements[0].componentName
2376
+ ].activeChildren[0].componentName
2377
+ ].activeChildren[ind].componentName
2378
+ ].stateValues.value,
2379
+ ).eq(samplednumbers[ind]);
2380
+ expect(
2381
+ stateVariables[
2382
+ stateVariables[
2383
+ stateVariables[
2384
+ stateVariables["/p5"].replacements[0].componentName
2385
+ ].activeChildren[0].componentName
2386
+ ].activeChildren[ind].componentName
2387
+ ].stateValues.value,
2388
+ ).eq(samplednumbers[ind]);
2389
+ expect(
2390
+ stateVariables[
2391
+ stateVariables[
2392
+ stateVariables[
2393
+ stateVariables["/p6"].replacements[0].componentName
2394
+ ].activeChildren[0].componentName
2395
+ ].activeChildren[ind].componentName
2396
+ ].stateValues.value,
2397
+ ).eq(samplednumbers[ind]);
2398
+ expect(
2399
+ stateVariables[
2400
+ stateVariables[
2401
+ stateVariables[
2402
+ stateVariables["/p7"].replacements[0].componentName
2403
+ ].activeChildren[0].componentName
2404
+ ].activeChildren[ind].componentName
2405
+ ].stateValues.value,
2406
+ ).eq(samplednumbers[ind]);
2407
+ expect(
2408
+ stateVariables[
2409
+ stateVariables[
2410
+ stateVariables[
2411
+ stateVariables["/p8"].replacements[0].componentName
2412
+ ].activeChildren[0].componentName
2413
+ ].activeChildren[ind].componentName
2414
+ ].stateValues.value,
2415
+ ).eq(samplednumbers[ind]);
2416
+ expect(
2417
+ stateVariables[
2418
+ stateVariables[
2419
+ stateVariables[
2420
+ stateVariables["/p9"].replacements[0].componentName
2421
+ ].activeChildren[0].componentName
2422
+ ].activeChildren[ind].componentName
2423
+ ].stateValues.value,
2424
+ ).eq(samplednumbers[ind]);
2425
+ }
2426
+ });
2427
+
2428
+ cy.log("go back to nothing");
2429
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
2430
+ `{end}{backspace}0{enter}`,
2431
+ { force: true },
2432
+ );
2433
+ cy.get(cesc("#\\/m1")).should("contain.text", "0");
2434
+ cy.window().then(async (win) => {
2435
+ let stateVariables = await win.returnAllStateVariables1();
2436
+ expect(
2437
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
2438
+ .activeChildren.length,
2439
+ ).eq(0);
2440
+ expect(
2441
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
2442
+ .activeChildren.length,
2443
+ ).eq(0);
2444
+ expect(
2445
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
2446
+ .activeChildren.length,
2447
+ ).eq(0);
2448
+ expect(
2449
+ stateVariables[
2450
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
2451
+ .activeChildren[0].componentName
2452
+ ].activeChildren.length,
2453
+ ).eq(0);
2454
+ expect(
2455
+ stateVariables[
2456
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
2457
+ .activeChildren[0].componentName
2458
+ ].activeChildren.length,
2459
+ ).eq(0);
2460
+ expect(
2461
+ stateVariables[
2462
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
2463
+ .activeChildren[0].componentName
2464
+ ].activeChildren.length,
2465
+ ).eq(0);
2466
+ expect(
2467
+ stateVariables[
2468
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
2469
+ .activeChildren[0].componentName
2470
+ ].activeChildren.length,
2471
+ ).eq(0);
2472
+ expect(
2473
+ stateVariables[
2474
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
2475
+ .activeChildren[0].componentName
2476
+ ].activeChildren.length,
2477
+ ).eq(0);
2478
+ expect(
2479
+ stateVariables[
2480
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
2481
+ .activeChildren[0].componentName
2482
+ ].activeChildren.length,
2483
+ ).eq(0);
2484
+ });
2485
+
2486
+ cy.log("get all six back");
2487
+ cy.get(cesc("#\\/_mathinput1") + " textarea").type(
2488
+ `{end}{backspace}6{enter}`,
2489
+ { force: true },
2490
+ );
2491
+ cy.get(cesc("#\\/m1")).should("contain.text", "6");
2492
+ cy.window().then(async (win) => {
2493
+ let stateVariables = await win.returnAllStateVariables1();
2494
+ let n1 = stateVariables["/a/n"].stateValues.value;
2495
+ let n2 = stateVariables["/b/n"].stateValues.value;
2496
+ let n3 = stateVariables["/c/n"].stateValues.value;
2497
+ let n4 = stateVariables["/d/n"].stateValues.value;
2498
+ let n5 = stateVariables["/e/n"].stateValues.value;
2499
+ let n6 = stateVariables["/f/n"].stateValues.value;
2500
+ expect(n1).eq(samplednumbers[0]);
2501
+ expect(n2).eq(samplednumbers[1]);
2502
+ expect(n3).eq(samplednumbers[2]);
2503
+ expect(n4).eq(samplednumbers[3]);
2504
+ expect(n5).eq(samplednumbers[4]);
2505
+ expect(n6).eq(samplednumbers[5]);
2506
+ expect(
2507
+ stateVariables[stateVariables["/p1"].activeChildren[0].componentName]
2508
+ .activeChildren.length,
2509
+ ).eq(6);
2510
+ expect(
2511
+ stateVariables[stateVariables["/p2"].activeChildren[0].componentName]
2512
+ .activeChildren.length,
2513
+ ).eq(6);
2514
+ expect(
2515
+ stateVariables[stateVariables["/p3"].activeChildren[0].componentName]
2516
+ .activeChildren.length,
2517
+ ).eq(6);
2518
+ expect(
2519
+ stateVariables[
2520
+ stateVariables[stateVariables["/p4"].replacements[0].componentName]
2521
+ .activeChildren[0].componentName
2522
+ ].activeChildren.length,
2523
+ ).eq(6);
2524
+ expect(
2525
+ stateVariables[
2526
+ stateVariables[stateVariables["/p5"].replacements[0].componentName]
2527
+ .activeChildren[0].componentName
2528
+ ].activeChildren.length,
2529
+ ).eq(6);
2530
+ expect(
2531
+ stateVariables[
2532
+ stateVariables[stateVariables["/p6"].replacements[0].componentName]
2533
+ .activeChildren[0].componentName
2534
+ ].activeChildren.length,
2535
+ ).eq(6);
2536
+ expect(
2537
+ stateVariables[
2538
+ stateVariables[stateVariables["/p7"].replacements[0].componentName]
2539
+ .activeChildren[0].componentName
2540
+ ].activeChildren.length,
2541
+ ).eq(6);
2542
+ expect(
2543
+ stateVariables[
2544
+ stateVariables[stateVariables["/p8"].replacements[0].componentName]
2545
+ .activeChildren[0].componentName
2546
+ ].activeChildren.length,
2547
+ ).eq(6);
2548
+ expect(
2549
+ stateVariables[
2550
+ stateVariables[stateVariables["/p9"].replacements[0].componentName]
2551
+ .activeChildren[0].componentName
2552
+ ].activeChildren.length,
2553
+ ).eq(6);
2554
+ for (let ind = 0; ind < 6; ind++) {
2555
+ expect(
2556
+ stateVariables[
2557
+ stateVariables[
2558
+ stateVariables["/p1"].activeChildren[0].componentName
2559
+ ].activeChildren[ind].componentName
2560
+ ].stateValues.value,
2561
+ ).eq(samplednumbers[ind]);
2562
+ expect(
2563
+ stateVariables[
2564
+ stateVariables[
2565
+ stateVariables["/p2"].activeChildren[0].componentName
2566
+ ].activeChildren[ind].componentName
2567
+ ].stateValues.value,
2568
+ ).eq(samplednumbers[ind]);
2569
+ expect(
2570
+ stateVariables[
2571
+ stateVariables[
2572
+ stateVariables["/p3"].activeChildren[0].componentName
2573
+ ].activeChildren[ind].componentName
2574
+ ].stateValues.value,
2575
+ ).eq(samplednumbers[ind]);
2576
+ expect(
2577
+ stateVariables[
2578
+ stateVariables[
2579
+ stateVariables[
2580
+ stateVariables["/p4"].replacements[0].componentName
2581
+ ].activeChildren[0].componentName
2582
+ ].activeChildren[ind].componentName
2583
+ ].stateValues.value,
2584
+ ).eq(samplednumbers[ind]);
2585
+ expect(
2586
+ stateVariables[
2587
+ stateVariables[
2588
+ stateVariables[
2589
+ stateVariables["/p5"].replacements[0].componentName
2590
+ ].activeChildren[0].componentName
2591
+ ].activeChildren[ind].componentName
2592
+ ].stateValues.value,
2593
+ ).eq(samplednumbers[ind]);
2594
+ expect(
2595
+ stateVariables[
2596
+ stateVariables[
2597
+ stateVariables[
2598
+ stateVariables["/p6"].replacements[0].componentName
2599
+ ].activeChildren[0].componentName
2600
+ ].activeChildren[ind].componentName
2601
+ ].stateValues.value,
2602
+ ).eq(samplednumbers[ind]);
2603
+ expect(
2604
+ stateVariables[
2605
+ stateVariables[
2606
+ stateVariables[
2607
+ stateVariables["/p7"].replacements[0].componentName
2608
+ ].activeChildren[0].componentName
2609
+ ].activeChildren[ind].componentName
2610
+ ].stateValues.value,
2611
+ ).eq(samplednumbers[ind]);
2612
+ expect(
2613
+ stateVariables[
2614
+ stateVariables[
2615
+ stateVariables[
2616
+ stateVariables["/p8"].replacements[0].componentName
2617
+ ].activeChildren[0].componentName
2618
+ ].activeChildren[ind].componentName
2619
+ ].stateValues.value,
2620
+ ).eq(samplednumbers[ind]);
2621
+ expect(
2622
+ stateVariables[
2623
+ stateVariables[
2624
+ stateVariables[
2625
+ stateVariables["/p9"].replacements[0].componentName
2626
+ ].activeChildren[0].componentName
2627
+ ].activeChildren[ind].componentName
2628
+ ].stateValues.value,
2629
+ ).eq(samplednumbers[ind]);
2630
+ }
2631
+ });
2632
+ });
2633
+
2634
+ it("sample single discrete uniform number, assign name", () => {
2635
+ cy.window().then(async (win) => {
2636
+ win.postMessage(
2637
+ {
2638
+ doenetML: `
2639
+ <text>a</text>
2640
+ <p><sampleRandomNumbers type="discreteUniform" from="3" step="7" to="16" assignnames="u"/></p>
2641
+ <p><sampleRandomNumbers type="discreteUniform" from="3" step="7" to="16" assignnames="v"/></p>
2642
+ <p><sampleRandomNumbers type="discreteUniform" from="3" step="7" to="16" assignnames="w"/></p>
2643
+ <p><copy assignNames="u2" target="u" /></p>
2644
+ <p><copy assignNames="v2" target="v" /></p>
2645
+ <p><copy assignNames="w2" target="w" /></p>
2646
+ `,
2647
+ },
2648
+ "*",
2649
+ );
2650
+ });
2651
+
2652
+ let options = [3, 10];
2653
+
2654
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
2655
+
2656
+ cy.window().then(async (win) => {
2657
+ let stateVariables = await win.returnAllStateVariables1();
2658
+
2659
+ let u = stateVariables["/u"];
2660
+ let u2 = stateVariables["/u2"];
2661
+
2662
+ expect(options.includes(u.stateValues.value)).eq(true);
2663
+ expect(u.stateValues.value).eq(u2.stateValues.value);
2664
+
2665
+ let v = stateVariables["/v"];
2666
+ let v2 = stateVariables["/v2"];
2667
+ expect(options.includes(v.stateValues.value)).eq(true);
2668
+ expect(v.stateValues.value).eq(v2.stateValues.value);
2669
+
2670
+ let w = stateVariables["/w"];
2671
+ let w2 = stateVariables["/w2"];
2672
+ expect(options.includes(w.stateValues.value)).eq(true);
2673
+ expect(w.stateValues.value).eq(w2.stateValues.value);
2674
+ });
2675
+ });
2676
+
2677
+ it("sample multiple uniform random numbers, assign names", () => {
2678
+ cy.window().then(async (win) => {
2679
+ win.postMessage(
2680
+ {
2681
+ doenetML: `
2682
+ <text>a</text>
2683
+ <p><aslist>
2684
+ <sampleRandomNumbers name="s" from="3" to="13" assignnames="u v w" numSamples="6" displayDigits="10" />
2685
+ </aslist></p>
2686
+ <p><copy assignNames="u2" target="u" /></p>
2687
+ <p><copy assignNames="v2" target="v" /></p>
2688
+ <p><copy assignNames="w2" target="w" /></p>
2689
+ `,
2690
+ },
2691
+ "*",
2692
+ );
2693
+ });
2694
+
2695
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
2696
+
2697
+ let results = [];
2698
+
2699
+ for (let ind = 0; ind < 6; ind++) {
2700
+ cy.get(cesc("#\\/_p1") + " > :nth-child(" + (2 * ind + 4) + ")")
2701
+ .invoke("text")
2702
+ .then((text) => {
2703
+ let num = Number(text);
2704
+ results[ind] = num;
2705
+ expect(num).gte(3);
2706
+ expect(num).lt(13);
2707
+ });
2708
+ }
2709
+
2710
+ cy.log("check by name").then(() => {
2711
+ cy.get(cesc("#\\/u")).should("have.text", results[0]);
2712
+ cy.get(cesc("#\\/u2")).should("have.text", results[0]);
2713
+ cy.get(cesc("#\\/v")).should("have.text", results[1]);
2714
+ cy.get(cesc("#\\/v2")).should("have.text", results[1]);
2715
+ cy.get(cesc("#\\/w")).should("have.text", results[2]);
2716
+ cy.get(cesc("#\\/w2")).should("have.text", results[2]);
2717
+ });
2718
+ cy.window().then(async (win) => {
2719
+ let stateVariables = await win.returnAllStateVariables1();
2720
+
2721
+ let u = stateVariables["/u"];
2722
+ let u2 = stateVariables["/u2"];
2723
+ expect(u.stateValues.value).closeTo(results[0], 1e-8);
2724
+ expect(u2.stateValues.value).closeTo(results[0], 1e-8);
2725
+
2726
+ let v = stateVariables["/v"];
2727
+ let v2 = stateVariables["/v2"];
2728
+ expect(v.stateValues.value).closeTo(results[1], 1e-8);
2729
+ expect(v2.stateValues.value).closeTo(results[1], 1e-8);
2730
+
2731
+ let w = stateVariables["/w"];
2732
+ let w2 = stateVariables["/w2"];
2733
+ expect(w.stateValues.value).closeTo(results[2], 1e-8);
2734
+ expect(w2.stateValues.value).closeTo(results[2], 1e-8);
2735
+
2736
+ let s = stateVariables["/s"];
2737
+ expect(s.replacements.length).eq(6);
2738
+ for (let ind = 0; ind < 6; ind++) {
2739
+ let r = stateVariables[s.replacements[ind].componentName];
2740
+ expect(r.stateValues.value).closeTo(results[ind], 1e-8);
2741
+ }
2742
+ });
2743
+ });
2744
+
2745
+ it("sample multiple uniform random numbers, assign names, newNamespace", () => {
2746
+ cy.window().then(async (win) => {
2747
+ win.postMessage(
2748
+ {
2749
+ doenetML: `
2750
+ <text>a</text>
2751
+ <p><aslist>
2752
+ <sampleRandomNumbers name="s" newnamespace from="3" to="13" assignnames="u v w" numSamples="6" displayDigits="10" />
2753
+ </aslist></p>
2754
+ <p><copy assignNames="u2" target="s/u" /></p>
2755
+ <p><copy assignNames="v2" target="s/v" /></p>
2756
+ <p><copy assignNames="w2" target="s/w" /></p>
2757
+ `,
2758
+ },
2759
+ "*",
2760
+ );
2761
+ });
2762
+
2763
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
2764
+
2765
+ let results = [];
2766
+
2767
+ for (let ind = 0; ind < 6; ind++) {
2768
+ cy.get(cesc("#\\/_p1") + " > :nth-child(" + (2 * ind + 4) + ")")
2769
+ .invoke("text")
2770
+ .then((text) => {
2771
+ let num = Number(text);
2772
+ results[ind] = num;
2773
+ expect(num).gte(3);
2774
+ expect(num).lt(13);
2775
+ });
2776
+ }
2777
+
2778
+ cy.log("check by name").then(() => {
2779
+ cy.get(cesc("#\\/s\\/u")).should("have.text", results[0]);
2780
+ cy.get(cesc("#\\/u2")).should("have.text", results[0]);
2781
+ cy.get(cesc("#\\/s\\/v")).should("have.text", results[1]);
2782
+ cy.get(cesc("#\\/v2")).should("have.text", results[1]);
2783
+ cy.get(cesc("#\\/s\\/w")).should("have.text", results[2]);
2784
+ cy.get(cesc("#\\/w2")).should("have.text", results[2]);
2785
+ });
2786
+ cy.window().then(async (win) => {
2787
+ let stateVariables = await win.returnAllStateVariables1();
2788
+
2789
+ let u = stateVariables["/s/u"];
2790
+ let u2 = stateVariables["/u2"];
2791
+ expect(u.stateValues.value).closeTo(results[0], 1e-8);
2792
+ expect(u2.stateValues.value).closeTo(results[0], 1e-8);
2793
+
2794
+ let v = stateVariables["/s/v"];
2795
+ let v2 = stateVariables["/v2"];
2796
+ expect(v.stateValues.value).closeTo(results[1], 1e-8);
2797
+ expect(v2.stateValues.value).closeTo(results[1], 1e-8);
2798
+
2799
+ let w = stateVariables["/s/w"];
2800
+ let w2 = stateVariables["/w2"];
2801
+ expect(w.stateValues.value).closeTo(results[2], 1e-8);
2802
+ expect(w2.stateValues.value).closeTo(results[2], 1e-8);
2803
+
2804
+ let s = stateVariables["/s"];
2805
+ expect(s.replacements.length).eq(6);
2806
+ for (let ind = 0; ind < 6; ind++) {
2807
+ let r = stateVariables[s.replacements[ind].componentName];
2808
+ expect(r.stateValues.value).closeTo(results[ind], 1e-8);
2809
+ }
2810
+ });
2811
+ });
2812
+
2813
+ it("copying parameters", () => {
2814
+ cy.window().then(async (win) => {
2815
+ win.postMessage(
2816
+ {
2817
+ doenetML: `
2818
+ <text>a</text>
2819
+ <p>Number of samples <mathinput name="nSamples" prefill="10" /></p>
2820
+ <p>Specified type of random number <textinput name="type" /></p>
2821
+ <p>Specified mean <mathinput name="specifiedMean" prefill="0" /></p>
2822
+ <p>Specified variance <mathinput name="specifiedVariance" prefill="1" /></p>
2823
+ <p>Specified from <mathinput name="specifiedFrom" prefill="0" /></p>
2824
+ <p>Specified to <mathinput name="specifiedTo" prefill="1" /></p>
2825
+ <p>Specified step <mathinput name="specifiedStep" prefill="1" /></p>
2826
+ <p>Actual type: <copy prop="type" target="samples" obtainPropFromComposite assignNames="actualType" /></p>
2827
+ <p>Actual from: <copy prop="from" target="samples" obtainPropFromComposite assignNames="actualFrom" /></p>
2828
+ <p>Actual to: <copy prop="to" target="samples" obtainPropFromComposite assignNames="actualTo" /></p>
2829
+ <p>Actual step: <copy prop="step" target="samples" obtainPropFromComposite assignNames="actualStep" /></p>
2830
+ <p>Expected mean: <copy prop="mean" target="samples" obtainPropFromComposite assignNames="expectedMean" displayDigits="10" /></p>
2831
+ <p>Expected variance: <copy prop="variance" target="samples" obtainPropFromComposite assignNames="expectedVariance" displayDigits="10" /></p>
2832
+ <p>Expected standard deviation: <copy prop="standardDeviation" target="samples" obtainPropFromComposite assignNames="expectedStandardDeviation" displayDigits="10" /></p>
2833
+ <p>Resulting mean: <mean name="resultingMean" displayDigits="10">$samples</mean></p>
2834
+ <p>Resulting variance: <variance name="resultingVariance" displayDigits="10">$samples</variance></p>
2835
+ <p>Resulting standard deviation: <standardDeviation name="resultingStandardDeviation" displayDigits="10">$samples</standardDeviation></p>
2836
+ <p name="p1"><aslist>
2837
+ <sampleRandomNumbers name="samples" numSamples="$nSamples" type="$type" mean="$specifiedMean" variance="$specifiedVariance" from="$specifiedFrom" to="$specifiedTo" step="$specifiedStep" displayDigits="10" />
2838
+ </aslist></p>
2839
+ <p name="p2"><aslist><copy target="samples" /></aslist></p>
2840
+ <p name="p3"><copy target="_aslist1" /></p>
2841
+
2842
+ <copy name="p4c" target="p1" assignNames="p4" />
2843
+ <copy name="p5c" target="p2" assignNames="p5" />
2844
+ <copy name="p6c" target="p3" assignNames="p6" />
2845
+
2846
+ <copy name="p7c" target="p4c" assignNames="p7" />
2847
+ <copy name="p8c" target="p5" assignNames="p8" />
2848
+ <copy name="p9c" target="p6c" assignNames="p9" />
2849
+
2850
+ <p>
2851
+ <copy prop="value" target="nSamples" assignNames="nSamplesa" />
2852
+ <copy prop="value" target="specifiedTo" assignNames="specifiedToa" />
2853
+ <copy prop="value" target="type" assignNames="typea" />
2854
+ <copy prop="value" target="specifiedVariance" assignNames="specifiedVariancea" />
2855
+ </p>
2856
+ `,
2857
+ },
2858
+ "*",
2859
+ );
2860
+ });
2861
+
2862
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
2863
+
2864
+ let checkSamples = function ({
2865
+ numSamples,
2866
+ specifiedType,
2867
+ specifiedMean,
2868
+ specifiedVariance,
2869
+ specifiedFrom,
2870
+ specifiedTo,
2871
+ specifiedStep,
2872
+ sampleComponent,
2873
+ allowedErrorInMean,
2874
+ allowedErrorInVariance,
2875
+ checkAllSamples = true,
2876
+ stateVariables,
2877
+ }) {
2878
+ let nReplacements = sampleComponent.replacements.length;
2879
+ if (sampleComponent.replacementsToWithhold) {
2880
+ nReplacements -= sampleComponent.replacementsToWithhold;
2881
+ }
2882
+ let samples = sampleComponent.replacements
2883
+ .slice(0, nReplacements)
2884
+ .map((x) => stateVariables[x.componentName].stateValues.value);
2885
+ expect(samples.length).eq(numSamples);
2886
+
2887
+ cy.get(cesc("#\\/nSamples") + " .mq-editable-field")
2888
+ .invoke("text")
2889
+ .then((text) => {
2890
+ expect(
2891
+ text.replace(/[\s\u200B-\u200D\uFEFF]/g, "").replace(/−/, "-"),
2892
+ ).equal(numSamples.toString());
2893
+ });
2894
+ cy.get(cesc("#\\/type_input")).should("have.value", specifiedType);
2895
+ cy.get(cesc("#\\/specifiedMean") + " .mq-editable-field")
2896
+ .invoke("text")
2897
+ .then((text) => {
2898
+ expect(
2899
+ text.replace(/[\s\u200B-\u200D\uFEFF]/g, "").replace(/−/, "-"),
2900
+ ).equal(specifiedMean.toString());
2901
+ });
2902
+ cy.get(cesc("#\\/specifiedVariance") + " .mq-editable-field")
2903
+ .invoke("text")
2904
+ .then((text) => {
2905
+ expect(
2906
+ text.replace(/[\s\u200B-\u200D\uFEFF]/g, "").replace(/−/, "-"),
2907
+ ).equal(specifiedVariance.toString());
2908
+ });
2909
+ cy.get(cesc("#\\/specifiedFrom") + " .mq-editable-field")
2910
+ .invoke("text")
2911
+ .then((text) => {
2912
+ expect(
2913
+ text.replace(/[\s\u200B-\u200D\uFEFF]/g, "").replace(/−/, "-"),
2914
+ ).equal(specifiedFrom.toString());
2915
+ });
2916
+ cy.get(cesc("#\\/specifiedTo") + " .mq-editable-field")
2917
+ .invoke("text")
2918
+ .then((text) => {
2919
+ expect(
2920
+ text.replace(/[\s\u200B-\u200D\uFEFF]/g, "").replace(/−/, "-"),
2921
+ ).equal(specifiedTo.toString());
2922
+ });
2923
+ cy.get(cesc("#\\/specifiedStep") + " .mq-editable-field")
2924
+ .invoke("text")
2925
+ .then((text) => {
2926
+ expect(
2927
+ text.replace(/[\s\u200B-\u200D\uFEFF]/g, "").replace(/−/, "-"),
2928
+ ).equal(specifiedStep.toString());
2929
+ });
2930
+
2931
+ let type = specifiedType.toLowerCase();
2932
+ if (!["gaussian", "uniform", "discreteuniform"].includes(type)) {
2933
+ type = "uniform";
2934
+ }
2935
+
2936
+ cy.get(cesc("#\\/actualType")).should("have.text", type);
2937
+
2938
+ let from = specifiedFrom;
2939
+ let to = specifiedTo;
2940
+ let step = specifiedStep;
2941
+ let expectedMean = specifiedMean;
2942
+ let expectedVariance = specifiedVariance;
2943
+
2944
+ if (type === "uniform") {
2945
+ step = "NaN";
2946
+ expectedMean = (to + from) / 2;
2947
+ expectedVariance = (to - from) ** 2 / 12;
2948
+ } else if (type === "discreteuniform") {
2949
+ to = from + Math.floor((to - from) / step) * step;
2950
+ expectedMean = (to + from) / 2;
2951
+ expectedVariance =
2952
+ ((((to - from) / step + 1) ** 2 - 1) * step ** 2) / 12;
2953
+ } else {
2954
+ from = "NaN";
2955
+ to = "NaN";
2956
+ step = "NaN";
2957
+ }
2958
+
2959
+ let expectedStandardDeviation = Math.sqrt(expectedVariance);
2960
+
2961
+ cy.get(cesc(`#\\/actualFrom`)).should("have.text", from);
2962
+ cy.get(cesc(`#\\/actualTo`)).should("have.text", to);
2963
+ cy.get(cesc(`#\\/actualStep`)).should("have.text", step);
2964
+ cy.get(cesc(`#\\/expectedMean`))
2965
+ .invoke("text")
2966
+ .then((text) => {
2967
+ expect(Number(text)).closeTo(expectedMean, 1e-8);
2968
+ });
2969
+ cy.get(cesc(`#\\/expectedVariance`))
2970
+ .invoke("text")
2971
+ .then((text) => {
2972
+ expect(Number(text)).closeTo(expectedVariance, 1e-8);
2973
+ });
2974
+ cy.get(cesc(`#\\/expectedStandardDeviation`))
2975
+ .invoke("text")
2976
+ .then((text) => {
2977
+ expect(Number(text)).closeTo(expectedStandardDeviation, 1e-8);
2978
+ });
2979
+
2980
+ let resultingMean = me.math.mean(samples);
2981
+ let resultingVariance = me.math.variance(samples);
2982
+ let resultingStandardDeviation = Math.sqrt(resultingVariance);
2983
+
2984
+ cy.get(cesc(`#\\/resultingMean`) + ` .mjx-mrow`)
2985
+ .invoke("text")
2986
+ .then((text) => {
2987
+ expect(Number(text.replace(/−/, "-"))).closeTo(resultingMean, 1e-8);
2988
+ expect(resultingMean).closeTo(expectedMean, allowedErrorInMean);
2989
+ });
2990
+ cy.get(cesc(`#\\/resultingVariance`) + ` .mjx-mrow`)
2991
+ .invoke("text")
2992
+ .then((text) => {
2993
+ expect(Number(text.replace(/−/, "-"))).closeTo(
2994
+ resultingVariance,
2995
+ 1e-8,
2996
+ );
2997
+ expect(resultingVariance).closeTo(
2998
+ expectedVariance,
2999
+ allowedErrorInVariance,
3000
+ );
3001
+ });
3002
+ cy.get(cesc(`#\\/resultingStandardDeviation`) + ` .mjx-mrow`)
3003
+ .invoke("text")
3004
+ .then((text) => {
3005
+ expect(Number(text.replace(/−/, "-"))).closeTo(
3006
+ resultingStandardDeviation,
3007
+ 1e-8,
3008
+ );
3009
+ expect(resultingStandardDeviation).closeTo(
3010
+ expectedStandardDeviation,
3011
+ Math.sqrt(allowedErrorInVariance),
3012
+ );
3013
+ });
3014
+
3015
+ if (checkAllSamples) {
3016
+ for (let ind = 1; ind <= 9; ind++) {
3017
+ cy.get(cesc(`#\\/p${ind}`))
3018
+ .invoke("text")
3019
+ .then((text) => {
3020
+ let numbers = text.split(",").map(Number);
3021
+ expect(numbers.length).eq(numSamples);
3022
+ for (let [i, num] of numbers.entries()) {
3023
+ expect(num).closeTo(samples[i], 1e-8);
3024
+ }
3025
+ });
3026
+ }
3027
+ }
3028
+ };
3029
+
3030
+ let numSamples = 10;
3031
+ let specifiedType = "";
3032
+ let specifiedMean = 0;
3033
+ let specifiedVariance = 1;
3034
+ let specifiedFrom = 0;
3035
+ let specifiedTo = 1;
3036
+ let specifiedStep = 1;
3037
+
3038
+ cy.log("initial values");
3039
+ cy.window().then(async (win) => {
3040
+ let stateVariables = await win.returnAllStateVariables1();
3041
+
3042
+ checkSamples({
3043
+ numSamples,
3044
+ specifiedType,
3045
+ specifiedMean,
3046
+ specifiedVariance,
3047
+ specifiedFrom,
3048
+ specifiedTo,
3049
+ specifiedStep,
3050
+ sampleComponent: stateVariables["/samples"],
3051
+ allowedErrorInMean: 0.4,
3052
+ allowedErrorInVariance: 0.4,
3053
+ stateVariables,
3054
+ });
3055
+ });
3056
+
3057
+ cy.log("Increase number of samples").then(() => {
3058
+ numSamples = 50;
3059
+ });
3060
+ cy.get(cesc(`#\\/nSamples`) + ` textarea`).type(
3061
+ "{end}{backspace}{backspace}50{enter}",
3062
+ { force: true },
3063
+ );
3064
+ cy.get(cesc("#\\/nSamplesa")).should("contain.text", "50");
3065
+
3066
+ cy.window().then(async (win) => {
3067
+ let stateVariables = await win.returnAllStateVariables1();
3068
+
3069
+ checkSamples({
3070
+ numSamples,
3071
+ specifiedType,
3072
+ specifiedMean,
3073
+ specifiedVariance,
3074
+ specifiedFrom,
3075
+ specifiedTo,
3076
+ specifiedStep,
3077
+ sampleComponent: stateVariables["/samples"],
3078
+ allowedErrorInMean: 0.2,
3079
+ allowedErrorInVariance: 0.2,
3080
+ checkAllSamples: false,
3081
+ stateVariables,
3082
+ });
3083
+ });
3084
+
3085
+ cy.log("change from and to").then(() => {
3086
+ specifiedFrom = -3;
3087
+ specifiedTo = 0;
3088
+ });
3089
+ cy.get(cesc(`#\\/specifiedFrom`) + ` textarea`).type(
3090
+ "{end}{backspace}{backspace}-3{enter}",
3091
+ { force: true },
3092
+ );
3093
+ cy.get(cesc(`#\\/specifiedTo`) + ` textarea`).type(
3094
+ "{end}{backspace}{backspace}0{enter}",
3095
+ { force: true },
3096
+ );
3097
+ cy.get(cesc("#\\/specifiedToa")).should("contain.text", "0");
3098
+ cy.window().then(async (win) => {
3099
+ let stateVariables = await win.returnAllStateVariables1();
3100
+
3101
+ checkSamples({
3102
+ numSamples,
3103
+ specifiedType,
3104
+ specifiedMean,
3105
+ specifiedVariance,
3106
+ specifiedFrom,
3107
+ specifiedTo,
3108
+ specifiedStep,
3109
+ sampleComponent: stateVariables["/samples"],
3110
+ allowedErrorInMean: 0.4,
3111
+ allowedErrorInVariance: 0.4,
3112
+ checkAllSamples: false,
3113
+ stateVariables,
3114
+ });
3115
+ });
3116
+
3117
+ cy.log("change type to discrete uniform").then(() => {
3118
+ specifiedType = "discreteUniform";
3119
+ });
3120
+ cy.get(cesc(`#\\/type_input`)).clear().type("discreteUniform{enter}");
3121
+ cy.get(cesc("#\\/typea")).should("contain.text", "discreteUniform");
3122
+ cy.window().then(async (win) => {
3123
+ let stateVariables = await win.returnAllStateVariables1();
3124
+
3125
+ checkSamples({
3126
+ numSamples,
3127
+ specifiedType,
3128
+ specifiedMean,
3129
+ specifiedVariance,
3130
+ specifiedFrom,
3131
+ specifiedTo,
3132
+ specifiedStep,
3133
+ sampleComponent: stateVariables["/samples"],
3134
+ allowedErrorInMean: 0.4,
3135
+ allowedErrorInVariance: 0.4,
3136
+ checkAllSamples: false,
3137
+ stateVariables,
3138
+ });
3139
+ });
3140
+
3141
+ cy.log("change from, to, and step").then(() => {
3142
+ specifiedFrom = 3;
3143
+ specifiedTo = -8;
3144
+ specifiedStep = -4;
3145
+ });
3146
+ cy.get(cesc(`#\\/specifiedFrom`) + ` textarea`).type(
3147
+ "{end}{backspace}{backspace}3{enter}",
3148
+ { force: true },
3149
+ );
3150
+ cy.get(cesc(`#\\/specifiedStep`) + ` textarea`).type(
3151
+ "{end}{backspace}{backspace}-4{enter}",
3152
+ { force: true },
3153
+ );
3154
+ cy.get(cesc(`#\\/specifiedTo`) + ` textarea`).type(
3155
+ "{end}{backspace}{backspace}-8{enter}",
3156
+ { force: true },
3157
+ );
3158
+ cy.get(cesc("#\\/specifiedToa")).should("contain.text", "−8");
3159
+ cy.window().then(async (win) => {
3160
+ let stateVariables = await win.returnAllStateVariables1();
3161
+
3162
+ checkSamples({
3163
+ numSamples,
3164
+ specifiedType,
3165
+ specifiedMean,
3166
+ specifiedVariance,
3167
+ specifiedFrom,
3168
+ specifiedTo,
3169
+ specifiedStep,
3170
+ sampleComponent: stateVariables["/samples"],
3171
+ allowedErrorInMean: 1,
3172
+ allowedErrorInVariance: 3,
3173
+ checkAllSamples: false,
3174
+ stateVariables,
3175
+ });
3176
+ });
3177
+
3178
+ cy.log("change type to gaussian").then(() => {
3179
+ specifiedType = "gaussian";
3180
+ });
3181
+ cy.get(cesc(`#\\/type_input`)).clear().type("gaussian{enter}");
3182
+ cy.get(cesc("#\\/typea")).should("contain.text", "gaussian");
3183
+ cy.window().then(async (win) => {
3184
+ let stateVariables = await win.returnAllStateVariables1();
3185
+
3186
+ checkSamples({
3187
+ numSamples,
3188
+ specifiedType,
3189
+ specifiedMean,
3190
+ specifiedVariance,
3191
+ specifiedFrom,
3192
+ specifiedTo,
3193
+ specifiedStep,
3194
+ sampleComponent: stateVariables["/samples"],
3195
+ allowedErrorInMean: 0.8,
3196
+ allowedErrorInVariance: 0.8,
3197
+ checkAllSamples: false,
3198
+ stateVariables,
3199
+ });
3200
+ });
3201
+
3202
+ cy.log("change mean and variance").then(() => {
3203
+ specifiedMean = -11;
3204
+ specifiedVariance = 3;
3205
+ });
3206
+ cy.get(cesc(`#\\/specifiedMean`) + ` textarea`).type(
3207
+ "{end}{backspace}{backspace}-11{enter}",
3208
+ { force: true },
3209
+ );
3210
+ cy.get(cesc(`#\\/specifiedVariance`) + ` textarea`).type(
3211
+ "{end}{backspace}{backspace}3{enter}",
3212
+ { force: true },
3213
+ );
3214
+ cy.get(cesc(`#\\/specifiedVariancea`)).should("contain.text", "3");
3215
+ cy.window().then(async (win) => {
3216
+ let stateVariables = await win.returnAllStateVariables1();
3217
+
3218
+ checkSamples({
3219
+ numSamples,
3220
+ specifiedType,
3221
+ specifiedMean,
3222
+ specifiedVariance,
3223
+ specifiedFrom,
3224
+ specifiedTo,
3225
+ specifiedStep,
3226
+ sampleComponent: stateVariables["/samples"],
3227
+ allowedErrorInMean: 0.8,
3228
+ allowedErrorInVariance: 3,
3229
+ checkAllSamples: false,
3230
+ stateVariables,
3231
+ });
3232
+ });
3233
+
3234
+ cy.log("Increase number of samples").then(() => {
3235
+ numSamples = 200;
3236
+ });
3237
+ cy.get(cesc(`#\\/nSamples`) + ` textarea`).type(
3238
+ "{end}{backspace}{backspace}200{enter}",
3239
+ { force: true },
3240
+ );
3241
+ cy.get(cesc("#\\/nSamplesa")).should("contain.text", "200");
3242
+ cy.window().then(async (win) => {
3243
+ let stateVariables = await win.returnAllStateVariables1();
3244
+
3245
+ checkSamples({
3246
+ numSamples,
3247
+ specifiedType,
3248
+ specifiedMean,
3249
+ specifiedVariance,
3250
+ specifiedFrom,
3251
+ specifiedTo,
3252
+ specifiedStep,
3253
+ sampleComponent: stateVariables["/samples"],
3254
+ allowedErrorInMean: 0.4,
3255
+ allowedErrorInVariance: 0.8,
3256
+ checkAllSamples: false,
3257
+ stateVariables,
3258
+ });
3259
+ });
3260
+
3261
+ cy.log("Decrease number of samples").then(() => {
3262
+ numSamples = 20;
3263
+ });
3264
+ cy.get(cesc(`#\\/nSamples`) + ` textarea`).type("{end}{backspace}{enter}", {
3265
+ force: true,
3266
+ });
3267
+ cy.get(cesc("#\\/nSamplesa")).should("not.contain.text", "200");
3268
+ cy.window().then(async (win) => {
3269
+ let stateVariables = await win.returnAllStateVariables1();
3270
+
3271
+ checkSamples({
3272
+ numSamples,
3273
+ specifiedType,
3274
+ specifiedMean,
3275
+ specifiedVariance,
3276
+ specifiedFrom,
3277
+ specifiedTo,
3278
+ specifiedStep,
3279
+ sampleComponent: stateVariables["/samples"],
3280
+ allowedErrorInMean: 1,
3281
+ allowedErrorInVariance: 3,
3282
+ checkAllSamples: true,
3283
+ stateVariables,
3284
+ });
3285
+ });
3286
+ });
3287
+
3288
+ it(`different numbers when reload page if don't save state`, () => {
3289
+ let doenetML = `
3290
+ <text>a</text>
3291
+ <p><aslist>
3292
+ <map>
3293
+ <template><sampleRandomNumbers /></template>
3294
+ <sources><sequence length="100" /></sources>
3295
+ </map>
3296
+ </aslist></p>
3297
+
3298
+ `;
3299
+
3300
+ cy.window().then(async (win) => {
3301
+ win.postMessage(
3302
+ {
3303
+ doenetML,
3304
+ },
3305
+ "*",
3306
+ );
3307
+ });
3308
+
3309
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3310
+
3311
+ let samples = [];
3312
+
3313
+ cy.window().then(async (win) => {
3314
+ let stateVariables = await win.returnAllStateVariables1();
3315
+
3316
+ samples = stateVariables["/_map1"].replacements.map(
3317
+ (x) =>
3318
+ stateVariables[
3319
+ stateVariables[
3320
+ stateVariables[x.componentName].replacements[0].componentName
3321
+ ].replacements[0].componentName
3322
+ ].stateValues.value,
3323
+ );
3324
+
3325
+ expect(samples.length).eq(100);
3326
+
3327
+ for (let sample of samples) {
3328
+ expect(sample).gt(0);
3329
+ expect(sample).lte(1);
3330
+ }
3331
+ });
3332
+
3333
+ cy.reload();
3334
+
3335
+ cy.window().then(async (win) => {
3336
+ win.postMessage(
3337
+ {
3338
+ doenetML,
3339
+ },
3340
+ "*",
3341
+ );
3342
+ });
3343
+
3344
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3345
+
3346
+ cy.window().then(async (win) => {
3347
+ let stateVariables = await win.returnAllStateVariables1();
3348
+
3349
+ let samples2 = stateVariables["/_map1"].replacements.map(
3350
+ (x) =>
3351
+ stateVariables[
3352
+ stateVariables[
3353
+ stateVariables[x.componentName].replacements[0].componentName
3354
+ ].replacements[0].componentName
3355
+ ].stateValues.value,
3356
+ );
3357
+
3358
+ expect(samples2.length).eq(100);
3359
+
3360
+ for (let [ind, sample] of samples2.entries()) {
3361
+ expect(sample).gt(0);
3362
+ expect(sample).lte(1);
3363
+ expect(sample).not.eq(samples[ind]);
3364
+ }
3365
+ });
3366
+ });
3367
+
3368
+ it("same numbers when reload if save state", () => {
3369
+ let doenetML = `
3370
+ <text>a</text>
3371
+ <p><aslist>
3372
+ <map>
3373
+ <template><sampleRandomNumbers variantDeterminesSeed /></template>
3374
+ <sources><sequence length="100" /></sources>
3375
+ </map>
3376
+ </aslist></p>
3377
+
3378
+ `;
3379
+
3380
+ cy.get("#testRunner_toggleControls").click();
3381
+ cy.get("#testRunner_allowLocalState").click();
3382
+ cy.wait(100);
3383
+ cy.get("#testRunner_toggleControls").click();
3384
+
3385
+ cy.window().then(async (win) => {
3386
+ win.postMessage(
3387
+ {
3388
+ doenetML,
3389
+ },
3390
+ "*",
3391
+ );
3392
+ });
3393
+
3394
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3395
+
3396
+ let samples = [];
3397
+
3398
+ cy.window().then(async (win) => {
3399
+ let stateVariables = await win.returnAllStateVariables1();
3400
+
3401
+ samples = stateVariables["/_map1"].replacements.map(
3402
+ (x) =>
3403
+ stateVariables[
3404
+ stateVariables[
3405
+ stateVariables[x.componentName].replacements[0].componentName
3406
+ ].replacements[0].componentName
3407
+ ].stateValues.value,
3408
+ );
3409
+
3410
+ expect(samples.length).eq(100);
3411
+
3412
+ for (let sample of samples) {
3413
+ expect(sample).gt(0);
3414
+ expect(sample).lte(1);
3415
+ }
3416
+ });
3417
+
3418
+ cy.reload();
3419
+
3420
+ cy.window().then(async (win) => {
3421
+ win.postMessage(
3422
+ {
3423
+ doenetML,
3424
+ },
3425
+ "*",
3426
+ );
3427
+ });
3428
+
3429
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3430
+
3431
+ cy.window().then(async (win) => {
3432
+ let stateVariables = await win.returnAllStateVariables1();
3433
+
3434
+ let samples2 = stateVariables["/_map1"].replacements.map(
3435
+ (x) =>
3436
+ stateVariables[
3437
+ stateVariables[
3438
+ stateVariables[x.componentName].replacements[0].componentName
3439
+ ].replacements[0].componentName
3440
+ ].stateValues.value,
3441
+ );
3442
+
3443
+ expect(samples2).eqls(samples);
3444
+ });
3445
+ });
3446
+
3447
+ it("same numbers for given variant if variantDeterminesSeed", () => {
3448
+ let doenetML = `
3449
+ <text>a</text>
3450
+ <p><aslist>
3451
+ <map>
3452
+ <template><sampleRandomNumbers variantDeterminesSeed /></template>
3453
+ <sources><sequence length="100" /></sources>
3454
+ </map>
3455
+ </aslist></p>
3456
+
3457
+ `;
3458
+
3459
+ cy.window().then(async (win) => {
3460
+ win.postMessage(
3461
+ {
3462
+ doenetML,
3463
+ requestedVariantIndex: 1,
3464
+ },
3465
+ "*",
3466
+ );
3467
+ });
3468
+
3469
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3470
+
3471
+ let samples = [];
3472
+
3473
+ cy.window().then(async (win) => {
3474
+ let stateVariables = await win.returnAllStateVariables1();
3475
+
3476
+ samples = stateVariables["/_map1"].replacements.map(
3477
+ (x) =>
3478
+ stateVariables[
3479
+ stateVariables[
3480
+ stateVariables[x.componentName].replacements[0].componentName
3481
+ ].replacements[0].componentName
3482
+ ].stateValues.value,
3483
+ );
3484
+
3485
+ expect(samples.length).eq(100);
3486
+
3487
+ for (let sample of samples) {
3488
+ expect(sample).gt(0);
3489
+ expect(sample).lte(1);
3490
+ }
3491
+ });
3492
+
3493
+ cy.reload();
3494
+
3495
+ cy.window().then(async (win) => {
3496
+ win.postMessage(
3497
+ {
3498
+ doenetML,
3499
+ requestedVariantIndex: 1,
3500
+ },
3501
+ "*",
3502
+ );
3503
+ });
3504
+
3505
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3506
+
3507
+ cy.window().then(async (win) => {
3508
+ let stateVariables = await win.returnAllStateVariables1();
3509
+
3510
+ let samples2 = stateVariables["/_map1"].replacements.map(
3511
+ (x) =>
3512
+ stateVariables[
3513
+ stateVariables[
3514
+ stateVariables[x.componentName].replacements[0].componentName
3515
+ ].replacements[0].componentName
3516
+ ].stateValues.value,
3517
+ );
3518
+
3519
+ expect(samples2).eqls(samples);
3520
+ });
3521
+
3522
+ cy.reload();
3523
+
3524
+ cy.window().then(async (win) => {
3525
+ win.postMessage(
3526
+ {
3527
+ doenetML,
3528
+ requestedVariantIndex: 2,
3529
+ },
3530
+ "*",
3531
+ );
3532
+ });
3533
+
3534
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3535
+
3536
+ cy.window().then(async (win) => {
3537
+ let stateVariables = await win.returnAllStateVariables1();
3538
+
3539
+ let samples2 = stateVariables["/_map1"].replacements.map(
3540
+ (x) =>
3541
+ stateVariables[
3542
+ stateVariables[
3543
+ stateVariables[x.componentName].replacements[0].componentName
3544
+ ].replacements[0].componentName
3545
+ ].stateValues.value,
3546
+ );
3547
+
3548
+ expect(samples2.length).eq(100);
3549
+
3550
+ for (let [ind, sample] of samples2.entries()) {
3551
+ expect(sample).gt(0);
3552
+ expect(sample).lte(1);
3553
+ expect(sample).not.eq(samples[ind]);
3554
+ }
3555
+ });
3556
+ });
3557
+
3558
+ it("rounding", () => {
3559
+ cy.window().then(async (win) => {
3560
+ win.postMessage(
3561
+ {
3562
+ doenetML: `
3563
+ <text>a</text>
3564
+ <p><aslist><sampleRandomNumbers assignNames="n1" from="10" to="20" displayDigits="10" /></aslist></p>
3565
+ <p><aslist><sampleRandomNumbers assignNames="n2" from="10" to="20" displayDigits="3" ignoreDisplayDecimals /></aslist></p>
3566
+ <p><aslist><sampleRandomNumbers assignNames="n3" from="10" to="20" displayDecimals="3" ignoreDisplayDigits /></aslist></p>
3567
+ <p><aslist><sampleRandomNumbers assignNames="n4" type="discreteUniform" from="10" to="20" displayDigits="3" ignoreDisplayDecimals padZeros /></aslist></p>
3568
+
3569
+ <p><number name="n1a">$n1</number></p>
3570
+ <p><number name="n2a">$n2</number></p>
3571
+ <p><number name="n3a">$n3</number></p>
3572
+ <p><number name="n4a">$n4</number></p>
3573
+
3574
+ `,
3575
+ },
3576
+ "*",
3577
+ );
3578
+ });
3579
+
3580
+ cy.get(cesc("#\\/_text1")).should("have.text", "a"); //wait for page to load
3581
+
3582
+ cy.window().then(async (win) => {
3583
+ let stateVariables = await win.returnAllStateVariables1();
3584
+
3585
+ let n1 = stateVariables["/n1"].stateValues.value;
3586
+ let n2 = stateVariables["/n2"].stateValues.value;
3587
+ let n3 = stateVariables["/n3"].stateValues.value;
3588
+ let n4 = stateVariables["/n4"].stateValues.value;
3589
+
3590
+ cy.get(cesc("#\\/n1")).should(
3591
+ "have.text",
3592
+ String(Math.round(n1 * 10 ** 8) / 10 ** 8),
3593
+ );
3594
+ cy.get(cesc("#\\/n2")).should(
3595
+ "have.text",
3596
+ String(Math.round(n2 * 10 ** 1) / 10 ** 1),
3597
+ );
3598
+ cy.get(cesc("#\\/n3")).should(
3599
+ "have.text",
3600
+ String(Math.round(n3 * 10 ** 3) / 10 ** 3),
3601
+ );
3602
+ cy.get(cesc("#\\/n4")).should("have.text", String(n4) + ".0");
3603
+
3604
+ cy.get(cesc("#\\/n1a")).should(
3605
+ "have.text",
3606
+ String(Math.round(n1 * 10 ** 8) / 10 ** 8),
3607
+ );
3608
+ cy.get(cesc("#\\/n2a")).should(
3609
+ "have.text",
3610
+ String(Math.round(n2 * 10 ** 1) / 10 ** 1),
3611
+ );
3612
+ cy.get(cesc("#\\/n3a")).should(
3613
+ "have.text",
3614
+ String(Math.round(n3 * 10 ** 3) / 10 ** 3),
3615
+ );
3616
+ cy.get(cesc("#\\/n4a")).should("have.text", String(n4) + ".0");
3617
+ });
3618
+ });
3619
+ });