jssm 5.35.4 → 5.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.codeclimate.yml +22 -22
  2. package/.editorconfig +12 -12
  3. package/.eslintrc +20 -20
  4. package/.nycrc +6 -6
  5. package/.travis.yml +8 -8
  6. package/LICENSE.md +21 -21
  7. package/README.md +997 -993
  8. package/dist/es6/jssm-dot.d.ts +6 -6
  9. package/dist/es6/jssm-dot.js +1 -1
  10. package/dist/es6/jssm.d.ts +100 -100
  11. package/dist/es6/jssm.js +792 -792
  12. package/dist/es6/jssm_types.d.ts +151 -151
  13. package/dist/es6/jssm_types.js +1 -1
  14. package/dist/es6/jssm_util.d.ts +8 -8
  15. package/dist/es6/jssm_util.js +34 -34
  16. package/dist/es6/version.d.ts +2 -2
  17. package/dist/es6/version.js +2 -2
  18. package/dist/jssm.es5.cjs.js +1 -1
  19. package/dist/jssm.es5.iife.js +1 -0
  20. package/jest-spec.config.js +27 -27
  21. package/jest-stoch.config.js +27 -27
  22. package/jssm-dot.d.ts +6 -6
  23. package/jssm.d.ts +100 -100
  24. package/jssm_types.d.ts +151 -151
  25. package/jssm_util.d.ts +8 -8
  26. package/package.json +125 -122
  27. package/rollup.config.iife.js +44 -44
  28. package/rollup.config.js +44 -44
  29. package/src/demo/index.html +38 -38
  30. package/src/demo/style.css +1 -1
  31. package/src/ts/jssm-dot.peg +928 -874
  32. package/src/ts/jssm.ts +1120 -1120
  33. package/src/ts/jssm_types.ts +346 -346
  34. package/src/ts/jssm_util.ts +100 -100
  35. package/src/ts/tests/actions.spec.ts +167 -167
  36. package/src/ts/tests/arrange.spec.ts +72 -72
  37. package/src/ts/tests/arrange.stoch.ts +4 -4
  38. package/src/ts/tests/array_box_if_string.spec.ts +30 -31
  39. package/src/ts/tests/array_transitions.spec.ts +129 -129
  40. package/src/ts/tests/arrow unicode.spec.ts +88 -88
  41. package/src/ts/tests/arrow.spec.ts +124 -124
  42. package/src/ts/tests/colors.spec.ts +58 -58
  43. package/src/ts/tests/comment.spec.ts +134 -134
  44. package/src/ts/tests/compile.spec.ts +79 -79
  45. package/src/ts/tests/constants.spec.ts +98 -98
  46. package/src/ts/tests/cycles.spec.ts +153 -153
  47. package/src/ts/tests/dot_preamble.spec.ts +16 -16
  48. package/src/ts/tests/embedded_sm.spec.ts +36 -36
  49. package/src/ts/tests/flow.spec.ts +22 -22
  50. package/src/ts/tests/forced transitions.spec.ts +26 -26
  51. package/src/ts/tests/general.spec.ts +933 -933
  52. package/src/ts/tests/graph node lists.spec.ts +21 -21
  53. package/src/ts/tests/histo.spec.ts +24 -24
  54. package/src/ts/tests/hooks.spec.ts +28 -0
  55. package/src/ts/tests/language.spec.ts +37 -37
  56. package/src/ts/tests/language_data/belarussian.json +13 -13
  57. package/src/ts/tests/language_data/bengali.json +15 -15
  58. package/src/ts/tests/language_data/emoji.json +21 -21
  59. package/src/ts/tests/language_data/english.json +16 -16
  60. package/src/ts/tests/language_data/french.json +16 -16
  61. package/src/ts/tests/language_data/german.json +16 -16
  62. package/src/ts/tests/language_data/hebrew.json +16 -16
  63. package/src/ts/tests/language_data/portuguese.json +12 -12
  64. package/src/ts/tests/language_data/russian.json +12 -12
  65. package/src/ts/tests/language_data/spanish.json +17 -17
  66. package/src/ts/tests/language_data/ukrainian.json +18 -18
  67. package/src/ts/tests/layout.spec.ts +29 -29
  68. package/src/ts/tests/machine_attributes.spec.ts +398 -398
  69. package/src/ts/tests/machine_name.spec.ts +14 -14
  70. package/src/ts/tests/named lists.spec.ts +24 -19
  71. package/src/ts/tests/nominated states.spec.ts +133 -133
  72. package/src/ts/tests/parse actions.spec.ts +32 -32
  73. package/src/ts/tests/parse.spec.ts +94 -94
  74. package/src/ts/tests/probability.spec.ts +146 -146
  75. package/src/ts/tests/r639.spec.ts +27 -27
  76. package/src/ts/tests/sample_select.spec.ts +173 -173
  77. package/src/ts/tests/seq.spec.ts +14 -16
  78. package/src/ts/tests/seq.stoch.ts +83 -0
  79. package/src/ts/tests/shapes.spec.ts +63 -63
  80. package/src/ts/tests/sm_tag.spec.ts +37 -37
  81. package/src/ts/tests/special characters.spec.ts +39 -39
  82. package/src/ts/tests/state_declaration.spec.ts +214 -200
  83. package/src/ts/tests/state_style.spec.ts +82 -39
  84. package/src/ts/tests/stop light.spec.ts +157 -157
  85. package/src/ts/tests/stripes.spec.ts +52 -52
  86. package/src/ts/tests/theme.spec.ts +45 -45
  87. package/src/ts/tests/weighted_histo_key.spec.ts +22 -22
  88. package/src/ts/tests/weighted_rand_select.spec.ts +27 -27
  89. package/src/ts/tests/weighted_sample_select.spec.ts +24 -26
  90. package/src/ts/version.ts +1 -1
  91. package/tree.txt +1794 -1794
  92. package/tsconfig.json +27 -27
  93. package/version.d.ts +2 -2
