Comparing version 0.17.0 to 0.17.1
- [x] specifying the initial edges as 1-dir node edges, | ||
- [x] names, | ||
- [x] action names (edge names are unique, action names are unique-to-source,) | ||
- [ ] the probability of an edge, | ||
- [x] the probability of an edge, | ||
- [ ] being the most probable edge, | ||
- [ ] random walks | ||
- [x] which states are "complete" (that is, that an input sequence can be considered satisfactorily terminal), | ||
@@ -110,3 +111,6 @@ - [x] whether a machine is | ||
- [ ] transition probability long-term measurement | ||
- [ ] state probability long-term measurement | ||
- [ ] sanity checks | ||
- [ ] `initial_state` must be a valid `state` | ||
difference between event and action: if action isn't handled, it's an error; if event, meh |
{ | ||
"name": "jssm", | ||
"version": "0.17.0", | ||
"version": "0.17.1", | ||
"description": "A Javascript state machine with a simple API. Well tested, and typed with Flowtype. MIT License.", | ||
@@ -5,0 +5,0 @@ "main": "dist/jssm.es5.browserified.js", |
@@ -20,14 +20,15 @@ | ||
const light = new jssm.machine({ | ||
initial_state: 'red', | ||
transitions:[ | ||
{ name:'switch_warn', action: 'proceed', from:'green', to:'yellow' }, | ||
{ name:'switch_halt', action: 'proceed', from:'yellow', to:'red' }, | ||
{ name:'switch_go', action: 'proceed', from:'red', to:'green' } | ||
] | ||
}); | ||
const trs = [ | ||
{ name: 'SwitchToWarn', action: 'Proceed', from:'Green', to:'Yellow' }, | ||
{ name: 'SwitchToHalt', action: 'Proceed', from:'Yellow', to:'Red' }, | ||
{ name: 'SwitchToGo', action: 'Proceed', from:'Red', to:'Green' } | ||
], | ||
light = new jssm.machine({ | ||
initial_state : 'Red', | ||
transitions : trs | ||
}); | ||
const r_states = light.states(); | ||
it('has the right state count', t => t.is(r_states.length, 3)); | ||
['red', 'yellow', 'green'].map(c => | ||
trs.map(t => t.to).map(c => | ||
it(`has state "${c}"`, t => t.is(r_states.includes(c), true)) | ||
@@ -38,6 +39,48 @@ ); | ||
it('has the right named transition count', t => t.is(r_names.size, 3)); | ||
['switch_warn', 'switch_halt', 'switch_go'].map(a => | ||
trs.map(t => t.name).map(a => | ||
it(`has named transition "${a}"`, t => t.is(r_names.has(a), true)) | ||
); | ||
it.describe('- `proceed` walkthrough', async it2 => { | ||
it2('machine starts red', t => t.is("Red", light.state())); | ||
it2('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it2('light is now green', t => t.is("Green", light.state())); | ||
it2('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it2('light is now yellow', t => t.is("Yellow", light.state())); | ||
it2('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it2('light is red again', t => t.is("Red", light.state())); | ||
}); | ||
it.describe('- mixed - `proceed` and `transition`', async it3 => { | ||
it3('machine starts red', t => t.is("Red", light.state())); | ||
it3('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it3('light is now green', t => t.is("Green", light.state())); | ||
it3('green refuses transition red', t => t.is(false, light.transition('Red'))); | ||
it3('green still green', t => t.is("Green", light.state())); | ||
it3('green refuses transition green', t => t.is(false, light.transition('Green'))); | ||
it3('green still green', t => t.is("Green", light.state())); | ||
it3('green accepts transition yellow', t => t.is(true, light.transition('Yellow'))); | ||
it3('green now yellow', t => t.is("Yellow", light.state())); | ||
it3('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it3('light is red again', t => t.is("Red", light.state())); | ||
it3('red refuses transition yellow', t => t.is(false, light.transition('Yellow'))); | ||
it3('red still red', t => t.is("Red", light.state())); | ||
it3('red refuses transition red', t => t.is(false, light.transition('Red'))); | ||
it3('red still red', t => t.is("Red", light.state())); | ||
it3('red accepts transition green', t => t.is(true, light.transition('Green'))); | ||
it3('red now green', t => t.is("Green", light.state())); | ||
it3('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it3('light is yellow again', t => t.is("Yellow", light.state())); | ||
it3('proceed is true', t => t.is(true, light.action('Proceed'))); | ||
it3('light is finally red again', t => t.is("Red", light.state())); | ||
}); | ||
}); | ||
@@ -145,3 +188,3 @@ | ||
it.describe('transition walkthrough', async it2 => { | ||
it.describe('- `transition` walkthrough', async it2 => { | ||
@@ -148,0 +191,0 @@ it2('machine starts off', t => t.is("off", light2.state())); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44591
645