heldentodd / xray-diffraction

This repository contains the code for one simulation, but eventually three are planned: bragg-law, Single Crystal Diffraction, and Powder Diffraction.
GNU General Public License v3.0
2 stars 1 forks source link

sim fails fuzz testing #3

Closed pixelzoom closed 4 years ago

pixelzoom commented 4 years ago

Related to #1 (code review):

  • [ ] Does the sim pass a scenery fuzz test? (run with query parameters fuzz&ea)

Running with ?fuzz&ea, the sim fails with this assertion:

assert.js:22 Uncaught Error: Assertion failed: Emitted unexpected number of args. Expected: 0 and received 1
    at window.assertions.assertFunction (assert.js:22)
    at Emitter.execute (Action.js:206)
    at Emitter.emit (Emitter.js:58)
    at XrayDiffractionModel.step (XrayDiffractionModel.js:80)
    at Sim.js:277
    at Action.execute (Action.js:225)
    at Sim.stepSimulation (Sim.js:945)
    at Sim.stepOneFrame (Sim.js:935)
    at Sim.runAnimationLoop (Sim.js:918)
pixelzoom commented 4 years ago

The above Error is due to an incorrect definition of stepEmitter. Here's a diff showing the fix that you should apply:

-      this.stepEmitter = new Emitter( { validators: [ { valueType: 'number' } ] } );
+      this.stepEmitter = new Emitter( { parameters: [ { valueType: 'number' } ] } );

After I made that change in my local copy, I hit another assertion failure:

assert.js:22 Uncaught Error: Assertion failed: The CSS string is an invalid color: hsl(1020, 100%, 50%)
    at window.assertions.assertFunction (assert.js:22)
    at Function.Color.checkPaintString (Color.js:791)
    at Path.setStroke (Paintable.js:198)
    at Path.set stroke [as stroke] (Paintable.js:211)
    at Node.js:5226
    at arrayEach (lodash-4.17.4.js:537)
    at Function.forEach (lodash-4.17.4.js:9359)
    at Path.mutate (Node.js:5213)
    at new Path (Path.js:84)
    at new LightPathNode (LightPathNode.js:77)

So there is some work to be done here for fuzz testing.

pixelzoom commented 4 years ago

By the way... ?fuzz runs the sim in a mode where user-input events are automatically synthesized, and used to exercise the sim. We refer to this a "fuzz testing the sim". There's no intelligence behind it, so think of it as 1000 monkeys pounding away on your sim.

And it's a good idea to always run with ?ea (enable assertions) while developing your code. Assertions are designed to catch programming errors.

heldentodd commented 4 years ago

I did the fuzz&ea test, and I think it's a great thing to have. However, I'm not seeing the assertion failure. It seems to run fine on Chrome, even with the debugger open. Should I be looking somewhere besides the console? Also it looks like it will run forever. How long should I let it run?

In any case I will be fixing the assertion failures you found. Thanks.

pixelzoom commented 4 years ago

I don't understand your question. It looks like you fixed the 2 assertion errors, in https://github.com/heldentodd/xray-diffraction/commit/102086c49c6e13f31b51a52f99a264a0f5dfe35b and https://github.com/heldentodd/xray-diffraction/commit/e7b6d9a2c2835766d959ffc6726eef547946678a. Prior to that, you should have seen the assertion errors in the browser console, and they should have occurred rather quickly. Your URL should have looked something like: http://localhost/~cmalley/GitHub/xray-diffraction/xray-diffraction_en.html?fuzz&ea

heldentodd commented 4 years ago

The color hue is now mapped between 0-360. I had just assumed that the underlying code would do this anyway, but I guess it might not on some browser.

I'm seeing the assertion errors now. I don't know what was wrong earlier. Thanks.