Class myphysicslab.test.TestViewerApp

Provided By
All Implemented Interfaces

Interactively run and view various engine2D tests after selecting the test to run from a set of menus. This lets us see what a test is doing; it uses the '_setup' method of the test to configure the simulation -- creating and arranging the initial state of objects. What you see should be exactly the same as what happens when running the test.

TestViewerApp examines a certain set of test classes and finds methods whose names end with '_setup' and adds the name of those tests to the menus. So it is only the 'setup' methods for the various tests that can be run here, not the actual tests.

In most cases, TestViewerApp should show the exact same results as the tests. There are a few tests that make changes outside of the _setup function for the test.

TestViewerApp has two levels of menus: a group menu for each group of tests, and another menu for individual tests. Selecting from the group menu changes what tests are available in the individual tests menu. Selecting from the individual tests menu starts that test running.

The main difference between how tests are run here in TestViewerApp versus how they are run in Engine2DTests is: in Engine2DTests we make a new ContactSim for each test, whereas in TestViewerApp we reuse the ContactSim. This is necessary because of the complex web of connections between controls, simulation, builder, etc. In future, it might be better to copy how Engine2DTests works and make a new ContactSim for each test.

WARNING: when trying to debug a test: check whether the options on the ContactSim and CollisionAdvance are different than the Engine2DTests options; such as ImpulseSim.setCollisionHandling, CollisionAdvance.setJointSmallImpacts, ContactSim.setExtraAccel, ContactSim.setExtraAccelTimeStep, the DiffEqSolver, the timeStep, etc.

How TestViewerApp Works

  • In setupSimControls, look in a set of specified classes (e.g. StraightStraightTest, CircleStraightTest, etc.)

  • Iterate over all methods in each class, looking for any methods that end with '_setup'

  • Make a list of '_setup' methods and their names

  • Make a set of menus, one menu item for each '_setup' method

  • When the menu item selected: reset the sim; run the selected '_setup' method.

Does Not Work With Advanced Compile

Under advanced compile the compiler decides that we don't need any of the tests so all of the static test classes are empty functions. This is because we find test functions to call by looking at properties of a test group object like myphysicslab.test.StraightStraightTest and then we form a menu of the functions whose name ends with _setup. But we never actually call those functions in a way that the compiler would see.

Communicating the Time Step

The reason for storing the time step in AdvanceStrategy is so that TestViewer produces same results as running a test. This is a way to communicate the time step to the TestViewer. VERY IMPORTANT for reproducing results. See TestViewer.startTest_ where we set the timestep on the SimRunner.

Communicating the Sim Rect

If a test sets a specific simulation rectangle on the ContactSim then we use that. Otherwise we try to find a rectangle that encloses all the objects and then some. See #setSimRect_.

Gravity and Damping Get Special Treatment

Because GravityLaw and DampingLaw get recreated for each test we search for them after building each test and connect the respective gravity and damping controls to them.

Another consequence is that we don't provide GravityLaw or DampingLaw to the EasyScriptParser, so these aren't as easily scriptable as in other apps. However, there are short names defined for them, so it is still relatively easy to add JavaScript to a URL script like this:


The gravity and damping controls are 'built-in' to the HTML, and there is special code for finding the HTML controls and connecting them. There is also a special method for inserting a control before these built-in gravity and damping controls, see #prependControl.

new TestViewerApp( elem_ids )

elem_ids{div_graph: string, form_terminal: string, graph_controls: string, images_dir: string, label_terminal: string, show_controls: string, show_graph: string, show_hide_form: string, show_terminal: string, sim_applet: string, sim_controls: string, term_input: string, term_output: string}

specifies the names of the HTML elementId's to look for in the HTML document; these elements are where the user interface of the simulation is created.

Instance Methods

Instance Properties

Static Properties

Type Definitions