@@ -1,157 +1,157 @@
1
-
2
- /* eslint-disable max-len */
3
-
4
- import * as jssm from '../jssm';
5
-
6
-
7
-
8
-
9
-
10
- describe('Simple stop light', () => {
11
-
12
- const light = jssm.sm`Red 'Proceed' -> Green 'Proceed' -> Yellow 'Proceed' -> Red;`;
13
-
14
- const r_states = light.states();
15
-
16
- test('has the right state count', () =>
17
- expect(r_states.length).toBe(3));
18
-
19
- ['Red', 'Yellow', 'Green'].map(c =>
20
- test(`has state "${c}"`, () =>
21
- expect(r_states.includes(c)).toBe(true))
22
- );
23
-
24
- describe('- `proceed` walkthrough', () => {
25
-
26
- test('machine starts red', () => expect( light.state() ).toBe( "Red" ));
27
- test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ));
28
- test('light is now green', () => expect( light.state() ).toBe( "Green" ));
29
- test('proceed is true 2', () => expect( light.action('Proceed') ).toBe( true ));
30
- test('light is now yellow', () => expect( light.state() ).toBe( "Yellow" ));
31
- test('proceed is true 3', () => expect( light.action('Proceed') ).toBe( true ));
32
- test('light is red again', () => expect( light.state() ).toBe( "Red" ));
33
-
34
- });
35
-
36
- describe('- mixed - `proceed` and `transition`', () => {
37
-
38
- test('machine starts red', () => expect( light.state() ).toBe("Red") );
39
- test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
40
- test('machine is now green', () => expect( light.state() ).toBe("Green") );
41
-
42
- test('refuses transition red', () => expect( light.transition('Red') ).toBe( false ) );
43
- test('green still green', () => expect( light.state() ).toBe("Green") );
44
- test('refuses transition green', () => expect( light.transition('Green') ).toBe( false ) );
45
- test('green still green', () => expect( light.state() ).toBe("Green") );
46
- test('accepts transition yellow', () => expect( light.transition('Yellow') ).toBe( true ) );
47
- test('green now yellow', () => expect( light.state() ).toBe("Yellow") );
48
-
49
- test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
50
- test('machine is now red', () => expect( light.state() ).toBe("Red") );
51
-
52
- test('refuses transition yellow', () => expect( light.transition('Yellow') ).toBe( false ) );
53
- test('green still green', () => expect( light.state() ).toBe("Red") );
54
- test('refuses transition red', () => expect( light.transition('Red') ).toBe( false ) );
55
- test('green still green', () => expect( light.state() ).toBe("Red") );
56
- test('accepts transition green', () => expect( light.transition('Green') ).toBe( true ) );
57
- test('red now green', () => expect( light.state() ).toBe("Green") );
58
-
59
- test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
60
- test('machine is now yellow', () => expect( light.state() ).toBe("Yellow") );
61
- test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
62
- test('machine is now red', () => expect( light.state() ).toBe("Red") );
63
-
64
- });
65
-
66
- });
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
- describe('Complex stop light', () => {
75
-
76
- const light2 = new jssm.Machine({
77
-
78
- start_states: ['off'],
79
-
80
- transitions:[
81
-
82
- { name:'turn_on', kind: 'legal', forced_only: false, main_path: false, action:'power_on', from:'off', to:'red'},
83
-
84
- { kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'red', to:'off' },
85
- { kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'yellow', to:'off' },
86
- { kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'green', to:'off' },
87
-
88
- { name:'switch_warn', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'green', to:'yellow' },
89
- { name:'switch_halt', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'yellow', to:'red' },
90
- { name:'switch_go', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'red', to:'green' }
91
-
92
- ]
93
-
94
- });
95
-
96
- const r_states = light2.states();
97
-
98
- test('has the right state count', () =>
99
- expect(r_states.length).toBe(4));
100
-
101
- ['red', 'yellow', 'green', 'off'].map(c =>
102
- test(`has state "${c}"`, () =>
103
- expect(r_states.includes(c)).toBe(true))
104
- );
105
-
106
- const r_names = light2.list_named_transitions();
107
-
108
- test('has the right named transition count', () =>
109
- expect(r_names.size).toBe(4));
110
-
111
- ['turn_on', 'switch_warn', 'switch_halt', 'switch_go'].map(a =>
112
- test(`has named transition "${a}"`, () =>
113
- expect(r_names.has(a)).toBe(true))
114
- );
115
-
116
- test('has the right exit actions for red', () =>
117
- expect(['power_off', 'proceed']).toEqual(light2.list_exit_actions('red')) );
118
-
119
-
120
- describe('- `transition` walkthrough', () => {
121
-
122
- test('machine starts off', () => expect( light2.state() ).toBe("off") );
123
- test('off refuses green', () => expect( light2.transition('green') ).toBe(false) );
124
- test('off refuses yellow', () => expect( light2.transition('yellow') ).toBe(false) );
125
-
126
- test('off refuses proceed', () => expect( light2.action('proceed') ).toBe(false) );
127
-
128
- test('off accepts red', () => expect( light2.transition('red') ).toBe(true) );
129
- test('off is now red', () => expect( light2.state() ).toBe("red") );
130
- test('red refuses yellow', () => expect( light2.transition('yellow') ).toBe(false) );
131
- test('red still red', () => expect( light2.state() ).toBe("red") );
132
- test('red refuses red', () => expect( light2.transition('red') ).toBe(false) );
133
- test('red still red 2', () => expect( light2.state() ).toBe("red") );
134
-
135
- test('red accepts green', () => expect( light2.transition('green') ).toBe(true) );
136
- test('red now green', () => expect( light2.state() ).toBe("green") );
137
- test('green refuses red', () => expect( light2.transition('red') ).toBe(false) );
138
- test('green still green', () => expect( light2.state() ).toBe("green") );
139
- test('green refuses green', () => expect( light2.transition('green') ).toBe(false) );
140
- test('green still green 2', () => expect( light2.state() ).toBe("green") );
141
-
142
- test('green accepts yellow', () => expect( light2.transition('yellow') ).toBe(true) );
143
- test('green now yellow', () => expect( light2.state() ).toBe("yellow") );
144
- test('yellow refuses green', () => expect( light2.transition('green') ).toBe(false) );
145
- test('yellow still yellow', () => expect( light2.state() ).toBe("yellow") );
146
- test('yellow refuses yellow', () => expect( light2.transition('yellow') ).toBe(false) );
147
- test('yellow still yellow 2', () => expect( light2.state() ).toBe("yellow") );
148
-
149
- test('yellow accepts red', () => expect( light2.transition('red') ).toBe(true) );
150
- test('back to red', () => expect( light2.state() ).toBe("red") );
151
-
152
- test('proceed is true', () => expect( light2.action('proceed') ).toBe(true) );
153
- test('light is now green', () => expect( light2.state() ).toBe("green") );
154
-
155
- });
156
-
157
- });
1
+
2
+ /* eslint-disable max-len */
3
+
4
+ import * as jssm from '../jssm';
5
+
6
+
7
+
8
+
9
+
10
+ describe('Simple stop light', () => {
11
+
12
+ const light = jssm.sm`Red 'Proceed' -> Green 'Proceed' -> Yellow 'Proceed' -> Red;`;
13
+
14
+ const r_states = light.states();
15
+
16
+ test('has the right state count', () =>
17
+ expect(r_states.length).toBe(3));
18
+
19
+ ['Red', 'Yellow', 'Green'].map(c =>
20
+ test(`has state "${c}"`, () =>
21
+ expect(r_states.includes(c)).toBe(true))
22
+ );
23
+
24
+ describe('- `proceed` walkthrough', () => {
25
+
26
+ test('machine starts red', () => expect( light.state() ).toBe( "Red" ));
27
+ test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ));
28
+ test('light is now green', () => expect( light.state() ).toBe( "Green" ));
29
+ test('proceed is true 2', () => expect( light.action('Proceed') ).toBe( true ));
30
+ test('light is now yellow', () => expect( light.state() ).toBe( "Yellow" ));
31
+ test('proceed is true 3', () => expect( light.action('Proceed') ).toBe( true ));
32
+ test('light is red again', () => expect( light.state() ).toBe( "Red" ));
33
+
34
+ });
35
+
36
+ describe('- mixed - `proceed` and `transition`', () => {
37
+
38
+ test('machine starts red', () => expect( light.state() ).toBe("Red") );
39
+ test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
40
+ test('machine is now green', () => expect( light.state() ).toBe("Green") );
41
+
42
+ test('refuses transition red', () => expect( light.transition('Red') ).toBe( false ) );
43
+ test('green still green', () => expect( light.state() ).toBe("Green") );
44
+ test('refuses transition green', () => expect( light.transition('Green') ).toBe( false ) );
45
+ test('green still green', () => expect( light.state() ).toBe("Green") );
46
+ test('accepts transition yellow', () => expect( light.transition('Yellow') ).toBe( true ) );
47
+ test('green now yellow', () => expect( light.state() ).toBe("Yellow") );
48
+
49
+ test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
50
+ test('machine is now red', () => expect( light.state() ).toBe("Red") );
51
+
52
+ test('refuses transition yellow', () => expect( light.transition('Yellow') ).toBe( false ) );
53
+ test('green still green', () => expect( light.state() ).toBe("Red") );
54
+ test('refuses transition red', () => expect( light.transition('Red') ).toBe( false ) );
55
+ test('green still green', () => expect( light.state() ).toBe("Red") );
56
+ test('accepts transition green', () => expect( light.transition('Green') ).toBe( true ) );
57
+ test('red now green', () => expect( light.state() ).toBe("Green") );
58
+
59
+ test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
60
+ test('machine is now yellow', () => expect( light.state() ).toBe("Yellow") );
61
+ test('proceed is true', () => expect( light.action('Proceed') ).toBe( true ) );
62
+ test('machine is now red', () => expect( light.state() ).toBe("Red") );
63
+
64
+ });
65
+
66
+ });
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ describe('Complex stop light', () => {
75
+
76
+ const light2 = new jssm.Machine({
77
+
78
+ start_states: ['off'],
79
+
80
+ transitions:[
81
+
82
+ { name:'turn_on', kind: 'legal', forced_only: false, main_path: false, action:'power_on', from:'off', to:'red'},
83
+
84
+ { kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'red', to:'off' },
85
+ { kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'yellow', to:'off' },
86
+ { kind: 'legal', forced_only: false, main_path: false, action:'power_off', from:'green', to:'off' },
87
+
88
+ { name:'switch_warn', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'green', to:'yellow' },
89
+ { name:'switch_halt', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'yellow', to:'red' },
90
+ { name:'switch_go', kind: 'legal', forced_only: false, main_path: false, action:'proceed', from:'red', to:'green' }
91
+
92
+ ]
93
+
94
+ });
95
+
96
+ const r_states = light2.states();
97
+
98
+ test('has the right state count', () =>
99
+ expect(r_states.length).toBe(4));
100
+
101
+ ['red', 'yellow', 'green', 'off'].map(c =>
102
+ test(`has state "${c}"`, () =>
103
+ expect(r_states.includes(c)).toBe(true))
104
+ );
105
+
106
+ const r_names = light2.list_named_transitions();
107
+
108
+ test('has the right named transition count', () =>
109
+ expect(r_names.size).toBe(4));
110
+
111
+ ['turn_on', 'switch_warn', 'switch_halt', 'switch_go'].map(a =>
112
+ test(`has named transition "${a}"`, () =>
113
+ expect(r_names.has(a)).toBe(true))
114
+ );
115
+
116
+ test('has the right exit actions for red', () =>
117
+ expect(['power_off', 'proceed']).toEqual(light2.list_exit_actions('red')) );
118
+
119
+
120
+ describe('- `transition` walkthrough', () => {
121
+
122
+ test('machine starts off', () => expect( light2.state() ).toBe("off") );
123
+ test('off refuses green', () => expect( light2.transition('green') ).toBe(false) );
124
+ test('off refuses yellow', () => expect( light2.transition('yellow') ).toBe(false) );
125
+
126
+ test('off refuses proceed', () => expect( light2.action('proceed') ).toBe(false) );
127
+
128
+ test('off accepts red', () => expect( light2.transition('red') ).toBe(true) );
129
+ test('off is now red', () => expect( light2.state() ).toBe("red") );
130
+ test('red refuses yellow', () => expect( light2.transition('yellow') ).toBe(false) );
131
+ test('red still red', () => expect( light2.state() ).toBe("red") );
132
+ test('red refuses red', () => expect( light2.transition('red') ).toBe(false) );
133
+ test('red still red 2', () => expect( light2.state() ).toBe("red") );
134
+
135
+ test('red accepts green', () => expect( light2.transition('green') ).toBe(true) );
136
+ test('red now green', () => expect( light2.state() ).toBe("green") );
137
+ test('green refuses red', () => expect( light2.transition('red') ).toBe(false) );
138
+ test('green still green', () => expect( light2.state() ).toBe("green") );
139
+ test('green refuses green', () => expect( light2.transition('green') ).toBe(false) );
140
+ test('green still green 2', () => expect( light2.state() ).toBe("green") );
141
+
142
+ test('green accepts yellow', () => expect( light2.transition('yellow') ).toBe(true) );
143
+ test('green now yellow', () => expect( light2.state() ).toBe("yellow") );
144
+ test('yellow refuses green', () => expect( light2.transition('green') ).toBe(false) );
145
+ test('yellow still yellow', () => expect( light2.state() ).toBe("yellow") );
146
+ test('yellow refuses yellow', () => expect( light2.transition('yellow') ).toBe(false) );
147
+ test('yellow still yellow 2', () => expect( light2.state() ).toBe("yellow") );
148
+
149
+ test('yellow accepts red', () => expect( light2.transition('red') ).toBe(true) );
150
+ test('back to red', () => expect( light2.state() ).toBe("red") );
151
+
152
+ test('proceed is true', () => expect( light2.action('proceed') ).toBe(true) );
153
+ test('light is now green', () => expect( light2.state() ).toBe("green") );
154
+
155
+ });
156
+
157
+ });
@@ -1,52 +1,52 @@
1
-
2
- /* eslint-disable max-len */
3
-
4
- import * as jssm from '../jssm';
5
-
6
-
7
-
8
-
9
-
10
- describe('stripe strategies', () => {
11
-
12
-
13
-
14
- const is_v = (str, v) =>
15
- test(str, () =>
16
- expect( jssm.parse(str) ).toEqual(v)
17
- );
18
-
19
-
20
-
21
- describe('basic stripe', () => {
22
- is_v(
23
- '[a b c] -> +|1;',
24
- [{from: ['a','b','c'], key: 'transition', se: {kind: '->', to: {key: 'stripe', value: 1}}}]
25
- );
26
- });
27
-
28
- describe('negative stripe', () => {
29
- is_v(
30
- '[a b c] -> -|1;',
31
- [{from: ['a','b','c'], key: 'transition', se: {kind: '->', to: {key: 'stripe', value: -1}}}]
32
- );
33
- });
34
-
35
- describe('wide stripe', () => {
36
- is_v(
37
- '[a b c] -> +|2;',
38
- [{from: ['a','b','c'], key: 'transition', se: {kind: '->', to: {key: 'stripe', value: 2}}}]
39
- );
40
- });
41
-
42
-
43
-
44
- test('illegal fractional stripe throws', () => {
45
-
46
- expect( () =>
47
- jssm.parse('[a b c] -> +|2.5;')
48
- ).toThrow();
49
-
50
- });
51
-
52
- });
1
+
2
+ /* eslint-disable max-len */
3
+
4
+ import * as jssm from '../jssm';
5
+
6
+
7
+
8
+
9
+
10
+ describe('stripe strategies', () => {
11
+
12
+
13
+
14
+ const is_v = (str, v) =>
15
+ test(str, () =>
16
+ expect( jssm.parse(str) ).toEqual(v)
17
+ );
18
+
19
+
20
+
21
+ describe('basic stripe', () => {
22
+ is_v(
23
+ '[a b c] -> +|1;',
24
+ [{from: ['a','b','c'], key: 'transition', se: {kind: '->', to: {key: 'stripe', value: 1}}}]
25
+ );
26
+ });
27
+
28
+ describe('negative stripe', () => {
29
+ is_v(
30
+ '[a b c] -> -|1;',
31
+ [{from: ['a','b','c'], key: 'transition', se: {kind: '->', to: {key: 'stripe', value: -1}}}]
32
+ );
33
+ });
34
+
35
+ describe('wide stripe', () => {
36
+ is_v(
37
+ '[a b c] -> +|2;',
38
+ [{from: ['a','b','c'], key: 'transition', se: {kind: '->', to: {key: 'stripe', value: 2}}}]
39
+ );
40
+ });
41
+
42
+
43
+
44
+ test('illegal fractional stripe throws', () => {
45
+
46
+ expect( () =>
47
+ jssm.parse('[a b c] -> +|2.5;')
48
+ ).toThrow();
49
+
50
+ });
51
+
52
+ });
@@ -1,45 +1,45 @@
1
-
2
- import { Themes } from './constants.spec';
3
-
4
- import { sm } from '../jssm';
5
-
6
-
7
-
8
-
9
-
10
- const baseline = sm`theme: ocean; z -> q;`,
11
- baseline_theme = baseline.theme();
12
-
13
- test('Themes sound like the ocean', () =>
14
- expect(baseline_theme).toBe('ocean') );
15
-
16
-
17
-
18
- const no_baseline = sm`z -> q;`,
19
- no_baseline_theme = no_baseline.theme();
20
-
21
- test('No theme sounds like none', () =>
22
- expect(no_baseline_theme).toBe('default') );
23
-
24
-
25
-
26
-
27
-
28
- describe('Named themes', () => {
29
-
30
- Themes.map(thisTheme =>
31
- test(`Theme "${thisTheme}" parses as a theme`, () =>
32
- expect( () => { const _foo = sm`theme: ${thisTheme}; a-> b;`; }).not.toThrow() ) );
33
-
34
- Themes.map(thisTheme =>
35
- test(`Theme "${thisTheme}" shows correct theme`, () =>
36
- expect( sm`theme: ${thisTheme}; a-> b;`.theme() ).toBe(thisTheme) ) );
37
-
38
- Themes.map(thisTheme =>
39
- test(`Missing theme shows theme "default"`, () =>
40
- expect( sm`a-> b;`.theme() ).toBe("default") ) );
41
-
42
- test('Fake theme throws', () =>
43
- expect( () => { const _foo = sm`theme: zeghezgqqqqthirteen; a-> b;`; }).toThrow() );
44
-
45
- });
1
+
2
+ import { Themes } from './constants.spec';
3
+
4
+ import { sm } from '../jssm';
5
+
6
+
7
+
8
+
9
+
10
+ const baseline = sm`theme: ocean; z -> q;`,
11
+ baseline_theme = baseline.theme();
12
+
13
+ test('Themes sound like the ocean', () =>
14
+ expect(baseline_theme).toBe('ocean') );
15
+
16
+
17
+
18
+ const no_baseline = sm`z -> q;`,
19
+ no_baseline_theme = no_baseline.theme();
20
+
21
+ test('No theme sounds like none', () =>
22
+ expect(no_baseline_theme).toBe('default') );
23
+
24
+
25
+
26
+
27
+
28
+ describe('Named themes', () => {
29
+
30
+ Themes.map(thisTheme =>
31
+ test(`Theme "${thisTheme}" parses as a theme`, () =>
32
+ expect( () => { const _foo = sm`theme: ${thisTheme}; a-> b;`; }).not.toThrow() ) );
33
+
34
+ Themes.map(thisTheme =>
35
+ test(`Theme "${thisTheme}" shows correct theme`, () =>
36
+ expect( sm`theme: ${thisTheme}; a-> b;`.theme() ).toBe(thisTheme) ) );
37
+
38
+ Themes.map(thisTheme =>
39
+ test(`Missing theme shows theme "default"`, () =>
40
+ expect( sm`a-> b;`.theme() ).toBe("default") ) );
41
+
42
+ test('Fake theme throws', () =>
43
+ expect( () => { const _foo = sm`theme: zeghezgqqqqthirteen; a-> b;`; }).toThrow() );
44
+
45
+ });
@@ -1,22 +1,22 @@
1
-
2
- import * as jssm from '../jssm';
3
-
4
-
5
-
6
-
7
-
8
- describe('weighted_histo_key/2', () => {
9
-
10
- const fruit = [ { label: 'apple', probability: 0.1 },
11
- { label: 'orange', probability: 0.4 },
12
- { label: 'banana', probability: 0.5 } ];
13
-
14
- const out = jssm.weighted_histo_key(10000, fruit, 'probability', 'label');
15
-
16
- test('produces a well formed probability map', () =>
17
- expect([... out.keys()].length).toBe(3)
18
- );
19
-
20
- });
21
-
22
- // stochable
1
+
2
+ import * as jssm from '../jssm';
3
+
4
+
5
+
6
+
7
+
8
+ describe('weighted_histo_key/2', () => {
9
+
10
+ const fruit = [ { label: 'apple', probability: 0.1 },
11
+ { label: 'orange', probability: 0.4 },
12
+ { label: 'banana', probability: 0.5 } ];
13
+
14
+ const out = jssm.weighted_histo_key(10000, fruit, 'probability', 'label');
15
+
16
+ test('produces a well formed probability map', () =>
17
+ expect([... out.keys()].length).toBe(3)
18
+ );
19
+
20
+ });
21
+
22
+ // stochable
@@ -1,27 +1,27 @@
1
-
2
- import * as jssm from '../jssm';
3
-
4
-
5
-
6
-
7
-
8
- describe('weighted_rand_select/2', () => {
9
-
10
- const fruit = [ { label: 'apple', probability: 0.1 },
11
- { label: 'orange', probability: 0.4 },
12
- { label: 'banana', probability: 0.5 } ];
13
-
14
- const acc = { apple: 0, orange: 0, banana: 0 };
15
-
16
- for (let i=0; i<10000; ++i) {
17
- acc[jssm.weighted_rand_select(fruit).label] = acc[jssm.weighted_rand_select(fruit).label] + 1;
18
- }
19
-
20
- test('banana baseline', () => expect( acc.banana > 3000 ).toBe(true) );
21
-
22
- test('requires an array', () => expect( () => jssm.weighted_rand_select( 'not_an_array' )).toThrow() );
23
- test('requires members to be objects', () => expect( () => jssm.weighted_rand_select( ['not_an_obj'] )).toThrow() );
24
-
25
- });
26
-
27
- // stochable
1
+
2
+ import * as jssm from '../jssm';
3
+
4
+
5
+
6
+
7
+
8
+ describe('weighted_rand_select/2', () => {
9
+
10
+ const fruit = [ { label: 'apple', probability: 0.1 },
11
+ { label: 'orange', probability: 0.4 },
12
+ { label: 'banana', probability: 0.5 } ];
13
+
14
+ const acc = { apple: 0, orange: 0, banana: 0 };
15
+
16
+ for (let i=0; i<10000; ++i) {
17
+ acc[jssm.weighted_rand_select(fruit).label] = acc[jssm.weighted_rand_select(fruit).label] + 1;
18
+ }
19
+
20
+ test('banana baseline', () => expect( acc.banana > 3000 ).toBe(true) );
21
+
22
+ test('requires an array', () => expect( () => jssm.weighted_rand_select( 'not_an_array' )).toThrow() );
23
+ test('requires members to be objects', () => expect( () => jssm.weighted_rand_select( ['not_an_obj'] )).toThrow() );
24
+
25
+ });
26
+
27
+ // stochable