jssm 5.45.2 → 5.48.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.
- package/dist/es6/jssm.d.ts +3 -1
- package/dist/es6/jssm.js +10 -0
- package/dist/es6/jssm_types.d.ts +6 -5
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/jssm.d.ts +3 -1
- package/jssm_types.d.ts +6 -5
- package/package.json +1 -1
- package/.codeclimate.yml +0 -22
- package/.editorconfig +0 -12
- package/.eslintrc +0 -20
- package/.nycrc +0 -6
- package/.travis.yml +0 -9
- package/dist/jssm.es5.iife.js +0 -1
- package/jest-spec.config.js +0 -27
- package/jest-stoch.config.js +0 -27
- package/rollup.config.iife.js +0 -44
- package/rollup.config.js +0 -44
- package/src/demo/index.html +0 -38
- package/src/demo/style.css +0 -2
- package/src/ts/jssm-dot.peg +0 -928
- package/src/ts/jssm.ts +0 -1243
- package/src/ts/jssm_types.ts +0 -385
- package/src/ts/jssm_util.ts +0 -117
- package/src/ts/tests/actions.spec.ts +0 -167
- package/src/ts/tests/arrange.spec.ts +0 -72
- package/src/ts/tests/arrange.stoch.ts +0 -4
- package/src/ts/tests/array_box_if_string.spec.ts +0 -30
- package/src/ts/tests/array_transitions.spec.ts +0 -129
- package/src/ts/tests/arrow unicode.spec.ts +0 -88
- package/src/ts/tests/arrow.spec.ts +0 -124
- package/src/ts/tests/colors.spec.ts +0 -58
- package/src/ts/tests/comment.spec.ts +0 -134
- package/src/ts/tests/compile.spec.ts +0 -79
- package/src/ts/tests/constants.spec.ts +0 -98
- package/src/ts/tests/cycles.spec.ts +0 -153
- package/src/ts/tests/dot_preamble.spec.ts +0 -16
- package/src/ts/tests/embedded_sm.spec.ts +0 -36
- package/src/ts/tests/flow.spec.ts +0 -22
- package/src/ts/tests/forced transitions.spec.ts +0 -26
- package/src/ts/tests/general.spec.ts +0 -933
- package/src/ts/tests/graph node lists.spec.ts +0 -21
- package/src/ts/tests/histo.spec.ts +0 -24
- package/src/ts/tests/hooks.spec.ts +0 -209
- package/src/ts/tests/language.spec.ts +0 -37
- package/src/ts/tests/language_data/belarussian.json +0 -14
- package/src/ts/tests/language_data/bengali.json +0 -16
- package/src/ts/tests/language_data/emoji.json +0 -22
- package/src/ts/tests/language_data/english.json +0 -17
- package/src/ts/tests/language_data/french.json +0 -17
- package/src/ts/tests/language_data/german.json +0 -17
- package/src/ts/tests/language_data/hebrew.json +0 -16
- package/src/ts/tests/language_data/portuguese.json +0 -13
- package/src/ts/tests/language_data/russian.json +0 -13
- package/src/ts/tests/language_data/spanish.json +0 -17
- package/src/ts/tests/language_data/ukrainian.json +0 -19
- package/src/ts/tests/layout.spec.ts +0 -29
- package/src/ts/tests/machine_attributes.spec.ts +0 -398
- package/src/ts/tests/machine_name.spec.ts +0 -14
- package/src/ts/tests/named lists.spec.ts +0 -24
- package/src/ts/tests/nominated states.spec.ts +0 -133
- package/src/ts/tests/parse actions.spec.ts +0 -32
- package/src/ts/tests/parse.spec.ts +0 -94
- package/src/ts/tests/probability.spec.ts +0 -146
- package/src/ts/tests/r639.spec.ts +0 -27
- package/src/ts/tests/sample_select.spec.ts +0 -173
- package/src/ts/tests/seq.spec.ts +0 -14
- package/src/ts/tests/seq.stoch.ts +0 -83
- package/src/ts/tests/shapes.spec.ts +0 -63
- package/src/ts/tests/sm_tag.spec.ts +0 -37
- package/src/ts/tests/special characters.spec.ts +0 -39
- package/src/ts/tests/state_declaration.spec.ts +0 -214
- package/src/ts/tests/state_style.spec.ts +0 -82
- package/src/ts/tests/stop light.spec.ts +0 -157
- package/src/ts/tests/stripes.spec.ts +0 -52
- package/src/ts/tests/theme.spec.ts +0 -45
- package/src/ts/tests/weighted_histo_key.spec.ts +0 -22
- package/src/ts/tests/weighted_rand_select.spec.ts +0 -27
- package/src/ts/tests/weighted_sample_select.spec.ts +0 -24
- package/src/ts/version.ts +0 -3
- package/tree.txt +0 -1794
- package/tsconfig.json +0 -27
package/src/ts/jssm_types.ts
DELETED
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
type StateType = string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type JssmSuccess = { success: true };
|
|
9
|
-
type JssmFailure = { success: false, error: any };
|
|
10
|
-
type JssmIncomplete = { success: 'incomplete' };
|
|
11
|
-
type JssmResult = JssmSuccess | JssmFailure | JssmIncomplete;
|
|
12
|
-
|
|
13
|
-
type JssmColor = string; // TODO FIXME constrain to #RRGGBBAA later // whargarbl
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type JssmPermitted = 'required' | 'disallowed';
|
|
18
|
-
type JssmPermittedOpt = 'required' | 'disallowed' | 'optional';
|
|
19
|
-
|
|
20
|
-
type JssmArrow = '->' | '<-' | '<->' | '<=->' | '<~->'
|
|
21
|
-
| '=>' | '<=' | '<=>' | '<-=>' | '<~=>'
|
|
22
|
-
| '~>' | '<~' | '<~>' | '<-~>' | '<=~>';
|
|
23
|
-
// | '⇒' | '⇐' | '⇔' | '⇐→' | '↚→'
|
|
24
|
-
// | '→' | '←' | '↔' | '←⇒' | '↚⇒'
|
|
25
|
-
// | '↛' | '↚' | '↮' | '←↛' | '⇐↛';
|
|
26
|
-
|
|
27
|
-
// TODO finish the arrow types - unicode *and* mixed
|
|
28
|
-
|
|
29
|
-
type JssmShape = "box" | "polygon" | "ellipse" | "oval" | "circle" | "point" | "egg" | "triangle"
|
|
30
|
-
| "plaintext" | "plain" | "diamond" | "trapezium" | "parallelogram" | "house" | "pentagon"
|
|
31
|
-
| "hexagon" | "septagon" | "octagon" | "doublecircle" | "doubleoctagon" | "tripleoctagon"
|
|
32
|
-
| "invtriangle" | "invtrapezium" | "invhouse" | "Mdiamond" | "Msquare" | "Mcircle" | "rect"
|
|
33
|
-
| "rectangle" | "square" | "star" | "none" | "underline" | "cylinder" | "note" | "tab"
|
|
34
|
-
| "folder" | "box3d" | "component" | "promoter" | "cds" | "terminator" | "utr" | "primersite"
|
|
35
|
-
| "restrictionsite" | "fivepoverhang" | "threepoverhang" | "noverhang" | "assembly"
|
|
36
|
-
| "signature" | "insulator" | "ribosite" | "rnastab" | "proteasesite" | "proteinstab"
|
|
37
|
-
| "rpromoter" | "rarrow" | "larrow" | "lpromoter" | "record";
|
|
38
|
-
|
|
39
|
-
type JssmArrowDirection = 'left' | 'right' | 'both';
|
|
40
|
-
type JssmArrowKind = 'none' | 'legal' | 'main' | 'forced';
|
|
41
|
-
|
|
42
|
-
type JssmLayout = 'dot' | 'circo' | 'twopi' | 'fdp'; // todo add the rest
|
|
43
|
-
|
|
44
|
-
type JssmCorner = 'regular' | 'rounded' | 'lined';
|
|
45
|
-
type JssmLineStyle = 'solid' | 'dashed' | 'dotted';
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
type FslDirection = 'up' | 'right' | 'down' | 'left';
|
|
52
|
-
type FslTheme = 'default' | 'ocean' | 'modern' | 'none';
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
type State = string;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
type JssmTransitionPermitter<DataType> =
|
|
65
|
-
(OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
66
|
-
|
|
67
|
-
type JssmTransitionPermitterMaybeArray<DataType> =
|
|
68
|
-
JssmTransitionPermitter<DataType>
|
|
69
|
-
| Array< JssmTransitionPermitter<DataType> >;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
type JssmTransition<DataType> = {
|
|
76
|
-
|
|
77
|
-
from : StateType,
|
|
78
|
-
to : StateType,
|
|
79
|
-
name? : string,
|
|
80
|
-
action? : StateType,
|
|
81
|
-
check? : JssmTransitionPermitterMaybeArray<DataType>, // validate this edge's transition; usually about data
|
|
82
|
-
probability? : number, // for stoch modelling, would like to constrain to [0..1], dunno how // TODO FIXME
|
|
83
|
-
kind : JssmArrowKind,
|
|
84
|
-
forced_only : boolean,
|
|
85
|
-
main_path : boolean
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
type JssmTransitions<DataType> =
|
|
90
|
-
Array< JssmTransition<DataType> >;
|
|
91
|
-
|
|
92
|
-
type JssmTransitionList = {
|
|
93
|
-
entrances : Array<StateType>,
|
|
94
|
-
exits : Array<StateType>
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
type JssmTransitionCycle = {
|
|
98
|
-
key : 'cycle',
|
|
99
|
-
value : StateType
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
type JssmTransitionRule =
|
|
103
|
-
StateType
|
|
104
|
-
| JssmTransitionCycle;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
type JssmGenericState = {
|
|
111
|
-
|
|
112
|
-
from : Array< StateType > ,
|
|
113
|
-
name : StateType ,
|
|
114
|
-
to : Array< StateType > ,
|
|
115
|
-
complete : boolean
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
type JssmMachineInternalState<DataType> = {
|
|
124
|
-
|
|
125
|
-
internal_state_impl_version : 1,
|
|
126
|
-
|
|
127
|
-
state : StateType,
|
|
128
|
-
states : Map< StateType, JssmGenericState >,
|
|
129
|
-
named_transitions : Map< StateType, number >,
|
|
130
|
-
edge_map : Map< StateType, Map<StateType, number> >,
|
|
131
|
-
actions : Map< StateType, Map<StateType, number> >,
|
|
132
|
-
reverse_actions : Map< StateType, Map<StateType, number> >,
|
|
133
|
-
edges : Array< JssmTransition<DataType> >
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
type JssmStatePermitter<DataType> =
|
|
142
|
-
(OldState: StateType, NewState: StateType, OldData: DataType, NewData: DataType) => boolean;
|
|
143
|
-
|
|
144
|
-
type JssmStatePermitterMaybeArray<DataType> =
|
|
145
|
-
JssmStatePermitter<DataType> | Array< JssmStatePermitter<DataType> >;
|
|
146
|
-
|
|
147
|
-
type JssmGenericMachine<DataType> = {
|
|
148
|
-
|
|
149
|
-
name? : string,
|
|
150
|
-
state : StateType,
|
|
151
|
-
data? : DataType,
|
|
152
|
-
nodes? : Array<StateType>,
|
|
153
|
-
transitions : JssmTransitions<DataType>,
|
|
154
|
-
check? : JssmStatePermitterMaybeArray<DataType>,
|
|
155
|
-
|
|
156
|
-
min_transitions? : number,
|
|
157
|
-
max_transitions? : number,
|
|
158
|
-
|
|
159
|
-
allow_empty? : boolean,
|
|
160
|
-
allow_islands? : boolean,
|
|
161
|
-
allow_force? : boolean,
|
|
162
|
-
|
|
163
|
-
keep_history? : boolean | number
|
|
164
|
-
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
type JssmStateDeclarationRule = {
|
|
172
|
-
key : string,
|
|
173
|
-
value : any // TODO FIXME COMEBACK enumerate types against concrete keys
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
type JssmStateDeclaration = {
|
|
177
|
-
|
|
178
|
-
declarations : Array<JssmStateDeclarationRule>,
|
|
179
|
-
|
|
180
|
-
shape? : JssmShape,
|
|
181
|
-
color? : JssmColor,
|
|
182
|
-
corners? : JssmCorner,
|
|
183
|
-
linestyle? : JssmLineStyle,
|
|
184
|
-
|
|
185
|
-
textColor? : JssmColor,
|
|
186
|
-
backgroundColor? : JssmColor,
|
|
187
|
-
borderColor? : JssmColor,
|
|
188
|
-
|
|
189
|
-
state : StateType
|
|
190
|
-
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
type JssmGenericConfig<DataType> = {
|
|
198
|
-
|
|
199
|
-
graph_layout? : JssmLayout,
|
|
200
|
-
|
|
201
|
-
complete? : Array<StateType>,
|
|
202
|
-
transitions : JssmTransitions<DataType>,
|
|
203
|
-
|
|
204
|
-
theme? : FslTheme,
|
|
205
|
-
flow? : FslDirection,
|
|
206
|
-
|
|
207
|
-
name? : string,
|
|
208
|
-
data? : DataType,
|
|
209
|
-
nodes? : Array<StateType>, // uncommon
|
|
210
|
-
check? : JssmStatePermitterMaybeArray<DataType>,
|
|
211
|
-
|
|
212
|
-
//locked? : bool = true,
|
|
213
|
-
min_exits? : number,
|
|
214
|
-
max_exits? : number,
|
|
215
|
-
allow_islands? : false,
|
|
216
|
-
allow_force? : false,
|
|
217
|
-
actions? : JssmPermittedOpt,
|
|
218
|
-
|
|
219
|
-
simplify_bidi? : boolean,
|
|
220
|
-
|
|
221
|
-
dot_preamble? : string,
|
|
222
|
-
|
|
223
|
-
start_states : Array<StateType>,
|
|
224
|
-
end_states? : Array<StateType>,
|
|
225
|
-
|
|
226
|
-
state_declaration? : Array<Object>,
|
|
227
|
-
|
|
228
|
-
arrange_declaration? : Array<Array<StateType>>,
|
|
229
|
-
arrange_start_declaration? : Array<Array<StateType>>,
|
|
230
|
-
arrange_end_declaration? : Array<Array<StateType>>,
|
|
231
|
-
|
|
232
|
-
machine_author? : string | Array<string>,
|
|
233
|
-
machine_comment? : string,
|
|
234
|
-
machine_contributor? : string | Array<string>,
|
|
235
|
-
machine_definition? : string,
|
|
236
|
-
machine_language? : string, // TODO FIXME COMEBACK
|
|
237
|
-
machine_license? : string, // TODO FIXME COMEBACK
|
|
238
|
-
machine_name? : string,
|
|
239
|
-
machine_version? : string, // TODO FIXME COMEBACK
|
|
240
|
-
|
|
241
|
-
fsl_version? : string, // TODO FIXME COMEBACK
|
|
242
|
-
|
|
243
|
-
auto_api? : boolean | string // TODO FIXME COMEBACK // boolean false means don't; boolean true means do; string means do-with-this-prefix
|
|
244
|
-
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
type JssmCompileRule = {
|
|
252
|
-
|
|
253
|
-
agg_as : string,
|
|
254
|
-
val : any // TODO COMEBACK FIXME
|
|
255
|
-
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
type JssmCompileSe = {
|
|
263
|
-
|
|
264
|
-
to : StateType,
|
|
265
|
-
se : JssmCompileSe,
|
|
266
|
-
kind : JssmArrow,
|
|
267
|
-
l_action? : StateType,
|
|
268
|
-
r_action? : StateType,
|
|
269
|
-
l_probability : number,
|
|
270
|
-
r_probability : number
|
|
271
|
-
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
type JssmCompileSeStart<DataType> = {
|
|
279
|
-
|
|
280
|
-
from : DataType,
|
|
281
|
-
se : JssmCompileSe,
|
|
282
|
-
key : string,
|
|
283
|
-
value? : string | number,
|
|
284
|
-
name? : string
|
|
285
|
-
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
type JssmParseTree =
|
|
293
|
-
|
|
294
|
-
Array< JssmCompileSeStart<StateType> >;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
type JssmParseFunctionType =
|
|
301
|
-
|
|
302
|
-
(string) => JssmParseTree;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
type BasicHookDescription = {
|
|
309
|
-
kind : 'hook'
|
|
310
|
-
from : string,
|
|
311
|
-
to : string,
|
|
312
|
-
handler : Function
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
type HookDescriptionWithAction = {
|
|
316
|
-
kind : 'named',
|
|
317
|
-
from : string,
|
|
318
|
-
to : string,
|
|
319
|
-
action : string,
|
|
320
|
-
handler : Function
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
type EntryHook = {
|
|
324
|
-
kind : 'entry',
|
|
325
|
-
to : string,
|
|
326
|
-
handler : Function
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
type ExitHook = {
|
|
330
|
-
kind : 'exit',
|
|
331
|
-
from : string,
|
|
332
|
-
handler : Function
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
type HookDescription
|
|
336
|
-
= BasicHookDescription
|
|
337
|
-
| HookDescriptionWithAction
|
|
338
|
-
| EntryHook
|
|
339
|
-
| ExitHook;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
export {
|
|
346
|
-
|
|
347
|
-
JssmColor,
|
|
348
|
-
|
|
349
|
-
JssmTransition,
|
|
350
|
-
JssmTransitions,
|
|
351
|
-
JssmTransitionList,
|
|
352
|
-
JssmTransitionRule,
|
|
353
|
-
|
|
354
|
-
JssmArrow,
|
|
355
|
-
JssmArrowKind,
|
|
356
|
-
JssmArrowDirection,
|
|
357
|
-
|
|
358
|
-
JssmGenericConfig,
|
|
359
|
-
JssmGenericState,
|
|
360
|
-
JssmGenericMachine,
|
|
361
|
-
|
|
362
|
-
JssmParseTree,
|
|
363
|
-
JssmCompileSe,
|
|
364
|
-
JssmCompileSeStart,
|
|
365
|
-
JssmCompileRule,
|
|
366
|
-
|
|
367
|
-
JssmPermitted,
|
|
368
|
-
JssmPermittedOpt,
|
|
369
|
-
JssmResult,
|
|
370
|
-
|
|
371
|
-
JssmStateDeclaration,
|
|
372
|
-
JssmStateDeclarationRule,
|
|
373
|
-
|
|
374
|
-
JssmLayout,
|
|
375
|
-
|
|
376
|
-
JssmParseFunctionType,
|
|
377
|
-
|
|
378
|
-
JssmMachineInternalState,
|
|
379
|
-
|
|
380
|
-
FslDirection,
|
|
381
|
-
FslTheme,
|
|
382
|
-
|
|
383
|
-
HookDescription
|
|
384
|
-
|
|
385
|
-
};
|
package/src/ts/jssm_util.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
function arr_uniq_p<T>(el: T, i: number, source: T[]): boolean {
|
|
3
|
-
return source.indexOf(el) === i;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const array_box_if_string = n =>
|
|
11
|
-
typeof n === 'string'? [n] : n;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// this is explicitly about other peoples' data, so it has to be weakly typed
|
|
18
|
-
/* eslint-disable flowtype/no-weak-types */
|
|
19
|
-
const weighted_rand_select: Function = (options: Array<any>, probability_property: string = 'probability'): any => {
|
|
20
|
-
|
|
21
|
-
if (!Array.isArray(options)) {
|
|
22
|
-
throw new TypeError('options must be a non-empty array of objects');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!(typeof options[0] === 'object')) {
|
|
26
|
-
throw new TypeError('options must be a non-empty array of objects');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const frand : Function = (cap): number => Math.random() * cap,
|
|
30
|
-
or_one : Function = (item): any => item === undefined? 1 : item,
|
|
31
|
-
prob_sum : number = options.reduce( (acc, val:any): number => acc + or_one(val[probability_property]), 0 ),
|
|
32
|
-
rnd : number = frand(prob_sum);
|
|
33
|
-
|
|
34
|
-
let cursor : number = 0,
|
|
35
|
-
cursor_sum : number = 0;
|
|
36
|
-
|
|
37
|
-
while ((cursor_sum += or_one(options[cursor++][probability_property])) <= rnd) { } // eslint-disable-line no-empty,fp/no-loops
|
|
38
|
-
return options[cursor-1];
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
/* eslint-enable flowtype/no-weak-types */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const seq: Function = (n: number): Array<number> =>
|
|
48
|
-
|
|
49
|
-
(new Array(n)).fill(true)
|
|
50
|
-
.map( (_, i): number => i );
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const histograph: Function = (ar : Array<any>): Map<any, number> => // eslint-disable-line flowtype/no-weak-types
|
|
57
|
-
|
|
58
|
-
ar.sort()
|
|
59
|
-
.reduce(
|
|
60
|
-
(m,v): Map<any, any> => // TODO FIXME eslint-disable-line flowtype/no-weak-types,no-sequences
|
|
61
|
-
( m.set(v, (m.has(v)? m.get(v)+1 : 1)) , m),
|
|
62
|
-
new Map()
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const weighted_sample_select: Function = (n: number, options: Array<any>, probability_property: string): Array<any> => // TODO FIXME no any // eslint-disable-line flowtype/no-weak-types
|
|
70
|
-
|
|
71
|
-
seq(n)
|
|
72
|
-
.map( (_i): any => // TODO FIXME eslint-disable-line flowtype/no-weak-types
|
|
73
|
-
weighted_rand_select(options, probability_property)
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const weighted_histo_key: Function = (n: number, opts: Array<any>, prob_prop: string, extract: string): Array<any> => // TODO FIXME no any // eslint-disable-line flowtype/no-weak-types
|
|
81
|
-
|
|
82
|
-
histograph(
|
|
83
|
-
weighted_sample_select(n, opts, prob_prop)
|
|
84
|
-
.map(
|
|
85
|
-
(s): any => s[extract] // TODO FIXME eslint-disable-line flowtype/no-weak-types
|
|
86
|
-
)
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const hook_name = (from: string, to: string): string =>
|
|
94
|
-
|
|
95
|
-
JSON.stringify([from, to]);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const named_hook_name = (from: string, to: string, action: string): string =>
|
|
102
|
-
|
|
103
|
-
JSON.stringify([from, to, action]);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export {
|
|
110
|
-
seq,
|
|
111
|
-
arr_uniq_p,
|
|
112
|
-
histograph, weighted_histo_key,
|
|
113
|
-
weighted_rand_select, weighted_sample_select,
|
|
114
|
-
array_box_if_string,
|
|
115
|
-
hook_name, named_hook_name
|
|
116
|
-
};
|
|
117
|
-
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable max-len */
|
|
3
|
-
|
|
4
|
-
import * as jssm from '../jssm';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
describe('Reports on actions', () => {
|
|
11
|
-
|
|
12
|
-
const roa_machine = new jssm.Machine({
|
|
13
|
-
start_states : ['off'],
|
|
14
|
-
transitions : [
|
|
15
|
-
{ name: 'turn_on', action: 'power_on', from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false }
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const roa_la = roa_machine.list_actions(); // todo comeback
|
|
20
|
-
|
|
21
|
-
test('Actions that it has', () =>
|
|
22
|
-
expect( typeof roa_machine.current_action_for('power_on') )
|
|
23
|
-
.toBe('number') );
|
|
24
|
-
|
|
25
|
-
test('Actions that it doesn\'t have', () =>
|
|
26
|
-
expect( typeof roa_machine.current_action_for('power_left') )
|
|
27
|
-
.toBe('undefined') );
|
|
28
|
-
|
|
29
|
-
test('Correct list type', () =>
|
|
30
|
-
expect( Array.isArray(roa_la) )
|
|
31
|
-
.toBe(true) );
|
|
32
|
-
|
|
33
|
-
test('Correct list size', () =>
|
|
34
|
-
expect( roa_la.length )
|
|
35
|
-
.toBe(1) );
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
describe('Actions', () => {
|
|
44
|
-
|
|
45
|
-
const act_machine = new jssm.Machine({
|
|
46
|
-
start_states : ['off'],
|
|
47
|
-
transitions : [
|
|
48
|
-
{ from: 'off', to: 'red', action: 'on', kind: 'legal', forced_only: false, main_path: false },
|
|
49
|
-
{ from: 'red', to: 'off', action: 'off', kind: 'legal', forced_only: false, main_path: false }
|
|
50
|
-
]
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('Red has actions().length 1', () =>
|
|
54
|
-
expect( act_machine.actions().length )
|
|
55
|
-
.toBe(1) );
|
|
56
|
-
|
|
57
|
-
test('Red has actions()[0] "on"', () =>
|
|
58
|
-
expect( act_machine.actions()[0] )
|
|
59
|
-
.toBe('on') );
|
|
60
|
-
|
|
61
|
-
test('Red has actions().length 1 again', () =>
|
|
62
|
-
expect( act_machine.actions('off').length )
|
|
63
|
-
.toBe(1) );
|
|
64
|
-
|
|
65
|
-
test('Red has actions()[0] "on" again', () =>
|
|
66
|
-
expect( act_machine.actions('off')[0] )
|
|
67
|
-
.toBe('on') );
|
|
68
|
-
|
|
69
|
-
test('Red has actions().length 1 re-again', () =>
|
|
70
|
-
expect( act_machine.actions('red').length )
|
|
71
|
-
.toBe(1) );
|
|
72
|
-
|
|
73
|
-
test('Red has actions()[0] "off" re-again', () =>
|
|
74
|
-
expect( act_machine.actions('red')[0] )
|
|
75
|
-
.toBe('off') );
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
describe('States having actions', () => {
|
|
84
|
-
|
|
85
|
-
const sha_machine = new jssm.Machine({
|
|
86
|
-
start_states : ['off'],
|
|
87
|
-
transitions : [
|
|
88
|
-
{ from: 'off', to: 'red', action: 'on', kind: 'legal', forced_only: false, main_path: false },
|
|
89
|
-
{ from: 'red', to: 'off', action: 'off', kind: 'legal', forced_only: false, main_path: false }
|
|
90
|
-
]
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('One action has "on"', () =>
|
|
94
|
-
expect( sha_machine.list_states_having_action('on').length )
|
|
95
|
-
.toBe(1) );
|
|
96
|
-
|
|
97
|
-
test('"on" is had by "off"', () =>
|
|
98
|
-
expect( sha_machine.list_states_having_action('on')[0] )
|
|
99
|
-
.toBe('off') );
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
describe('List exit actions', () => {
|
|
108
|
-
|
|
109
|
-
const lea_machine = new jssm.Machine({
|
|
110
|
-
start_states : ['off'],
|
|
111
|
-
transitions : [
|
|
112
|
-
{ from: 'off', to: 'red', action: 'on', kind: 'legal', forced_only: false, main_path: false },
|
|
113
|
-
{ from: 'red', to: 'off', action: 'off', kind: 'legal', forced_only: false, main_path: false }
|
|
114
|
-
]
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('List exit actions, shows "on" from off as default', () =>
|
|
118
|
-
expect( lea_machine.list_exit_actions()[0] )
|
|
119
|
-
.toBe('on') );
|
|
120
|
-
|
|
121
|
-
test('List exit actions, shows "on" from off', () =>
|
|
122
|
-
expect( lea_machine.list_exit_actions('off')[0] )
|
|
123
|
-
.toBe('on') );
|
|
124
|
-
|
|
125
|
-
test('List exit actions, shows "off" from red', () =>
|
|
126
|
-
expect( lea_machine.list_exit_actions('red')[0] )
|
|
127
|
-
.toBe('off') );
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
describe('Reports on action edges', () => {
|
|
136
|
-
|
|
137
|
-
const roae_machine = new jssm.Machine({
|
|
138
|
-
start_states : ['off'],
|
|
139
|
-
transitions : [
|
|
140
|
-
{ name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false }
|
|
141
|
-
]
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('Reports on action edges, that it has', () =>
|
|
145
|
-
expect( typeof roae_machine.current_action_edge_for('power_on') )
|
|
146
|
-
.toBe('object') );
|
|
147
|
-
|
|
148
|
-
test('Reports on action edges, that it doesn\'t have', () =>
|
|
149
|
-
expect( () => roae_machine.current_action_edge_for('power_west') )
|
|
150
|
-
.toThrow() );
|
|
151
|
-
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
describe('Two nodes should be able to have matching edges with differing action labels', () => {
|
|
159
|
-
|
|
160
|
-
// const machine = sm`a 'first' -> a; a 'second' -> a;`;
|
|
161
|
-
|
|
162
|
-
// test('that it has', () => expect( typeof machine.current_action_edge_for('power_on') ).toBe('object') );
|
|
163
|
-
// test('that it doesn\'t have', () => expect( () => machine.current_action_edge_for('power_west') ).toThrow() );
|
|
164
|
-
|
|
165
|
-
test.todo('todo - uncomment when #531 is resolved');
|
|
166
|
-
|
|
167
|
-
});
|