Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert actions to spec. convert array_transitions to spec.
- Loading branch information
1 parent
fb301b6
commit a2b70f9
Showing
5 changed files
with
241 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
|
||
/* eslint-disable max-len */ | ||
|
||
const jssm = require('../../../build/jssm.es5.cjs.js'), | ||
sm = jssm.sm; | ||
|
||
|
||
|
||
describe('Reports on actions', () => { | ||
|
||
const roa_machine = new jssm.Machine({ | ||
start_states: ['off'], | ||
transitions:[ { name:'turn_on', action:'power_on', from:'off', to:'red'} ] | ||
}); | ||
|
||
const roa_la = roa_machine.list_actions(); // todo comeback | ||
|
||
test('Actions that it has', () => expect( typeof roa_machine.current_action_for('power_on') ).toBe('number') ); | ||
test('Actions that it doesn\'t have', () => expect( typeof roa_machine.current_action_for('power_left') ).toBe('undefined') ); | ||
test('Correct list type', () => expect( Array.isArray(roa_la) ).toBe(true) ); | ||
test('Correct list size', () => expect( roa_la.length ).toBe(1) ); | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('Actions', () => { | ||
|
||
const act_machine = new jssm.Machine({ | ||
start_states: ['off'], | ||
transitions:[ { from:'off', to:'red', action:'on' }, { from:'red', to:'off',action:'off' } ] | ||
}); | ||
|
||
test('Red has actions().length 1', () => expect( act_machine.actions().length ).toBe(1) ); | ||
test('Red has actions()[0] "on"', () => expect( act_machine.actions()[0] ).toBe('on') ); | ||
|
||
test('Red has actions().length 1 again', () => expect( act_machine.actions('off').length ).toBe(1) ); | ||
test('Red has actions()[0] "on" again', () => expect( act_machine.actions('off')[0] ).toBe('on') ); | ||
|
||
test('Red has actions().length 1 re-again', () => expect( act_machine.actions('red').length ).toBe(1) ); | ||
test('Red has actions()[0] "off" re-again', () => expect( act_machine.actions('red')[0] ).toBe('off') ); | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('States having actions', () => { | ||
|
||
const sha_machine = new jssm.Machine({ | ||
start_states: ['off'], | ||
transitions:[ { from:'off', to:'red', action:'on' }, { from:'red', to:'off',action:'off' } ] | ||
}); | ||
|
||
test('One action has "on"', () => expect( sha_machine.list_states_having_action('on').length ).toBe(1) ); | ||
test('"on" is had by "off"', () => expect( sha_machine.list_states_having_action('on')[0] ).toBe('off') ); | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('List exit actions', () => { | ||
|
||
const lea_machine = new jssm.Machine({ | ||
start_states: ['off'], | ||
transitions:[ { from:'off', to:'red', action:'on' }, { from:'red', to:'off',action:'off' } ] | ||
}); | ||
|
||
test('List exit actions, shows "on" from off as default', () => expect( lea_machine.list_exit_actions()[0] ).toBe('on') ); | ||
test('List exit actions, shows "on" from off', () => expect( lea_machine.list_exit_actions('off')[0] ).toBe('on') ); | ||
test('List exit actions, shows "off" from red', () => expect( lea_machine.list_exit_actions('red')[0] ).toBe('off') ); | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('Reports on action edges', () => { | ||
|
||
const roae_machine = new jssm.Machine({ | ||
start_states: ['off'], | ||
transitions:[ { name:'turn_on', action:'power_on', from:'off', to:'red'} ] | ||
}); | ||
|
||
test('Reports on action edges, that it has', () => expect( typeof roae_machine.current_action_edge_for('power_on') ).toBe('object') ); | ||
test('Reports on action edges, that it doesn\'t have', () => expect( () => roae_machine.current_action_edge_for('power_west') ).toThrow() ); | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('Two nodes should be able to have matching edges with differing action labels', () => { | ||
|
||
// const machine = sm`a 'first' -> a; a 'second' -> a;`; | ||
|
||
// test('that it has', () => expect( typeof machine.current_action_edge_for('power_on') ).toBe('object') ); | ||
// test('that it doesn\'t have', () => expect( () => machine.current_action_edge_for('power_west') ).toThrow() ); | ||
|
||
test.todo('todo - uncomment when #531 is resolved'); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
/* eslint-disable max-len */ | ||
|
||
const jssm = require('../../../build/jssm.es5.cjs.js'); | ||
|
||
|
||
|
||
|
||
|
||
describe('Array basics', () => { | ||
|
||
|
||
|
||
describe('array of one', () => { | ||
|
||
const aLeft = [ | ||
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"}, | ||
]; | ||
|
||
test('[a]->d;', () => expect( jssm.compile(jssm.parse('[a]->d;')).transitions ).toEqual(aLeft) ); | ||
|
||
}); | ||
|
||
|
||
|
||
describe('array of one', () => { | ||
|
||
const aLeft = [ | ||
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"}, | ||
]; | ||
|
||
test('[a]->d;', () => expect( jssm.compile(jssm.parse('[a]->d;')).transitions ).toEqual(aLeft) ); | ||
|
||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('Array sides', () => { | ||
|
||
|
||
|
||
describe('array on left', () => { | ||
|
||
const aLeft = [ | ||
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"b","to":"d","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"c","to":"d","kind":"legal"} | ||
]; | ||
|
||
test('[a b c]->d;', () => expect( jssm.compile(jssm.parse('[a b c]->d;')).transitions ).toEqual(aLeft) ); | ||
|
||
}); | ||
|
||
|
||
|
||
describe('array on right', () => { | ||
|
||
const aRight = [ | ||
{main_path: false,forced_only: false,"from":"a","to":"b","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"a","to":"c","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"a","to":"d","kind":"legal"} | ||
]; | ||
|
||
test('a->[b c d];', () => expect( jssm.compile(jssm.parse('a->[b c d];')).transitions ).toEqual(aRight) ); | ||
|
||
}); | ||
|
||
|
||
|
||
describe('array on both sides', () => { | ||
|
||
const aBoth = [ | ||
{main_path: false,forced_only: false,"from":"a","to":"x","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"a","to":"y","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"a","to":"z","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"b","to":"x","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"b","to":"y","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"b","to":"z","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"c","to":"x","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"c","to":"y","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"c","to":"z","kind":"legal"} | ||
]; | ||
|
||
test('[a b c]->[x y z];', () => expect( jssm.compile(jssm.parse('[a b c]->[x y z];')).transitions ).toEqual(aBoth) ); | ||
|
||
}); | ||
|
||
|
||
|
||
describe('array in middle', () => { | ||
|
||
const aBoth = [ | ||
{main_path: false,forced_only: false,"from":"a","to":"x","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"a","to":"y","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"a","to":"z","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"x","to":"b","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"y","to":"b","kind":"legal"}, | ||
{main_path: false,forced_only: false,"from":"z","to":"b","kind":"legal"} | ||
]; | ||
|
||
test('a->[x y z]->b;', () => expect( jssm.compile(jssm.parse('a->[x y z]->b;')).transitions ).toEqual(aBoth) ); | ||
|
||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
|
||
|
||
|
||
|
||
describe('array of zero must throw', () => { | ||
|
||
const aLeft = []; | ||
|
||
test('On left []->d;', () => expect( () => jssm.compile( jssm.parse('[]->d;') ).transitions ).toThrow() ); | ||
test('On right d->[];', () => expect( () => jssm.compile( jssm.parse('d->[];') ).transitions ).toThrow() ); | ||
test('On both []->[];', () => expect( () => jssm.compile( jssm.parse('[]->[];') ).transitions ).toThrow() ); | ||
test('In middle d->[]->e;', () => expect( () => jssm.compile( jssm.parse('d->[]->e;') ).transitions ).toThrow() ); | ||
test('In loop d->[]->d;', () => expect( () => jssm.compile( jssm.parse('d->[]->d;') ).transitions ).toThrow() ); | ||
|
||
}); |