-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathslim_test_core.cpp
2679 lines (2363 loc) · 285 KB
/
slim_test_core.cpp
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
989
990
991
992
993
994
995
996
997
998
999
1000
//
// slim_test_core.cpp
// SLiM
//
// Created by Ben Haller on 7/11/20.
// Copyright (c) 2020-2025 Philipp Messer. All rights reserved.
// A product of the Messer Lab, http://messerlab.org/slim/
//
// This file is part of SLiM.
//
// SLiM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// SLiM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with SLiM. If not, see <http://www.gnu.org/licenses/>.
#include "slim_test.h"
#include "eidos_globals.h"
#include <string>
#pragma mark initialize() tests
void _RunInitTests(void)
{
// ************************************************************************************
//
// Initialization function tests
//
// Test (void)initializeGeneConversion(numeric$ conversionFraction, numeric$ meanLength)
SLiMAssertScriptStop("initialize() { initializeGeneConversion(0.5, 10000000000000, 0.0); stop(); }", __LINE__); // legal; no max for meanLength
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(-0.001, 10000000000000, 0.0); stop(); }", "nonCrossoverFraction must be between 0.0 and 1.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(1.001, 10000000000000, 0.0); stop(); }", "nonCrossoverFraction must be between 0.0 and 1.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(0.5, -0.01, 0.0); stop(); }", "meanLength must be >= 0.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(0.5, 1000, -0.001); stop(); }", "simpleConversionFraction must be between 0.0 and 1.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(0.5, 1000, 1.001); stop(); }", "simpleConversionFraction must be between 0.0 and 1.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(0.5, 1000, 0.0, -1.001); stop(); }", "bias must be between -1.0 and 1.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(0.5, 1000, 0.0, 1.001); stop(); }", "bias must be between -1.0 and 1.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeGeneConversion(0.5, 1000, 0.0, 0.1); stop(); }", "must be 0.0 in non-nucleotide-based models", __LINE__);
// Test (object<MutationType>$)initializeMutationType(is$ id, numeric$ dominanceCoeff, string$ distributionType, ...)
SLiMAssertScriptStop("initialize() { initializeMutationType('m1', 0.5, 'f', 0.0); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeMutationType(1, 0.5, 'f', 0.0); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType(-1, 0.5, 'f', 0.0); stop(); }", "identifier value is out of range", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('p2', 0.5, 'f', 0.0); stop(); }", "identifier prefix 'm' was expected", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('mm1', 0.5, 'f', 0.0); stop(); }", "must be a simple integer", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'f'); stop(); }", "requires exactly 1 DFE parameter", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'f', 0.0, 0.0); stop(); }", "requires exactly 1 DFE parameter", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', 0.0); stop(); }", "requires exactly 2 DFE parameters", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'e', 0.0, 0.0); stop(); }", "requires exactly 1 DFE parameter", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'n', 0.0); stop(); }", "requires exactly 2 DFE parameters", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', 0.0); stop(); }", "requires exactly 2 DFE parameters", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 0.0); stop(); }", "requires exactly 2 DFE parameters", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'f', 'foo'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', 'foo', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', 0.0, 'foo'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'e', 'foo'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'n', 'foo', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'n', 0.0, 'foo'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', 'foo', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', 0.0, 'foo'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 'foo', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 0.0, 'foo'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'f', '1'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', '1', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', 0.0, '1'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'e', '1'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'n', '1', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'n', 0.0, '1'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', '1', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', 0.0, '1'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', '1', 0.0); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 0.0, '1'); stop(); }", "must be of type numeric", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'x', 0.0); stop(); }", "must be 'f', 'g', 'e', 'n', 'w', or 's'", __LINE__);
SLiMAssertScriptStop("initialize() { x = initializeMutationType('m7', 0.5, 'f', 0.0); if (x == m7) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { x = initializeMutationType(7, 0.5, 'f', 0.0); if (x == m7) stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { m7 = 15; initializeMutationType(7, 0.5, 'f', 0.0); stop(); }", "already defined", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'f', 0.0); initializeMutationType('m1', 0.5, 'f', 0.0); stop(); }", "already defined", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', 3.1, 0.0); stop(); }", "must have a shape parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'g', 3.1, -1.0); stop(); }", "must have a shape parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'n', 3.1, -1.0); stop(); }", "must have a standard deviation parameter >= 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', 3.1, 0.0); stop(); }", "must have a scale parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'p', 3.1, -1.0); stop(); }", "must have a scale parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 0.0, 7.5); stop(); }", "must have a scale parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', -1.0, 7.5); stop(); }", "must have a scale parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 3.1, 0.0); stop(); }", "must have a shape parameter > 0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationType('m1', 0.5, 'w', 3.1, -7.5); stop(); }", "must have a shape parameter > 0", __LINE__);
// Test (object<GenomicElementType>$)initializeGenomicElementType(is$ id, io<MutationType> mutationTypes, numeric proportions)
std::string define_m12(" initializeMutationType('m1', 0.5, 'f', 0.0); initializeMutationType('m2', 0.5, 'f', 0.5); ");
SLiMAssertScriptStop("initialize() {" + define_m12 + "initializeGenomicElementType('g1', object(), integer(0)); stop(); }", __LINE__); // legal: genomic element with no mutations
SLiMAssertScriptStop("initialize() {" + define_m12 + "initializeGenomicElementType('g1', integer(0), float(0)); stop(); }", __LINE__); // legal: genomic element with no mutations
SLiMAssertScriptStop("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(m1,m2), c(0,0)); stop(); }", __LINE__); // legal: genomic element with all zero proportions (must be fixed later...)
SLiMAssertScriptStop("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(m1,m2), 1:2); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() {" + define_m12 + "initializeGenomicElementType(1, c(m1,m2), 1:2); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() {" + define_m12 + "initializeGenomicElementType('g1', 1:2, 1:2); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(m1,m2)); stop(); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(m1,m2), 1); stop(); }", "requires the sizes", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(m1,m2), c(-1,2)); stop(); }", "must be greater than or equal to zero", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "initializeGenomicElementType('g1', 2:3, 1:2); stop(); }", "not defined", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(2,2), 1:2); stop(); }", "used more than once", __LINE__);
SLiMAssertScriptStop("initialize() {" + define_m12 + "x = initializeGenomicElementType('g7', c(m1,m2), 1:2); if (x == g7) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() {" + define_m12 + "x = initializeGenomicElementType(7, c(m1,m2), 1:2); if (x == g7) stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "g7 = 17; initializeGenomicElementType(7, c(m1,m2), 1:2); stop(); }", "already defined", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_m12 + "initializeGenomicElementType('g1', c(m1,m2), 1:2); initializeGenomicElementType('g1', c(m1,m2), c(0,0)); stop(); }", "already defined", __LINE__);
// Test (void)initializeGenomicElement(io<GenomicElementType>$ genomicElementType, integer$ start, integer$ end)
std::string define_g1(define_m12 + " initializeGenomicElementType('g1', c(m1,m2), 1:2); ");
SLiMAssertScriptStop("initialize() {" + define_g1 + "initializeGenomicElement(g1, 0, 1000000000); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() {" + define_g1 + "initializeGenomicElement(1, 0, 1000000000); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeGenomicElement(g1, 0); stop(); }", "cannot be NULL separately", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeGenomicElement(2, 0, 1000000000); stop(); }", "not defined", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeGenomicElement(g1, -1, 1000000000); stop(); }", "out of range", __LINE__);
//SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeGenomicElement(g1, 0, 1000000001); stop(); }", "out of range", __LINE__); // now legal!
SLiMAssertScriptStop("initialize() {" + define_g1 + "initializeGenomicElement(g1, 0, 1000000000000000); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeGenomicElement(g1, 0, 1000000000000001); stop(); }", "out of range", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeGenomicElement(g1, 100, 99); stop(); }", "is less than start position", __LINE__);
// Test (void)initializeMutationRate(numeric$ rate)
SLiMAssertScriptStop("initialize() { initializeMutationRate(0.0); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationRate(); stop(); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationRate(-0.0000001); stop(); }", "requires rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationRate(10000000); stop(); }", "requires rates to be", __LINE__); // no longer legal, in SLiM 3.5
// Test (void)initializeRecombinationRate(numeric rates, [integer ends])
SLiMAssertScriptStop("initialize() { initializeRecombinationRate(0.0); stop(); }", __LINE__); // legal: singleton rate, no end
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(); stop(); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(-0.00001); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeRecombinationRate(0.5); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(0.6); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(10000); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000)); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(c(0.0, 0.1)); stop(); }", "requires rates to be a singleton if", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(integer(0), integer(0)); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(c(0.0, 0.1), 1000); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(c(0.0, 0.1), 1:3); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(c(0.0, 0.1), c(2000, 1000)); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(c(0.0, 0.1), c(1000, 1000)); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeRecombinationRate(c(0.0, -0.001), c(1000, 2000)); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeRecombinationRate(0.0); stop(); }", __LINE__); // legal: singleton rate, no end
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(); stop(); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(-0.00001); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeRecombinationRate(0.5); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(0.6); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(10000); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000)); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1)); stop(); }", "requires rates to be a singleton if", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(integer(0), integer(0)); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), 1000); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), 1:3); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(2000, 1000)); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 1000)); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, -0.001), c(1000, 2000)); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), '*'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(integer(0), integer(0), '*'); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), 1000, '*'); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), 1:3, '*'); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(2000, 1000), '*'); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 1000), '*'); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, -0.001), c(1000, 2000), '*'); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(integer(0), integer(0), 'M'); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), 1000, 'M'); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), 1:3, 'M'); stop(); }", "ends and rates to be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(2000, 1000), 'M'); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 1000), 'M'); stop(); }", "ascending order", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeRecombinationRate(c(0.0, -0.001), c(1000, 2000), 'M'); stop(); }", "requires rates to be in [0.0, 0.5]", __LINE__);
SLiMAssertScriptStop("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 2000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); initializeRecombinationRate(0.0, 2000, 'F'); stop(); } 1 early() {}", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 3000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); initializeRecombinationRate(0.0, 2000, 'F'); } 1 early() {}", "do not cover the full chromosome", __LINE__, false);
SLiMAssertScriptStop("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 1000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); initializeRecombinationRate(0.0, 2000, 'F'); } 1 early() { stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 2000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); initializeRecombinationRate(0.0, 1999, 'F'); } 1 early() {}", "do not cover the full chromosome", __LINE__, false);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 2000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); initializeRecombinationRate(0.0, 2001, 'F'); } 1 early() { stop(); }", "do not cover the full chromosome", __LINE__, false);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 2000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), 'M'); initializeRecombinationRate(0.0, 2000, '*'); } 1 early() {}", "single map versus separate maps", __LINE__);
SLiMAssertScriptRaise("initialize() {" + define_g1 + "initializeMutationRate(0.0); initializeGenomicElement(g1, 0, 2000); initializeSex('A'); initializeRecombinationRate(c(0.0, 0.1), c(1000, 2000), '*'); initializeRecombinationRate(0.0, 2000, 'F'); } 1 early() {}", "single map versus separate maps", __LINE__);
// Test (void)initializeSex(string$ chromosomeType)
SLiMAssertScriptStop("initialize() { initializeSex('A'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('X'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('Y'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('Z'); stop(); }", "requires a chromosomeType of", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSex('A'); initializeSex('A'); stop(); }", "may be called only once", __LINE__);
// Test (void)initializeSLiMModelType(string$ modelType)
SLiMAssertScriptRaise("initialize() { initializeSLiMModelType(); stop(); }", "missing required argument 'modelType'", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMModelType('WF'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMModelType('nonWF'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMModelType('foo'); stop(); }", "legal values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(); initializeSLiMModelType('WF'); stop(); }", "must be called before", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationRate(0.0); initializeSLiMModelType('WF'); stop(); }", "must be called before", __LINE__);
// Test (void)initializeSLiMOptions([logical$ keepPedigrees = F], [string$ dimensionality = ""], [string$ periodicity = ""], [integer$ mutationRuns = 0], [logical$ preventIncidentalSelfing = F])
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(F); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(T); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(F, ''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(T, ''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(F, 'xyz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(T, 'xyz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality=''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xy'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='', periodicity=''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x', periodicity=''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x', periodicity='x'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xy', periodicity=''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xy', periodicity='x'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xy', periodicity='y'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xy', periodicity='xy'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity=''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='x'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='y'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='z'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='xy'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='xz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='yz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='xyz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(preventIncidentalSelfing=F); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(preventIncidentalSelfing=T); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(keepPedigrees=NULL); stop(); }", "cannot be type NULL", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality=NULL); stop(); }", "cannot be type NULL", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(preventIncidentalSelfing=NULL); stop(); }", "cannot be type NULL", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='foo'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='y'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='z'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xz'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='yz'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='zyx'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='', periodicity='x'); stop(); }", "may not be set in non-spatial simulations", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x', periodicity='y'); stop(); }", "cannot utilize spatial dimensions beyond", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x', periodicity='z'); stop(); }", "cannot utilize spatial dimensions beyond", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xy', periodicity='z'); stop(); }", "cannot utilize spatial dimensions beyond", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='foo'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xyz', periodicity='xzy'); stop(); }", "legal non-empty values", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(); initializeSLiMOptions(); stop(); }", "may be called only once", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeMutationRate(0.0); initializeSLiMOptions(); stop(); }", "must be called before", __LINE__);
// Test (object<InteractionType>$)initializeInteractionType(is$ id, string$ spatiality, [logical$ reciprocal = F], [numeric$ maxDistance = INF], [string$ sexSegregation = "**"])
SLiMAssertScriptRaise("initialize() { initializeInteractionType(-1, ''); stop(); }", "identifier value is out of range", __LINE__);
SLiMAssertScriptStop("initialize() { initializeInteractionType(0, ''); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeInteractionType('i0', ''); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType(0, 'x'); stop(); }", "spatial dimensions beyond those set", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType('i0', 'x'); stop(); }", "spatial dimensions beyond those set", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType(0, 'w'); stop(); }", "spatiality 'w' must be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType('i0', 'w'); stop(); }", "spatiality 'w' must be", __LINE__);
SLiMAssertScriptStop("initialize() { initializeInteractionType(0, '', T); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType(0, '', T, 0.1); stop(); }", "must be INF for non-spatial interactions", __LINE__);
SLiMAssertScriptStop("initialize() { initializeInteractionType(0, '', T, INF, '**'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType(0, '', T, INF, '*M'); stop(); }", "unsupported in non-sexual simulation", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, '**'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, '*M'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, '*F'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, 'M*'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, 'MM'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, 'MF'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, 'F*'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, 'FM'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSex('A'); initializeInteractionType(0, '', T, INF, 'FF'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType(0, '', T, INF, 'W*'); stop(); }", "unsupported sexSegregation value", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeInteractionType(0, '', T, INF, '*W'); stop(); }", "unsupported sexSegregation value", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'w'); stop(); }", "spatiality 'w' must be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType('i0', 'w'); stop(); }", "spatiality 'w' must be", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, '', T); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, '', T, 0.1); stop(); }", "must be INF for non-spatial interactions", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, '', T, INF, '**'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, '', T, INF, '*M'); stop(); }", "unsupported in non-sexual simulation", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeSex('A'); initializeInteractionType(0, '', T, INF, '*M'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, '', T, INF, 'W*'); stop(); }", "unsupported sexSegregation value", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'y'); stop(); }", "spatial dimensions beyond those set", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', F); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', T); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', F, 0.1); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', T, 0.1); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', T, 0.0); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', T, -0.1); stop(); }", "maxDistance must be >= 0.0", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='x'); initializeInteractionType(0, 'x', T, 0.1, '*M'); stop(); }", "unsupported in non-sexual simulation", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='x'); initializeSex('A'); initializeInteractionType(0, 'x', T, 0.1, '*M'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'x'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'y'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'z'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'xy'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'yz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'xz'); stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'xyz'); stop(); }", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'w'); stop(); }", "spatiality 'w' must be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'yx'); stop(); }", "spatiality 'yx' must be", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(dimensionality='xyz'); initializeInteractionType(0, 'zyx'); stop(); }", "spatiality 'zyx' must be", __LINE__);
}
#pragma mark Community tests
void _RunCommunityTests(void)
{
// Note that _RunSpeciesTests() also does some Community tests, for historical reasons...
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { community.outputUsage(); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { community.usage(); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.allGenomicElementTypes, g1)) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (community.allInteractionTypes.size() == 0) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.allMutationTypes, m1)) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (community.allScriptBlocks.size() == 3) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.allSpecies, sim)) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.allSubpopulations, p1)) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (community.logFiles.size() == 0) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (community.tick == 2) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { community.tag = 10; if (community.tag == 10) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.genomicElementTypesWithIDs(1), g1)) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.genomicElementTypesWithIDs(2); } ", "did not find", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.genomicElementTypesWithIDs(c(2,3)); } ", "did not find", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.genomicElementTypesWithIDs(c(1,1)), c(g1,g1))) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "2 early() { if (identical(community.interactionTypesWithIDs(1), i1)) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "2 early() { community.interactionTypesWithIDs(2); } ", "did not find", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "2 early() { community.interactionTypesWithIDs(c(2,3)); } ", "did not find", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "2 early() { if (identical(community.interactionTypesWithIDs(c(1,1)), c(i1,i1))) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.mutationTypesWithIDs(1), m1)) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.mutationTypesWithIDs(2); } ", "did not find", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.mutationTypesWithIDs(c(2,3)); } ", "did not find", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.mutationTypesWithIDs(c(1,1)), c(m1,m1))) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "s1 2 early() { if (identical(community.scriptBlocksWithIDs(1), self)) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "s1 2 early() { community.scriptBlocksWithIDs(2); } ", "did not find", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "s1 2 early() { community.scriptBlocksWithIDs(c(2,3)); } ", "did not find", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "s1 2 early() { if (identical(community.scriptBlocksWithIDs(c(1,1)), c(self,self))) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.speciesWithIDs(0), sim)) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.speciesWithIDs(1); } ", "did not find", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.speciesWithIDs(c(1,2)); } ", "did not find", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.speciesWithIDs(c(0,0)), c(sim,sim))) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.subpopulationsWithIDs(1), p1)) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.subpopulationsWithIDs(2); } ", "did not find", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { community.subpopulationsWithIDs(c(2,3)); } ", "did not find", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "2 early() { if (identical(community.subpopulationsWithIDs(c(1,1)), c(p1,p1))) stop(); } ", __LINE__);
}
#pragma mark Species tests
void _RunSpeciesTests(const std::string &temp_path)
{
// ************************************************************************************
//
// Gen 1+ tests: Species & Community
//
// Test sim properties
SLiMAssertScriptStop(gen1_setup + "1 first() { } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.chromosomes; } " + gen2_stop, __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.chromosomes = sim.chromosomes; } " + gen2_stop, "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.chromosomes.type == 'A') stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.chromosomes.type = 'A'; } " + gen2_stop, "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex + "1 early() { if (sim.chromosomes.type == 'X') stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup_sex + "1 early() { sim.chromosomes.type = 'X'; } " + gen2_stop, "read-only property", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { sim.cycle; } ", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.cycle = 7; } " + gen2_stop, __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { community.tick = 7; } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (community.cycleStage == 'early') stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (community.cycleStage == 'early') stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 late() { if (community.cycleStage == 'late') stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "modifyChild(p1) { if (community.cycleStage == 'reproduction') stop(); } 2 early() {}", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "mutationEffect(m1) { if (community.cycleStage == 'fitness') stop(); } 100 early() {}", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { community.cycleStage = 'early'; } ", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.genomicElementTypes == g1) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.genomicElementTypes = g1; } ", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (community.modelType == 'WF') stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex + "1 early() { if (community.modelType == 'WF') stop(); } ", __LINE__);
SLiMAssertScriptStop(WF_prefix + gen1_setup + "1 early() { if (community.modelType == 'WF') stop(); } ", __LINE__);
SLiMAssertScriptStop(WF_prefix + gen1_setup_sex + "1 early() { if (community.modelType == 'WF') stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { community.modelType = 'foo'; } ", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.mutationTypes == m1) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.mutationTypes = m1; } ", "read-only property", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { sim.mutations; } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.mutations = _Test(7); } ", "cannot be object element type", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { sim.scriptBlocks; } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.scriptBlocks = sim.scriptBlocks[0]; } ", "read-only property", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { community.allScriptBlocks; } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { community.allScriptBlocks = community.allScriptBlocks[0]; } ", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.sexEnabled == F) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex + "1 early() { if (sim.sexEnabled == T) stop(); } ", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (size(sim.subpopulations) == 0) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.subpopulations = _Test(7); } ", "cannot be object element type", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (size(sim.substitutions) == 0) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.substitutions = _Test(7); } ", "cannot be object element type", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.tag; } ", "before being set", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { c(sim,sim).tag; } ", "before being set", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { sim.tag = -17; } ", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.tag = -17; } 2 early() { if (sim.tag == -17) stop(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { community.verbosity; } ", __LINE__);
SLiMAssertScriptSuccess(gen1_setup + "1 early() { community.verbosity = -17; } ", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { community.verbosity = -17; } 2 early() { if (community.verbosity == -17) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.dimensionality == '') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "1 early() { if (sim.dimensionality == '') stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "1 early() { sim.dimensionality = 'x'; }", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1x + "1 early() { if (sim.dimensionality == 'x') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.periodicity == '') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "1 early() { if (sim.periodicity == '') stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "1 early() { sim.periodicity = 'x'; }", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1x + "1 early() { if (sim.periodicity == '') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1xyzPxz + "1 early() { if (sim.periodicity == 'xz') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { if (sim.id == 0) stop(); } ", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.id = 2; } " + gen2_stop, "read-only property", __LINE__);
// Test sim - (object<Subpopulation>)addSubpop(is$ subpopID, integer$ size, [float$ sexRatio])
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.addSubpop('p1', 10); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.addSubpop(1, 10); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.addSubpop('p1', 10, 0.5); } " + gen2_stop, __LINE__); // default value
SLiMAssertScriptStop(gen1_setup + "1 early() { sim.addSubpop(1, 10, 0.5); } " + gen2_stop, __LINE__); // default value
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.addSubpop('p1', 10, 0.4); } " + gen2_stop, "non-sexual simulation", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.addSubpop(1, 10, 0.4); } " + gen2_stop, "non-sexual simulation", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex + "1 early() { sim.addSubpop('p1', 10, 0.5); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_sex + "1 early() { sim.addSubpop(1, 10, 0.5); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { x = sim.addSubpop('p7', 10); if (x == p7) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup + "1 early() { x = sim.addSubpop(7, 10); if (x == p7) stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { p7 = 17; sim.addSubpop('p7', 10); stop(); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.addSubpop('p7', 10); sim.addSubpop(7, 10); stop(); }", "used already", __LINE__);
// Test sim - (object<Subpopulation>)addSubpopSplit(is$ subpopID, integer$ size, io<Subpopulation>$ sourceSubpop, [float$ sexRatio])
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.addSubpopSplit('p2', 10, p1); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.addSubpopSplit('p2', 10, 1); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.addSubpopSplit(2, 10, p1); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.addSubpopSplit(2, 10, 1); } " + gen2_stop, __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.addSubpopSplit(2, 10, 7); } " + gen2_stop, "not defined", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.addSubpopSplit('p2', 10, p1, 0.5); } " + gen2_stop, __LINE__); // default value
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.addSubpopSplit(2, 10, p1, 0.5); } " + gen2_stop, __LINE__); // default value
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.addSubpopSplit('p2', 10, p1, 0.4); } " + gen2_stop, "non-sexual simulation", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.addSubpopSplit(2, 10, p1, 0.4); } " + gen2_stop, "non-sexual simulation", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { sim.addSubpopSplit('p2', 10, p1, 0.5); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { sim.addSubpopSplit(2, 10, p1, 0.5); } " + gen2_stop, __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { x = sim.addSubpopSplit('p7', 10, p1); if (x == p7) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { x = sim.addSubpopSplit(7, 10, p1); if (x == p7) stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p7 = 17; sim.addSubpopSplit('p7', 10, p1); stop(); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.addSubpopSplit('p7', 10, p1); sim.addSubpopSplit(7, 10, p1); stop(); }", "used already", __LINE__);
// Test sim - (void)deregisterScriptBlock(io<SLiMEidosBlock> scriptBlocks)
SLiMAssertScriptSuccess(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(s1); } s1 2 early() { stop(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(1); } s1 2 early() { stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(object()); } s1 2 early() { stop(); }", __LINE__); // legal: deregister nothing
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(c(s1, s1)); } s1 2 early() { stop(); }", "same script block", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(c(1, 1)); } s1 2 early() { stop(); }", "same script block", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(s1); community.deregisterScriptBlock(s1); } s1 2 early() { stop(); }", "same script block", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(1); community.deregisterScriptBlock(1); } s1 2 early() { stop(); }", "same script block", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(c(s1, s2)); } s1 2 early() { stop(); } s2 3 early() { stop(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "1 early() { community.deregisterScriptBlock(c(1, 2)); } s1 2 early() { stop(); } s2 3 early() { stop(); }", __LINE__);
// Test sim - (object<Individual>)individualsWithPedigreeIDs(integer pedigreeIDs, [Nio<Subpopulation> subpops = NULL])
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.individualsWithPedigreeIDs(1); }", "when pedigree recording", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(integer(0)); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(100000); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(rep(100000, 1000)); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = p1.individuals[0]; ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = p1.individuals; ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = sample(p1.individuals, 1000, replace=T); ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.individualsWithPedigreeIDs(1, p1); }", "when pedigree recording", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(integer(0), p1); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(100000, p1); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(rep(100000, 1000), p1); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = p1.individuals[0]; ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids, p1); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = p1.individuals; ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids, p1); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = sample(p1.individuals, 1000, replace=T); ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids, p1); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.individualsWithPedigreeIDs(1, 1); }", "when pedigree recording", __LINE__);
SLiMAssertScriptRaise("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { sim.individualsWithPedigreeIDs(1, 10); }", "p10 not defined", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(integer(0), 1); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(100000, 1); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "1 early() { i = sim.individualsWithPedigreeIDs(rep(100000, 1000), 1); if (identical(i, p1.individuals[integer(0)])) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = p1.individuals[0]; ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids, 1); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = p1.individuals; ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids, 1); if (identical(i1, i2)) stop(); }", __LINE__);
SLiMAssertScriptStop("initialize() { initializeSLiMOptions(keepPedigrees=T); }" + gen1_setup_p1 + "10 early() { i1 = sample(p1.individuals, 1000, replace=T); ids = i1.pedigreeID; i2 = sim.individualsWithPedigreeIDs(ids, 1); if (identical(i1, i2)) stop(); }", __LINE__);
// Test sim - (void)killIndividuals(object<Individual> individuals)
// this is also done in the test script killIndividuals_test.slim, in Miscellaneous
SLiMAssertScriptSuccess(nonWF_prefix + gen1_setup_p1_100 + "2:10 first() { p1.individuals.tag = 0; s = p1.sampleIndividuals(3); s.tag = 1; sim.killIndividuals(s); if (sum(p1.individuals.tag) != 0) stop(); }", __LINE__);
SLiMAssertScriptSuccess(nonWF_prefix + gen1_setup_p1_100 + "2:10 early() { p1.individuals.tag = 0; s = p1.sampleIndividuals(3); s.tag = 1; sim.killIndividuals(s); if (sum(p1.individuals.tag) != 0) stop(); }", __LINE__);
SLiMAssertScriptSuccess(nonWF_prefix + gen1_setup_p1_100 + "2:10 late() { p1.individuals.tag = 0; s = p1.sampleIndividuals(3); s.tag = 1; sim.killIndividuals(s); if (sum(p1.individuals.tag) != 0) stop(); }", __LINE__);
SLiMAssertScriptSuccess(nonWF_prefix + gen1_setup_sex_p1_100 + "2:10 first() { p1.individuals.tag = 0; s = p1.sampleIndividuals(3); s.tag = 1; sim.killIndividuals(s); if (sum(p1.individuals.tag) != 0) stop(); }", __LINE__);
SLiMAssertScriptSuccess(nonWF_prefix + gen1_setup_sex_p1_100 + "2:10 early() { p1.individuals.tag = 0; s = p1.sampleIndividuals(3); s.tag = 1; sim.killIndividuals(s); if (sum(p1.individuals.tag) != 0) stop(); }", __LINE__);
SLiMAssertScriptSuccess(nonWF_prefix + gen1_setup_sex_p1_100 + "2:10 late() { p1.individuals.tag = 0; s = p1.sampleIndividuals(3); s.tag = 1; sim.killIndividuals(s); if (sum(p1.individuals.tag) != 0) stop(); }", __LINE__);
// Test sim - (float)mutationFrequencies(Nio<Subpopulation> subpops, [object<Mutation> mutations])
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(p1); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(c(p1, p2)); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(NULL); }", __LINE__); // legal, requests population-wide frequencies
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(sim.subpopulations); }", __LINE__); // legal, requests population-wide frequencies
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(object()); }", __LINE__); // legal to specify an empty object vector
SLiMAssertScriptRaise(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(10); }", "p10 not defined", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(1); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(1:2); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(sim.subpopulations.id); }", __LINE__); // legal, requests population-wide frequencies
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationFrequencies(integer(0)); }", __LINE__); // legal to specify an empty integer vector
// Test sim - (integer)mutationCounts(Nio<Subpopulation> subpops, [object<Mutation> mutations])
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(p1); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(c(p1, p2)); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(NULL); }", __LINE__); // legal, requests population-wide frequencies
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(sim.subpopulations); }", __LINE__); // legal, requests population-wide frequencies
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(object()); }", __LINE__); // legal to specify an empty object vector
SLiMAssertScriptRaise(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(10); }", "p10 not defined", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(1); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(1:2); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(sim.subpopulations.id); }", __LINE__); // legal, requests population-wide frequencies
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 early() { sim.mutationCounts(integer(0)); }", __LINE__); // legal to specify an empty integer vector
// Test sim - (object<Mutation>)mutationsOfType(io<MutationType>$ mutType)
SLiMAssertScriptSuccess(gen1_setup_p1 + "10 early() { sim.mutationsOfType(m1); } ", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "10 early() { sim.mutationsOfType(1); } ", __LINE__);
// Test sim - (object<Mutation>)countOfMutationsOfType(io<MutationType>$ mutType)
SLiMAssertScriptSuccess(gen1_setup_p1 + "10 early() { sim.countOfMutationsOfType(m1); } ", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "10 early() { sim.countOfMutationsOfType(1); } ", __LINE__);
// Test sim - (void)outputFixedMutations(void)
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFixedMutations(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFixedMutations(NULL); }", __LINE__);
if (Eidos_TemporaryDirectoryExists())
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFixedMutations('" + temp_path + "/slimOutputFixedTest.txt'); }", __LINE__);
// Test sim - (void)outputFull([string$ filePath])
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(NULL); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(spatialPositions=T); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(spatialPositions=F); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(ages=T); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(ages=F); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 late() { sim.outputFull(spatialPositions=T); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 late() { sim.outputFull(spatialPositions=F); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 late() { sim.outputFull(ages=T); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 late() { sim.outputFull(ages=F); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1p2p3 + "1 late() { sim.outputFull(NULL, T); }", "cannot output in binary format", __LINE__);
if (Eidos_TemporaryDirectoryExists())
{
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull('" + temp_path + "/slimOutputFullTest.txt'); }", __LINE__); // legal, output to file path; this test might work only on Un*x systems
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { sim.outputFull('" + temp_path + "/slimOutputFullTest.slimbinary', T); }", __LINE__); // legal, output to file path; this test might work only on Un*x systems
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 late() { p1.individuals.x = runif(10); sim.outputFull('" + temp_path + "/slimOutputFullTest_POSITIONS.txt'); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 late() { p1.individuals.x = runif(10); sim.outputFull('" + temp_path + "/slimOutputFullTest_POSITIONS.slimbinary', T); }", __LINE__);
}
// Test sim - (void)outputMutations(object<Mutation> mutations)
SLiMAssertScriptSuccess(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(sim.mutations); }", __LINE__); // legal; should have some mutations by gen 5
SLiMAssertScriptSuccess(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(sim.mutations[0]); }", __LINE__); // legal; output just one mutation
SLiMAssertScriptSuccess(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(sim.mutations[integer(0)]); }", __LINE__); // legal to specify an empty object vector
SLiMAssertScriptSuccess(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(object()); }", __LINE__); // legal to specify an empty object vector
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(NULL); }", "cannot be type NULL", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(sim.mutations, NULL); }", __LINE__);
if (Eidos_TemporaryDirectoryExists())
SLiMAssertScriptSuccess(gen1_setup_highmut_p1 + "5 late() { sim.outputMutations(sim.mutations, '" + temp_path + "/slimOutputMutationsTest.txt'); }", __LINE__);
// Test sim - (void)readFromPopulationFile(string$ filePath)
if (Eidos_TemporaryDirectoryExists())
{
SLiMAssertScriptSuccess(gen1_setup + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest.txt'); }", __LINE__); // legal, read from file path; depends on the outputFull() test above
SLiMAssertScriptSuccess(gen1_setup + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest.slimbinary'); }", __LINE__); // legal, read from file path; depends on the outputFull() test above
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest_POSITIONS.txt'); }", "spatial dimensionality of this model", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest_POSITIONS.slimbinary'); }", "output spatial dimensionality does not match", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest_POSITIONS.txt'); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_i1x + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest_POSITIONS.slimbinary'); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup + "1 early() { sim.readFromPopulationFile('" + temp_path + "/notAFile.foo'); }", "does not exist or is empty", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest.txt'); if (size(sim.subpopulations) != 3) stop(); }", __LINE__); // legal; should wipe previous state
SLiMAssertScriptSuccess(gen1_setup_p1 + "1 early() { sim.readFromPopulationFile('" + temp_path + "/slimOutputFullTest.slimbinary'); if (size(sim.subpopulations) != 3) stop(); }", __LINE__); // legal; should wipe previous state
}
// Test sim - (object<SLiMEidosBlock>)registerFirstEvent(Nis$ id, string$ source, [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { community.registerFirstEvent(NULL, '{ stop(); }', 2, 2); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerFirstEvent('s1', '{ stop(); }', 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; community.registerFirstEvent('s1', '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; community.registerFirstEvent(1, '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerFirstEvent(1, '{ stop(); }', 2, 2); community.registerFirstEvent(1, '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerFirstEvent(1, '{ stop(); }', 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerFirstEvent(1, '{ stop(); }', -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerFirstEvent(1, '{ stop(); }', 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerFirstEvent(1, '{ $; }', 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim - (object<SLiMEidosBlock>)registerEarlyEvent(Nis$ id, string$ source, [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { community.registerEarlyEvent(NULL, '{ stop(); }', 2, 2); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerEarlyEvent('s1', '{ stop(); }', 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; community.registerEarlyEvent('s1', '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; community.registerEarlyEvent(1, '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerEarlyEvent(1, '{ stop(); }', 2, 2); community.registerEarlyEvent(1, '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerEarlyEvent(1, '{ stop(); }', 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerEarlyEvent(1, '{ stop(); }', -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerEarlyEvent(1, '{ stop(); }', 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerEarlyEvent(1, '{ $; }', 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim - (object<SLiMEidosBlock>)registerLateEvent(Nis$ id, string$ source, [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { community.registerLateEvent(NULL, '{ stop(); }', 2, 2); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerLateEvent('s1', '{ stop(); }', 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; community.registerLateEvent('s1', '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; community.registerLateEvent(1, '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerLateEvent(1, '{ stop(); }', 2, 2); community.registerLateEvent(1, '{ stop(); }', 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerLateEvent(1, '{ stop(); }', 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerLateEvent(1, '{ stop(); }', -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerLateEvent(1, '{ stop(); }', 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { community.registerLateEvent(1, '{ $; }', 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim - (object<SLiMEidosBlock>)registerFitnessEffectCallback(Nis$ id, string$ source, [Nio<Subpopulation>$ subpop], [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(NULL, '{ stop(); }', NULL, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(NULL, '{ stop(); }', p1, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(NULL, '{ stop(); }'); } 10 early() { ; }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback('s1', '{ stop(); }', NULL, 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { s1 = 7; sim.registerFitnessEffectCallback('s1', '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { s1 = 7; sim.registerFitnessEffectCallback(1, '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(1, '{ stop(); }', NULL, 2, 2); sim.registerFitnessEffectCallback(1, '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(1, '{ stop(); }', NULL, 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(1, '{ stop(); }', NULL, -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(1, '{ stop(); }', NULL, 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerFitnessEffectCallback(1, '{ $; }', NULL, 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim - (object<SLiMEidosBlock>)registerMutationEffectCallback(Nis$ id, string$ source, io<MutationType>$ mutType, [Nio<Subpopulation>$ subpop], [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }', 1, NULL, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }', m1, NULL, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }', 1, 1, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }', m1, p1, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }', 1); } 10 early() { ; }", __LINE__);
SLiMAssertScriptStop(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }', m1); } 10 early() { ; }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(NULL, '{ stop(); }'); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback('s1', '{ stop(); }', m1, NULL, 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { s1 = 7; sim.registerMutationEffectCallback('s1', '{ stop(); }', m1, NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { s1 = 7; sim.registerMutationEffectCallback(1, '{ stop(); }', m1, NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(1, '{ stop(); }', m1, NULL, 2, 2); sim.registerMutationEffectCallback(1, '{ stop(); }', m1, NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(1, '{ stop(); }', m1, NULL, 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(1, '{ stop(); }', m1, NULL, -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(1, '{ stop(); }', m1, NULL, 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_highmut_p1 + "1 early() { sim.registerMutationEffectCallback(1, '{ $; }', m1, NULL, 2, 2); }", "unexpected token '$'", __LINE__);
// Test community - (object<SLiMEidosBlock>)registerInteractionCallback(Nis$ id, string$ source, io<InteractionType>$ intType, [Nio<Subpopulation>$ subpop], [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }', 1, NULL, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }', i1, NULL, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }', 1, 1, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }', i1, p1, 5, 10); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }', 1); } 10 early() { ; }", __LINE__);
SLiMAssertScriptStop(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }', i1); } 10 early() { ; }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(NULL, '{ stop(); }'); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback('s1', '{ stop(); }', i1, NULL, 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { s1 = 7; community.registerInteractionCallback('s1', '{ stop(); }', i1, NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { s1 = 7; community.registerInteractionCallback(1, '{ stop(); }', i1, NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(1, '{ stop(); }', i1, NULL, 2, 2); community.registerInteractionCallback(1, '{ stop(); }', i1, NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(1, '{ stop(); }', i1, NULL, 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(1, '{ stop(); }', i1, NULL, -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(1, '{ stop(); }', i1, NULL, 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_i1 + "late() { i1.evaluate(p1); i1.strength(p1.individuals[0]); } 1 early() { community.registerInteractionCallback(1, '{ $; }', i1, NULL, 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim - (object<SLiMEidosBlock>)registerMateChoiceCallback(Nis$ id, string$ source, [Nio<Subpopulation>$ subpop], [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL, '{ stop(); }', NULL, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL, '{ stop(); }', NULL, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL, '{ stop(); }', 1, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL, '{ stop(); }', p1, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL, '{ stop(); }'); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL, '{ stop(); }'); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(NULL); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback('s1', '{ stop(); }', NULL, 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; sim.registerMateChoiceCallback('s1', '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; sim.registerMateChoiceCallback(1, '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(1, '{ stop(); }', NULL, 2, 2); sim.registerMateChoiceCallback(1, '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(1, '{ stop(); }', NULL, 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(1, '{ stop(); }', NULL, -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(1, '{ stop(); }', NULL, 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerMateChoiceCallback(1, '{ $; }', NULL, 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim - (object<SLiMEidosBlock>)registerModifyChildCallback(Nis$ id, string$ source, [Nio<Subpopulation>$ subpop], [integer$ start], [integer$ end])
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL, '{ stop(); }', NULL, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL, '{ stop(); }', NULL, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL, '{ stop(); }', 1, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL, '{ stop(); }', p1, 2, 2); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL, '{ stop(); }'); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL, '{ stop(); }'); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(NULL); }", "missing required argument", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback('s1', '{ stop(); }', NULL, 2, 2); } s1 early() { }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; sim.registerModifyChildCallback('s1', '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { s1 = 7; sim.registerModifyChildCallback(1, '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(1, '{ stop(); }', NULL, 2, 2); sim.registerModifyChildCallback(1, '{ stop(); }', NULL, 2, 2); }", "already defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(1, '{ stop(); }', NULL, 3, 2); }", "requires start <= end", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(1, '{ stop(); }', NULL, -1, -1); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(1, '{ stop(); }', NULL, 0, 0); }", "out of range", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { sim.registerModifyChildCallback(1, '{ $; }', NULL, 2, 2); }", "unexpected token '$'", __LINE__);
// Test sim – (object<SLiMEidosBlock>)rescheduleScriptBlock(io<SLiMEidosBlock>$ block, [Ni$ start = NULL], [Ni$ end = NULL], [Ni ticks = NULL])
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=10, end=9); stop(); } s1 10 early() { }", "requires start <= end", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, ticks=integer(0)); stop(); } s1 10 early() { }", __LINE__); // this is now legal
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, ticks=c(25, 25)); stop(); } s1 10 early() { }", "same tick cannot be used twice", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=25, end=25, ticks=25); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=25, end=NULL, ticks=25); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=NULL, end=25, ticks=25); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=25, end=25); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25)) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=25, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25:29)) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=NULL, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "for the currently executing", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "for the currently executing", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { b = community.rescheduleScriptBlock(s1, start=NULL, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "scheduled for a past tick", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { b = community.rescheduleScriptBlock(s1, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "scheduled for a past tick", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=25, end=NULL); if (b.start == 25 & b.end == 1000000001) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, start=25); if (b.start == 25 & b.end == 1000000001) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, ticks=25); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25)) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, ticks=25:28); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25:28)) stop(); } s1 10 early() { }", __LINE__);
// these would use a `ticks` property now to check the scheduling, if that property existed; you'd also have sort-order issues though, would need to check the sorted order
//SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, ticks=c(25:28, 35)); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, c(25:28, 35))) stop(); } s1 10 early() { }", __LINE__);
//SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(s1, ticks=c(13, 25:28)); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, c(13, 25:28))) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(2, start=10, end=9); stop(); } s1 10 early() { }", "s2 not defined", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=10, end=9); stop(); } s1 10 early() { }", "requires start <= end", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, ticks=integer(0)); stop(); } s1 10 early() { }", __LINE__); // this is now legal
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, ticks=c(25, 25)); stop(); } s1 10 early() { }", "same tick cannot be used twice", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=25, end=25, ticks=25); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=25, end=NULL, ticks=25); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=NULL, end=25, ticks=25); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1); stop(); } s1 10 early() { }", "either start/end or ticks", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=25, end=25); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25)) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=25, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25:29)) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=NULL, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "for the currently executing", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "for the currently executing", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { b = community.rescheduleScriptBlock(1, start=NULL, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "scheduled for a past tick", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "2 early() { b = community.rescheduleScriptBlock(1, end=29); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 1:29)) stop(); } s1 10 early() { }", "scheduled for a past tick", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=25, end=NULL); if (b.start == 25 & b.end == 1000000001) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, start=25); if (b.start == 25 & b.end == 1000000001) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, ticks=25); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25)) stop(); } s1 10 early() { }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, ticks=25:28); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, 25:28)) stop(); } s1 10 early() { }", __LINE__);
// these would use a `ticks` property now to check the scheduling, if that property existed; you'd also have sort-order issues though, would need to check the sorted order
//SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, ticks=c(25:28, 35)); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, c(25:28, 35))) stop(); } s1 10 early() { }", __LINE__);
//SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { b = community.rescheduleScriptBlock(1, ticks=c(13, 25:28)); r = sapply(b, 'applyValue.start:applyValue.end;'); if (identical(r, c(13, 25:28))) stop(); } s1 10 early() { }", __LINE__);
// Test Community - (object<LogFile>$)createLogFile(string$ filePath, [Ns initialContents = NULL], [logical$ append = F], [logical$ compress = F], [string$ sep = ","], [Ni$ logInterval = NULL], [Ni$ flushInterval = NULL])
if (Eidos_TemporaryDirectoryExists())
SLiMAssertScriptSuccess(gen1_setup_p1p2p3 + "1 late() { path = '" + temp_path + "/slimLogFileTest.txt'; log = community.createLogFile(path, initialContents='# HEADER COMMENT', logInterval=1); log.addTick(); log.addCycle(); log.addSubpopulationSize(p1); } 10 late() { }", __LINE__);
// Test Community - (void)simulationFinished(void)
SLiMAssertScriptStop(gen1_setup_p1 + "11 early() { stop(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "10 early() { community.simulationFinished(); } 11 early() { stop(); }", __LINE__);
SLiMAssertScriptSuccess(gen1_setup_p1 + "10 early() { sim.simulationFinished(); } 11 early() { stop(); }", __LINE__);
// Test sim - (object<Mutation>)subsetMutations([No<Mutation>$ exclude = NULL], [Nio<MutationType>$ mutationType = NULL], [Ni$ position = NULL], [Nis$ nucleotide = NULL], [Ni$ tag = NULL], [Ni$ id = NULL])
// unusually, we do this with custom SLiM scripts that check the API stochastically, since it would be difficult
// to test all the possible parameter combinations otherwise; we do a non-nucleotide test and a nucleotide test
SLiMAssertScriptSuccess(R"V0G0N(
initialize() {
initializeMutationRate(1e-2);
initializeMutationType('m1', 0.5, 'f', 0.0);
initializeMutationType('m2', 0.5, 'f', 0.0);
initializeGenomicElementType('g1', c(m1,m2), c(1,1));
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-8);
m2.color="red";
}
1 early() { sim.addSubpop('p1', 10); }
50 early() {
m=sim.mutations;
m.tag=rdunif(m.size(), max=5);
for (i in 1:10000) {
ex=(runif(1)<0.8) ? NULL else sample(m,1);
mt=(runif(1)<0.8) ? NULL else ((runif(1) < 0.5) ? m1 else m2);
pos=(runif(1)<0.8) ? NULL else rdunif(1, max=99);
tag=(runif(1)<0.8) ? NULL else rdunif(1, max=5);
id=(runif(1)<0.8) ? NULL else sample(m.id, 1);
method1=sim.subsetMutations(exclude=ex, mutType=mt, position=pos,
tag=tag, id=id);
method2=m;
if (!isNULL(ex)) method2=method2[method2!=ex];
if (!isNULL(mt)) method2=method2[method2.mutationType==mt];
if (!isNULL(pos)) method2=method2[method2.position==pos];
if (!isNULL(tag)) method2=method2[method2.tag==tag];
if (!isNULL(id)) method2=method2[method2.id==id];
if (!identical(method1,method2)) stop();
}
}
)V0G0N", __LINE__);
SLiMAssertScriptSuccess(R"V0G0N(
initialize() {
initializeSLiMOptions(nucleotideBased=T);
initializeAncestralNucleotides(randomNucleotides(100));
initializeMutationTypeNuc('m1', 0.5, 'f', 0.0);
initializeMutationTypeNuc('m2', 0.5, 'f', 0.0);
initializeGenomicElementType('g1', c(m1,m2), c(1,1), mmJukesCantor(1e-2 / 3));
initializeGenomicElement(g1, 0, 99);
initializeRecombinationRate(1e-8);
m2.color="red";
}
1 early() { sim.addSubpop('p1', 10); }
50 early() {
m=sim.mutations;
m.tag=rdunif(m.size(), max=5);
for (i in 1:10000) {
ex=(runif(1)<0.8) ? NULL else sample(m,1);
mt=(runif(1)<0.8) ? NULL else ((runif(1) < 0.5) ? m1 else m2);
pos=(runif(1)<0.8) ? NULL else rdunif(1, max=99);
nuc=(runif(1)<0.8) ? NULL else rdunif(1, max=3);
tag=(runif(1)<0.8) ? NULL else rdunif(1, max=5);
id=(runif(1)<0.8) ? NULL else sample(m.id, 1);
method1=sim.subsetMutations(exclude=ex, mutType=mt, position=pos,
nucleotide=nuc, tag=tag, id=id);
method2=m;
if (!isNULL(ex)) method2=method2[method2!=ex];
if (!isNULL(mt)) method2=method2[method2.mutationType==mt];
if (!isNULL(pos)) method2=method2[method2.position==pos];
if (!isNULL(nuc)) method2=method2[method2.nucleotideValue==nuc];
if (!isNULL(tag)) method2=method2[method2.tag==tag];
if (!isNULL(id)) method2=method2[method2.id==id];
if (!identical(method1,method2)) stop();
}
}
)V0G0N", __LINE__);
// Test sim EidosDictionaryUnretained functionality: - (+)getValue(is$ key) and - (void)setValue(is$ key, + value)
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.setValue('foo', 7:9); sim.setValue('bar', 'baz'); } 10 early() { if (identical(sim.getValue('foo'), 7:9) & identical(sim.getValue('bar'), 'baz')) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.setValue('foo', 3:5); sim.setValue('foo', 'foobar'); } 10 early() { if (identical(sim.getValue('foo'), 'foobar')) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { sim.setValue('foo', 3:5); sim.setValue('foo', NULL); } 10 early() { if (isNULL(sim.getValue('foo'))) stop(); }", __LINE__);
// Test mutation frequency/counts by cross-checking different methods against each other
// this is a shortened version of SLiM_project/Miscellaneous/Testing/test_multichrom_freqs_counts.slim
// it is best when run under DEBUG, since then SLiM's self-check code is also involved
SLiMAssertScriptSuccess(R"V0G0N(
initialize() {
initializeSex();
initializeMutationType("m1", 0.5, "f", 0.0);
initializeMutationType("m2", 0.5, "f", 0.1);
initializeMutationType("m3", 0.5, "f", -0.01);
initializeGenomicElementType("g1", c(m1,m2,m3), c(100, 1, 10));
ids = 1:11;
lengths = c(2e4, rep(1e4, 10));
types = c("A", "A", "H", "X", "Y", "W", "Z", "HF", "FL", "HM", "ML");
for (id in ids, length in lengths, type in types)
{
initializeChromosome(id, length);
initializeMutationRate(1e-4);
initializeGenomicElement(g1, 0, length - 1);
initializeRecombinationRate(1e-4);
}
}
1 early() {
sim.addSubpop("p1", 10);
sim.addSubpop("p2", 10);
p1.setMigrationRates(p2, 0.001);
p2.setMigrationRates(p1, 0.01);
}
85 early() {
p1.setSubpopulationSize(30);
p2.setSubpopulationSize(30);
}
90:100 late() {
p1_haplosomes = p1.haplosomes;
p2_haplosomes = p2.haplosomes;
all_haplosomes = c(p1_haplosomes, p2_haplosomes);
haplosome_subsample = sample(all_haplosomes, integerDiv(size(all_haplosomes), 4));
all_muts = sim.mutations;
sampled_muts = sample(sim.mutations, integerDiv(size(sim.mutations), 2));
// check mutation counts first
for (iter in 1:2)
{
muts_checked = ((iter == 1) ? NULL else sampled_muts);
counts_hapsample_1 = haplosome_subsample.mutationCountsInHaplosomes(muts_checked);
counts_p1_haplosomes = p1_haplosomes.mutationCountsInHaplosomes(muts_checked);
counts_p1_subpop = sim.mutationCounts(p1, muts_checked);
if (!identical(counts_p1_haplosomes, counts_p1_subpop))
stop("iter == " + iter);
counts_hapsample_2 = haplosome_subsample.mutationCountsInHaplosomes(muts_checked);
if (!identical(counts_hapsample_1, counts_hapsample_2))
stop("iter == " + iter);
counts_p2_haplosomes = p2_haplosomes.mutationCountsInHaplosomes(muts_checked);
counts_p2_subpop = sim.mutationCounts(p2, muts_checked);
if (!identical(counts_p2_haplosomes, counts_p2_subpop))
stop("iter == " + iter);
counts_p1p1_haplosomes = c(p1_haplosomes, p2_haplosomes).mutationCountsInHaplosomes(muts_checked);
counts_p1p2_subpop = sim.mutationCounts(c(p1, p2), muts_checked);
counts_pop = sim.mutationCounts(NULL, muts_checked);
if (!identical(counts_p1p1_haplosomes, counts_p1p2_subpop))
stop("iter == " + iter);
if (!identical(counts_pop, counts_p1p2_subpop))
stop("iter == " + iter);
if (!identical(counts_p1_haplosomes + counts_p2_haplosomes, counts_p1p2_subpop))
stop("iter == " + iter);
counts_hapsample_3 = haplosome_subsample.mutationCountsInHaplosomes(muts_checked);
if (!identical(counts_hapsample_1, counts_hapsample_3))
stop("iter == " + iter);
}
// check mutation frequencies second
for (iter in 1:2)
{
muts_checked = ((iter == 1) ? NULL else sampled_muts);
freqs_hapsample_1 = haplosome_subsample.mutationFrequenciesInHaplosomes(muts_checked);
freqs_p1_haplosomes = p1_haplosomes.mutationFrequenciesInHaplosomes(muts_checked);
freqs_p1_subpop = sim.mutationFrequencies(p1, muts_checked);
if (!identical(freqs_p1_haplosomes, freqs_p1_subpop))
stop("iter == " + iter);
freqs_hapsample_2 = haplosome_subsample.mutationFrequenciesInHaplosomes(muts_checked);
if (!identical(freqs_hapsample_1, freqs_hapsample_2))
stop("iter == " + iter);
freqs_p2_haplosomes = p2_haplosomes.mutationFrequenciesInHaplosomes(muts_checked);
freqs_p2_subpop = sim.mutationFrequencies(p2, muts_checked);
if (!identical(freqs_p2_haplosomes, freqs_p2_subpop))
stop("iter == " + iter);
freqs_p1p1_haplosomes = c(p1_haplosomes, p2_haplosomes).mutationFrequenciesInHaplosomes(muts_checked);
freqs_p1p2_subpop = sim.mutationFrequencies(c(p1, p2), muts_checked);
freqs_pop = sim.mutationFrequencies(NULL, muts_checked);
if (!identical(freqs_p1p1_haplosomes, freqs_p1p2_subpop))
stop("iter == " + iter);
if (!identical(freqs_pop, freqs_p1p2_subpop))
stop("iter == " + iter);
freqs_hapsample_3 = haplosome_subsample.mutationFrequenciesInHaplosomes(muts_checked);
if (!identical(freqs_hapsample_1, freqs_hapsample_3))
stop("iter == " + iter);
}
}
)V0G0N", __LINE__);
}
#pragma mark Subpopulation tests
void _RunSubpopulationTests(void)
{
// ************************************************************************************
//
// Gen 1+ tests: Subpopulation
//
// Test Subpopulation properties
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.cloningRate == 0.0) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.firstMaleIndex == p1.firstMaleIndex) stop(); }", __LINE__); // legal but undefined value in non-sexual sims
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (size(p1.haplosomes) == 20) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (size(p1.haplosomesNonNull) == 20) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (size(p1.individuals) == 10) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.id == 1) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (identical(p1.immigrantSubpopFractions, float(0))) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (identical(p1.immigrantSubpopIDs, integer(0))) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.selfingRate == 0.0) stop(); }", __LINE__); // legal but always 0.0 in non-sexual sims
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.sexRatio == 0.0) stop(); }", __LINE__); // legal but always 0.0 in non-sexual sims
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (identical(p1.species, sim)) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.individualCount == 10) stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.tag; }", "before being set", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { c(p1,p1).tag; }", "before being set", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.tag = 135; if (p1.tag == 135) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.fitnessScaling = 135.0; if (p1.fitnessScaling == 135.0) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.fitnessScaling = 0.0; if (p1.fitnessScaling == 0.0) stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.fitnessScaling = -0.01; }", "must be >= 0.0", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.fitnessScaling = NAN; }", "must be >= 0.0", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.name == 'p1') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.name = 'p1'; if (p1.name == 'p1') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.name = 'foo'; if (p1.name == 'foo') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.name = 'foo'; p1.name = 'bar'; if (p1.name == 'bar') stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.name = 'p2'; }", "subpopulation symbol", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.name = 'foo'; p1.name = 'bar'; p1.name = 'foo'; }", "must be unique", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { if (p1.description == '') stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_p1 + "1 early() { p1.description = 'this is groovy'; if (p1.description == 'this is groovy') stop(); }", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.cloningRate = 0.0; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.firstMaleIndex = p1.firstMaleIndex; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.haplosomes = p1.haplosomes[0]; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.haplosomesNonNull = p1.haplosomesNonNull[0]; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.individuals = p1.individuals[0]; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.id = 1; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.immigrantSubpopFractions = 1.0; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.immigrantSubpopIDs = 1; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.selfingRate = 0.0; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.sexRatio = 0.5; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.species = sim; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptRaise(gen1_setup_p1 + "1 early() { p1.individualCount = 10; stop(); }", "read-only property", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (identical(p1.cloningRate, c(0.0,0.0))) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (p1.firstMaleIndex == 5) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (size(p1.haplosomes) == 20) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (size(p1.haplosomesNonNull) == 15) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (size(p1.individuals) == 10) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (p1.id == 1) stop(); }", __LINE__);
SLiMAssertScriptStop(gen1_setup_sex_p1 + "1 early() { if (identical(p1.immigrantSubpopFractions, float(0))) stop(); }", __LINE__);