-
Notifications
You must be signed in to change notification settings - Fork 21
/
general.spec.ts
988 lines (616 loc) · 25.6 KB
/
general.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
/* eslint-disable max-len */
import * as jssm from '../jssm';
test('build-set version number is present', () =>
expect(typeof jssm.version)
.toBe('string'));
test('build_time is present', () =>
expect(typeof jssm.build_time)
.toBe('number'));
describe('Stochastic weather', () => {
new jssm.Machine({
start_states: ['breezy'],
transitions: [
{ from: 'breezy', to: 'breezy', probability: 0.4, kind: 'legal', forced_only: false, main_path: false },
{ from: 'breezy', to: 'sunny', probability: 0.3, kind: 'legal', forced_only: false, main_path: false },
{ from: 'breezy', to: 'cloudy', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'breezy', to: 'windy', probability: 0.1, kind: 'legal', forced_only: false, main_path: false },
{ from: 'breezy', to: 'rain', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'sunny', to: 'sunny', probability: 0.5, kind: 'legal', forced_only: false, main_path: false },
{ from: 'sunny', to: 'hot', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'sunny', to: 'breezy', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'sunny', to: 'cloudy', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'sunny', to: 'rain', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'hot', to: 'hot', probability: 0.75, kind: 'legal', forced_only: false, main_path: false },
{ from: 'hot', to: 'breezy', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'hot', to: 'sunny', probability: 0.2, kind: 'legal', forced_only: false, main_path: false },
{ from: 'cloudy', to: 'cloudy', probability: 0.6, kind: 'legal', forced_only: false, main_path: false },
{ from: 'cloudy', to: 'sunny', probability: 0.2, kind: 'legal', forced_only: false, main_path: false },
{ from: 'cloudy', to: 'rain', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'cloudy', to: 'breezy', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'windy', to: 'windy', probability: 0.3, kind: 'legal', forced_only: false, main_path: false },
{ from: 'windy', to: 'gale', probability: 0.1, kind: 'legal', forced_only: false, main_path: false },
{ from: 'windy', to: 'breezy', probability: 0.4, kind: 'legal', forced_only: false, main_path: false },
{ from: 'windy', to: 'rain', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'windy', to: 'sunny', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'gale', to: 'gale', probability: 0.65, kind: 'legal', forced_only: false, main_path: false },
{ from: 'gale', to: 'windy', probability: 0.25, kind: 'legal', forced_only: false, main_path: false },
{ from: 'gale', to: 'torrent', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'gale', to: 'hot', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'rain', to: 'rain', probability: 0.3, kind: 'legal', forced_only: false, main_path: false },
{ from: 'rain', to: 'torrent', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'rain', to: 'windy', probability: 0.1, kind: 'legal', forced_only: false, main_path: false },
{ from: 'rain', to: 'breezy', probability: 0.15, kind: 'legal', forced_only: false, main_path: false },
{ from: 'rain', to: 'sunny', probability: 0.1, kind: 'legal', forced_only: false, main_path: false },
{ from: 'rain', to: 'cloudy', probability: 0.3, kind: 'legal', forced_only: false, main_path: false },
{ from: 'torrent', to: 'torrent', probability: 0.65, kind: 'legal', forced_only: false, main_path: false },
{ from: 'torrent', to: 'rain', probability: 0.25, kind: 'legal', forced_only: false, main_path: false },
{ from: 'torrent', to: 'cloudy', probability: 0.05, kind: 'legal', forced_only: false, main_path: false },
{ from: 'torrent', to: 'gale', probability: 0.05, kind: 'legal', forced_only: false, main_path: false }
]
});
test.todo('Unfinished test case in general spec');
});
describe('Arrow direction', () => {
test('arrow_direction reads left correctly', () =>
expect(jssm.arrow_direction('<-'))
.toBe('left') );
test('arrow_direction reads right correctly', () =>
expect(jssm.arrow_direction('->'))
.toBe('right') );
test('arrow_direction reads both correctly', () =>
expect(jssm.arrow_direction('<->'))
.toBe('both') );
});
describe('list exit actions', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ from:'off', to:'red', action:'on', kind: 'legal', forced_only: false, main_path: false },
{ from:'red', to:'off', action:'off', kind: 'legal', forced_only: false, main_path: false }
]
});
test('shows "on" from off as default', () =>
expect(machine.list_exit_actions()[0])
.toBe('on') );
test('shows "on" from off', () =>
expect(machine.list_exit_actions('off')[0])
.toBe('on') );
test('shows "off" from red', () =>
expect(machine.list_exit_actions('red')[0])
.toBe('off') );
});
describe('probable exits for', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[ { from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false } ]
});
test('probable exits are an array', () =>
expect(Array.isArray(machine.probable_exits_for('off')) )
.toBe(true) );
test('one probable exit in example', () =>
expect(machine.probable_exits_for('off').length)
.toBe(1) );
test('exit is an object', () =>
expect(typeof machine.probable_exits_for('off')[0])
.toBe('object') );
test('exit 0 has a string from property', () =>
expect(typeof machine.probable_exits_for('off')[0].from)
.toBe('string') );
});
describe('probable action exits', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ from:'off', to:'red', action:'on', kind: 'legal', forced_only: false, main_path: false },
{ from:'red', to:'off', action:'off', kind: 'legal', forced_only: false, main_path: false }
]
});
test('probable action exits are an array', () =>
expect(Array.isArray(machine.probable_action_exits()) )
.toBe(true) );
test('probable action exit 1 is on', () =>
expect(machine.probable_action_exits()[0].action)
.toBe('on') );
test('probable action exits are an array 2', () =>
expect(Array.isArray(machine.probable_action_exits('off')) )
.toBe(true) );
test('probable action exit 1 is on 2', () =>
expect(machine.probable_action_exits('off')[0].action)
.toBe('on') );
test('probable action exits are an array 3', () =>
expect(Array.isArray(machine.probable_action_exits('red')) )
.toBe(true) );
test('probable action exit 1 is on 3', () =>
expect(machine.probable_action_exits('red')[0].action)
.toBe('off') );
});
describe('probabilistic_transition', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [ { from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false } ]
});
machine.probabilistic_transition();
test('solo after probabilistic is red', () =>
expect(machine.state())
.toBe('red') );
});
describe('probabilistic_walk', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false },
{ from: 'red', to: 'off', kind: 'legal', forced_only: false, main_path: false }
]
});
machine.probabilistic_walk(3);
test('solo after probabilistic walk 3 is red', () =>
expect(machine.state())
.toBe('red') );
});
describe('probabilistic_histo_walk', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false },
{ from: 'red', to: 'off', kind: 'legal', forced_only: false, main_path: false }
]
});
const histo = machine.probabilistic_histo_walk(3);
test('histo is a Map', () =>
expect(histo instanceof Map)
.toBe(true) );
test('histo red is 2', () =>
expect(histo.get('red'))
.toBe(2) );
test('histo off is 2', () =>
expect(histo.get('off'))
.toBe(2) );
});
describe('reports state_is_final', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[
{ from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false },
{ from: 'off', to: 'mid', kind: 'legal', forced_only: false, main_path: false },
{ from: 'mid', to: 'fin', kind: 'legal', forced_only: false, main_path: false }
],
complete:['red', 'mid']
});
test('final false for neither', () =>
expect(machine.state_is_final('off') )
.toBe(false) );
test('final true for just terminal', () =>
expect(machine.state_is_final('mid') )
.toBe(true) );
test('final true for just complete', () =>
expect(machine.state_is_final('fin') )
.toBe(true) );
test('final true', () =>
expect(machine.state_is_final('red') )
.toBe(true) );
});
describe('reports is_final', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[
{ from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false }
],
complete:['red']
});
const init_final = machine.is_final();
machine.transition('red');
const fin_final = machine.is_final();
test('final false', () =>
expect(init_final)
.toBe(false) );
test('final true', () =>
expect(fin_final)
.toBe(true) );
// why is this written this way?
/* todo whargarbl needs another two tests for is_changing once reintroduced */
});
describe('reports state_is_terminal', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [ { name: 'turn_on', action: 'power_on', from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false } ]
});
test('terminal false', () =>
expect(machine.state_is_terminal('off') )
.toBe(false) );
test('terminal true', () =>
expect(machine.state_is_terminal('red') )
.toBe(true) );
test('terminal on missing state throws', () =>
expect( () => machine.state_is_terminal('notARealState') )
.toThrow() );
});
describe('reports is_terminal', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [ { name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false} ]
});
const first = machine.is_terminal();
machine.transition('red');
const second = machine.is_terminal();
const terms = machine.has_terminals();
// why is this written this way?
test('terminal false', () =>
expect(first)
.toBe(false) );
test('terminal true', () =>
expect(second)
.toBe(true) );
test('has_terminals', () =>
expect(terms)
.toBe(true) );
});
describe('reports state_is_complete', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[ { name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false} ],
complete:['off'] // huhu
});
test('state_is_complete false', () =>
expect(machine.state_is_complete('off') )
.toBe(true) );
test('state_is_complete true', () =>
expect(machine.state_is_complete('red') )
.toBe(false) );
test('throws on nonexisting state', () =>
expect( () => machine.state_is_complete('thisStateDoesNotExist') )
.toThrow() );
});
describe('reports is_complete', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[ { name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false} ],
complete:['off'] // huhu
});
const first = machine.is_complete();
machine.transition('red');
const second = machine.is_complete();
const terms = machine.has_completes();
// why is this written this way?
test('is_complete false', () =>
expect(first)
.toBe(true) );
test('is_complete true', () =>
expect(second)
.toBe(false) );
test('has_completes', () =>
expect(terms)
.toBe(true) );
});
describe('reports on actions', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[ { name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false} ]
});
const a = machine.list_actions(); // todo comeback
test('that it has', () =>
expect(typeof machine.current_action_for('power_on') )
.toBe('number') );
test('that it doesn\'t have', () =>
expect(typeof machine.current_action_for('power_left') )
.toBe('undefined') );
test('correct list type', () =>
expect(Array.isArray(a))
.toBe(true) );
test('correct list size', () =>
expect(a.length)
.toBe(1) );
});
describe('actions', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ from:'off', to:'red', action:'on', kind: 'legal', forced_only: false, main_path: false },
{ from:'red', to:'off', action:'off', kind: 'legal', forced_only: false, main_path: false }
]
});
test('red has actions().length 1', () =>
expect(machine.actions().length)
.toBe(1) );
test('red has actions()[0] "on"', () =>
expect(machine.actions()[0])
.toBe('on') );
test('red has actions().length 1 again', () =>
expect(machine.actions('off').length)
.toBe(1) );
test('red has actions()[0] "on" again', () =>
expect(machine.actions('off')[0])
.toBe('on') );
test('red has actions().length 1 re-again', () =>
expect(machine.actions('red').length)
.toBe(1) );
test('red has actions()[0] "off" re-again',
() => expect(machine.actions('red')[0])
.toBe('off') );
});
describe('states having action', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ from:'off', to: 'red', action: 'on', kind: 'legal', forced_only: false, main_path: false },
{ from:'red', to: 'off', action: 'off', kind: 'legal', forced_only: false, main_path: false }
]
});
test('one action has on', () =>
expect(machine.list_states_having_action('on').length)
.toBe(1) );
test('on is had by off', () =>
expect(machine.list_states_having_action('on')[0])
.toBe('off') );
});
describe('unenterables', () => {
const machine = new jssm.Machine({
start_states: ['off'],
transitions:[ { name:'turn_on', action: 'power_on', from: 'off', to: 'red', kind: 'legal', forced_only: false, main_path: false } ]
});
test('off isn\'t enterable', () =>
expect(machine.is_unenterable('off') )
.toBe(true) );
test('red is enterable', () =>
expect(machine.is_unenterable('red') )
.toBe(false) );
test('machine has unenterables', () =>
expect(machine.has_unenterables() )
.toBe(true) );
test('unenterable test on missing state throws', () =>
expect( () => machine.is_unenterable('notARealState') )
.toThrow() );
});
describe('reports on action edges', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false }
]
});
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() );
});
describe('reports on states', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false }
]
});
test('that it has', () =>
expect(typeof machine.state_for('off') )
.toBe('object') );
test('that it doesn\'t have', () =>
expect(() => { machine.state_for('no such state'); })
.toThrow() );
});
describe('returns states', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false }
]
});
test('that it has', () =>
expect( typeof machine.machine_state() )
.toBe('object') );
});
describe('initializes with states', () => {
describe('without start state list', () => {
['Red', 'Yellow', 'Green'].forEach( color => {
const machine = jssm.from(`start_states: [Red Yellow Green]; Red => Green => Yellow => Red;`, { initial_state: color });
test(`Initial state in traffic light is ${color}`, () =>
expect(machine.state()).toBe(color));
});
});
test('fails because that state is absent', () =>
expect(() => jssm.from(`start_states: [Red Yellow Green]; Red => Green => Yellow => Red;`, { initial_state: 'Blue' }))
.toThrow());
});
describe('reports on transitions', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [
{ name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false }
]
});
test('unspecified transition return type', () =>
expect(typeof machine.list_transitions() )
.toBe('object') );
test('unspecified transition correct entrance count', () =>
expect(machine.list_transitions().entrances.length)
.toBe(0) );
test('unspecified transition correct exit count', () =>
expect(machine.list_transitions().exits.length)
.toBe(1) );
test('specified transition return type', () =>
expect(typeof machine.list_transitions('off') )
.toBe('object') );
test('specified transition correct entrance count', () =>
expect(machine.list_transitions('off').entrances.length)
.toBe(0) );
test('specified transition correct exit count', () =>
expect(machine.list_transitions('off').exits.length)
.toBe(1) );
test('no such spec trans return type', () =>
expect(typeof machine.list_transitions('moot') )
.toBe('object') );
test('no such spec trans correct entrance count', () =>
expect(machine.list_transitions('moot').entrances.length)
.toBe(0) );
test('no such spec trans correct exit count', () =>
expect(machine.list_transitions('moot').exits.length)
.toBe(0) );
test('unspecified entrance return type', () =>
expect(Array.isArray( machine.list_entrances() ))
.toBe(true) );
test('unspecified entrance correct count', () =>
expect(machine.list_entrances().length)
.toBe(0) );
test('specified entrance return type', () =>
expect(Array.isArray( machine.list_entrances('off') ))
.toBe(true) );
test('specified entrance correct count', () =>
expect(machine.list_entrances('off').length)
.toBe(0) );
test('no such specified entrance return type', () =>
expect(Array.isArray( machine.list_entrances('moot') ))
.toBe(true) ); // todo whargarbl should these throw?
test('no such specified entrance correct count', () =>
expect(machine.list_entrances('moot').length)
.toBe(0) );
test('unspecified exit return type', () =>
expect(Array.isArray( machine.list_exits() ))
.toBe(true) );
test('unspecified exit correct count', () =>
expect(machine.list_exits().length)
.toBe(1) );
test('specified exit return type', () =>
expect(Array.isArray( machine.list_exits('off') ))
.toBe(true) );
test('specified exit correct count', () =>
expect(machine.list_exits('off').length)
.toBe(1) );
test('no such specified exit return type', () =>
expect(Array.isArray( machine.list_exits('moot') ))
.toBe(true) );
test('no such specified exit correct count', () =>
expect(machine.list_exits('moot').length)
.toBe(0) );
test('edge list return type', () =>
expect(Array.isArray( machine.list_edges() ))
.toBe(true) );
test('edge list correct count', () =>
expect(machine.list_edges().length)
.toBe(1) );
});
describe('transition by state names', () => {
const machine = new jssm.Machine({
start_states : ['off'],
transitions : [ { name:'turn_on', action:'power_on', from:'off', to:'red', kind: 'legal', forced_only: false, main_path: false } ]
});
test('finds off -> red', () =>
expect(machine.get_transition_by_state_names('off', 'red') )
.toBe(0) );
test('does not find off -> blue', () =>
expect(machine.get_transition_by_state_names('off', 'blue') )
.toBe(undefined) );
test('does not find blue -> red', () =>
expect(machine.get_transition_by_state_names('blue', 'red') )
.toBe(undefined) );
});
describe('Illegal machines', () => {
test('catch repeated names', () => expect( () => {
new jssm.Machine({
start_states: ['moot'],
transitions:[
{ name: 'identical', from: '1', to: '2', kind: 'legal', forced_only: false, main_path: false },
{ name: 'identical', from: '2', to: '3', kind: 'legal', forced_only: false, main_path: false }
]
});
}).toThrow() );
test('must define from', () => expect( () => {
new jssm.Machine({
start_states: ['moot'],
transitions:[
{ name:'identical', to:'2', kind: 'legal', forced_only: false, main_path: false }
]
} as any);
}).toThrow() );
test('must define to', () => expect( () => {
new jssm.Machine({
start_states: ['moot'],
transitions:[
{ name:'identical', from:'1', kind: 'legal', forced_only: false, main_path: false }
]
} as any);
}).toThrow() );
test('must not have two identical edges', () => expect( () => {
new jssm.Machine({
start_states: ['moot'],
transitions:[
{ name:'id1', from:'1', to:'2', kind: 'legal', forced_only: false, main_path: false },
{ name:'id2', from:'1', to:'2', kind: 'legal', forced_only: false, main_path: false }
]
});
}).toThrow() );
test('must not have two of the same action from the same source', () => expect( () => {
new jssm.Machine({
start_states: ['moot'],
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false },
{ name:'id2', from:'1', to:'3', action:'identical', kind: 'legal', forced_only: false, main_path: false }
]
});
}).toThrow() );
test.todo('Does is_complete need an argument?');
// test('must not have completion of non-state', () => expect( () => {
// const machine = new jssm.Machine({
// start_states: ['moot'],
// transitions:[
// { name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
// ]
// });
// machine.is_complete('no such state');
// }).toThrow() );
test.todo('is the _new_state api misunderstood in these tests?')
// test('internal state helper must not accept double states', () => expect( () => {
// const machine = new jssm.Machine({
// start_states: ['moot'],
// transitions:[
// { name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
// ]
// });
// machine._new_state({from: '1', name:'id1', to:'2', complete:false});
// machine._new_state({from: '1', name:'id1', to:'2', complete:false});
// }).toThrow() );
test('can\'t get actions of non-state', () => expect( () => {
const machine = new jssm.Machine({
start_states: ['1'],
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
]
});
machine.actions('three');
}).toThrow() );
test('can\'t get states having non-action', () => expect( () => {
const machine = new jssm.Machine({
start_states: ['1'],
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
]
});
machine.list_states_having_action('no such action');
}).toThrow() );
test('can\'t list exit states of non-action', () => expect( () => {
const machine = new jssm.Machine({
start_states: ['1'],
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
]
});
machine.list_exit_actions('no such action');
}).toThrow() );
test('probable exits for throws on non-state', () => expect( () => {
const machine = new jssm.Machine({
start_states: ['1'],
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
]
});
machine.probable_exits_for('3');
}).toThrow() );
test('no probable action exits of non-action', () => expect( () => {
const machine = new jssm.Machine({
start_states: ['1'],
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical', kind: 'legal', forced_only: false, main_path: false }
]
});
machine.probable_action_exits('no such action');
}).toThrow() );
});