Skip to content

Commit

Permalink
flip spread with new obj to throw on list_exit_actions and probable_a…
Browse files Browse the repository at this point in the history
…ction_exits
  • Loading branch information
StoneCypher committed Jul 5, 2017
1 parent 9b30e34 commit 1c8f98e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 12 deletions.
18 changes: 13 additions & 5 deletions dist/jssm.es5.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/lib/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>jssm 3.1.6 | Documentation</title>
<title>jssm 3.1.9 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>3.1.6</code></div>
<div class='mb1'><code>3.1.9</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "3.1.6",
"version": "3.1.9",
"engines": {
"node": ">=6.0.0"
},
Expand Down
10 changes: 8 additions & 2 deletions src/js/jssm.js
Expand Up @@ -314,14 +314,20 @@ class machine<mNT, mDT> {
}
*/
list_exit_actions(whichState : mNT = this.state() ) : Array<any> { // these are mNT
return [... (this._reverse_actions.get(whichState) || new Map()).values()] // wasteful, should throw instead
const ra_base = this._reverse_actions.get(whichState);
if (!(ra_base)) { throw new Error(`No such state ${JSON.stringify(whichState)}`); }

return [... ra_base.values()]
.map ( (edgeId:number) => this._edges[edgeId] )
.filter ( (o:JssmTransition<mNT, mDT>) => o.from === whichState )
.map ( filtered => filtered.action );
}

probable_action_exits(whichState : mNT = this.state() ) : Array<any> { // these are mNT
return [... (this._reverse_actions.get(whichState) || new Map()).values()] // wasteful, should throw instead
const ra_base = this._reverse_actions.get(whichState);
if (!(ra_base)) { throw new Error(`No such state ${JSON.stringify(whichState)}`); }

return [... ra_base.values()]
.map ( (edgeId:number) => this._edges[edgeId] )
.filter ( (o:JssmTransition<mNT, mDT>) => o.from === whichState )
.map ( filtered => ( { action : filtered.action,
Expand Down
38 changes: 37 additions & 1 deletion src/js/tests/general.js
Expand Up @@ -247,6 +247,28 @@ describe('probable exits for', async it => {



describe('probable action exits', async it => {

const machine = new jssm.machine({
initial_state: 'off',
transitions:[ { from:'off', to:'red', action:'on' }, { from:'red', to:'off',action:'off' } ]
});

it('probable action exits are an array', t => t.is(true, Array.isArray(machine.probable_action_exits()) ) );
it('probable action exit 1 is on', t => t.is('on', machine.probable_action_exits()[0].action ) );

it('probable action exits are an array', t => t.is(true, Array.isArray(machine.probable_action_exits('off')) ) );
it('probable action exit 1 is on', t => t.is('on', machine.probable_action_exits('off')[0].action ) );

it('probable action exits are an array', t => t.is(true, Array.isArray(machine.probable_action_exits('red')) ) );
it('probable action exit 1 is on', t => t.is('off', machine.probable_action_exits('red')[0].action ) );

});





describe('probabilistic_transition', async it => {

const machine = new jssm.machine({
Expand Down Expand Up @@ -736,7 +758,21 @@ describe('Illegal machines', async it => {
]
});

machine.actions('no such action');
machine.list_states_having_action('no such action');

}, Error));


it('can\'t list exit states of non-action', t => t.throws(() => {

const machine = new jssm.machine({
initial_state: '1',
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical' }
]
});

machine.list_exit_actions('no such action');

}, Error));

Expand Down

0 comments on commit 1c8f98e

Please sign in to comment.