File: coll.tst

package info (click to toggle)
gap 4r10p0-7
  • links: PTS
  • area: main
  • in suites: buster
  • size: 47,392 kB
  • sloc: ansic: 118,475; xml: 54,089; sh: 4,112; perl: 1,654; makefile: 274
file content (672 lines) | stat: -rw-r--r-- 14,813 bytes parent folder | download
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
#############################################################################
##
#W  coll.tst
##
##  Test operations defined in coll.gd
##
gap> START_TEST("coll.tst");
gap> if not IsBound(TestConsistencyOfEnumeratorByFunctions) then
>   ReadGapRoot( "tst/testenumerator.g" );
> fi;

#
# some collections that are not lists
#
gap> F:=FreeGroup(2);;
gap> c1:=ConjugacyClass(F, One(F));;
gap> IsList(c1); IsCollection(c1);
false
true
gap> c2:=ConjugacyClass(F, F.1);;
gap> IsList(c2); IsCollection(c2);
false
true

#############################################################################
#
# IsEmpty
# IsTrivial
# IsNonTrivial
# IsFinite
#
gap> props := [IsEmpty, IsTrivial, IsNonTrivial, IsFinite];;

# ... immediate methods for a collection which knows its size,
# applied to empty collection
gap> M0:=Magma(FamilyObj([1]), []);;
gap> ForAll(props, prop -> not Tester(prop)(M0));
true
gap> Size(M0);
0
gap> ForAll(props, prop -> Tester(prop)(M0));
true
gap> List(props, p -> p(M0));
[ true, false, true, true ]

# ... immediate methods for a collection which knows its size,
# applied to trivial (= size 1) collection
gap> N1:=Magma([[[1,0],[0,0]]]);;
gap> ForAll(props, prop -> not Tester(prop)(N1));
true

#gap> Size(N1);
#1
#gap> ForAll(props, prop -> Tester(prop)(N1));
#true
#gap> List(props, p -> p(N1));
#[ false, true, false, true ]

# ... immediate methods for a collection which knows its size,
# applied to collection with size greater than 1
gap> M2:=Magma(0, 1);;
gap> ForAll(props, prop -> not Tester(prop)(M2));
true
gap> Size(M2);
2
gap> ForAll(props, prop -> Tester(prop)(M2));
true
gap> List(props, p -> p(M2));
[ false, false, true, true ]

# ... for a collection which does not know its size
gap> List(props, p -> p(Magma(FamilyObj([1]), [])));
[ true, false, true, true ]
gap> List(props, p -> p(Magma(1)));
[ false, true, false, true ]
gap> List(props, p -> p(Magma(0, 1)));
[ false, false, true, true ]

# for a list
gap> IsEmpty([]);
true
gap> IsFinite([]);
true
gap> List(props, p -> p([1]));
[ false, true, false, true ]
gap> List(props, p -> p([0,1]));
[ false, false, true, true ]

#############################################################################
#
# IsWholeFamily
#
gap> IsWholeFamily([1]);
Error, cannot test whether <C> contains the family of its elements

#############################################################################
#
# Size
#

## method for collections knowing they are infinite
gap> c2:=ConjugacyClass(F, F.1);;
gap> HasSize(c2);
false
gap> SetIsFinite(c2, false);
gap> Size(c2);
infinity

# immediate method for collections with HasAsList
gap> M2:=Magma(0, 1);;
gap> HasSize(M2);
false
gap> SetAsList(M2, [0,1]);
gap> HasSize(M2);
true
gap> Size(M2);
2

# method for collections, by computing length of enumerator
gap> M2:=Magma(0, 1);;
gap> Size(M2);
2

#############################################################################
#
# Representative
#
gap> M1 := Magma(1);;
gap> Representative([1]);
1
gap> Representative(M1);
1
gap> Representative([]);
Error, <list> must be nonempty to have a representative

#############################################################################
#
# RepresentativeSmallest
#
# ... for an (empty) collection
gap> M0:=Magma(FamilyObj([1]), []);;

# first go through the generic collection method, and trigger the error there
gap> RepresentativeSmallest(M0);
Error, <C> must be nonempty to have a representative

# now AsSSortedList(M0) is set, so calling RepresentativeSmallest again
# goes through another method which tests HasAsSSortedList
gap> RepresentativeSmallest(M0);
Error, <C> must be nonempty to have a representative

# recreate M0 with EnumeratorSorted set but not AsSSortedList
# to trigger a third method
gap> M0:=Magma(FamilyObj([1]), []);;
gap> SetEnumeratorSorted(M0, []);
gap> RepresentativeSmallest(M0);
Error, <C> must be nonempty to have a representative

#############################################################################
#
# Random
# RandomList
# PseudoRandom
#
# TODO

#############################################################################
#
# Enumerator
#
gap> Enumerator(c1);
[ <identity ...> ]
gap> Enumerator(M0);
[  ]
gap> enum := Enumerator(M2);;
gap> TestConsistencyOfEnumeratorByFunctions(enum);
true
gap> Size(enum);
2

#############################################################################
#
# EnumeratorSorted
#
gap> EnumeratorSorted(M0);
[  ]
gap> EnumeratorSorted(M2);
[ 0, 1 ]

#############################################################################
#
# EnumeratorOfSubset
#
gap> EnumeratorOfSubset();
Error, usage: EnumeratorOfSubset( <list>, <blist>[, <ishomog>] )
gap> enum:=EnumeratorOfSubset([1,2,Z(3)], [true,false,true]);
Error, missing third argument <ishomog> for inhomog. <list>

#
gap> enum:=EnumeratorOfSubset([1,2,3], [true,false,true]);
<enumerator>
gap> TestConsistencyOfEnumeratorByFunctions(enum);
true
gap> AsList(enum);
[ 1, 3 ]

# 
gap> enum:=EnumeratorOfSubset([1,Z(2),3], [true,false,true], true);
<enumerator>
gap> TestConsistencyOfEnumeratorByFunctions(enum);
true
gap> AsList(enum);
[ 1, 3 ]

# 
gap> enum:=EnumeratorOfSubset([1,2,Z(3)], [true,false,true], false);
<enumerator>
gap> TestConsistencyOfEnumeratorByFunctions(enum);
true
gap> AsList(enum);
[ 1, Z(3) ]

#############################################################################
#
# EnumeratorByFunctions
#
# Since most other non-list enumerators in GAP are implemented using
# EnumeratorByFunctions, there is no strong need to test it explicitly
# by constructing yet another type of enum. It might still be useful to
# do so at some point, to specifically test some of the more exotic or
# undocumented aspects, but for now we don't do it.
#
gap> EnumeratorByFunctions(1,1);
Error, <record> must be a record with components `ElementNumber'
and `NumberElement'

#
gap> enum:=Enumerator(Magma(0));
<enumerator of <commutative semigroup with 1 generator>>
gap> IsEnumeratorByFunctions(enum);
true
gap> Print(enum, "\n");
<enumerator of Semigroup( [ 0 ] )>

#############################################################################
#
# Iterator
#
gap> iter:=Iterator(M1);
<iterator>
gap> List(iter);
[ 1 ]

#
gap> iter:=Iterator([2,1]);
<iterator>
gap> List(iter);
[ 2, 1 ]

#############################################################################
#
# IteratorSorted
#
gap> iter:=IteratorSorted(M1);
<iterator>
gap> List(iter);
[ 1 ]

#
gap> iter:=IteratorSorted([2,1]);
<iterator>
gap> List(iter);
[ 1, 2 ]

#############################################################################
#
# IteratorByFunctions
#
gap> IteratorByFunctions(1);
Error, <record> must be a record with components `NextIterator',
`IsDoneIterator', and `ShallowCopy'

#############################################################################
#
# ConcatenationIterators
#
gap> iter:=ConcatenationIterators([Iterator(M1), Iterator(M0), Iterator([2,3])]);
<iterator>
gap> List(iter);
[ 1, 2, 3 ]

#############################################################################
#
# TrivialIterator
#
gap> iter:=TrivialIterator(42);
<iterator>
gap> List(iter);
[ 42 ]

#############################################################################
#
# List
# SortedList
# SSortedList = Set
#
# These functions are already being tested extensively via calls from
# elsewhere, so we don't bother to add further explicit tests.

#############################################################################
#
# AsList
# AsSortedList
# AsSSortedList = AsSet
#
gap> res:=List([AsList,AsSortedList,AsSet], f -> f(Magma(FamilyObj([1]), [])));
[ [  ], [  ], [  ] ]
gap> List(res,IsMutable);
[ false, false, false ]
gap> res:=List([AsList,AsSortedList,AsSet], f -> f(Magma(1)));
[ [ 1 ], [ 1 ], [ 1 ] ]
gap> List(res,IsMutable);
[ false, false, false ]

#############################################################################
#
# Sum
#
gap> Sum();
Error, usage: Sum( <C>[, <func>][, <init>] )

# for plain lists
gap> Sum([0,1]);
1
gap> Sum([0,1], x->x+1);
3
gap> Sum([0,1], 4);
5
gap> Sum([0,1], x->x+1, 4);
7

# for other collections
gap> Sum(M0);
0
gap> Sum(M0, x->x+1);
0
gap> Sum(M2);
1
gap> Sum(M2, x->x+1);
3
gap> Sum(M2, 4);
5
gap> Sum(M2, x->x+1, 4);
7

# input validation
gap> Sum();
Error, usage: Sum( <C>[, <func>][, <init>] )
gap> Sum([0,1], 4, x->x+1);
Error, usage: Sum( <C>[, <func>][, <init>] )

#############################################################################
#
# Product
#

# for plain lists
gap> Product([0,1]);
0
gap> Product([0,1], x->x+1);
2
gap> Product([0,1], 4);
0
gap> Product([0,1], x->x+1, 4);
8

# for other collections
gap> Product(M0);
1
gap> Product(M0, x->x+1);
1
gap> Product(M2);
0
gap> Product(M2, x->x+1);
2
gap> Product(M2, 4);
0
gap> Product(M2, x->x+1, 4);
8

# input validation
gap> Product();
Error, usage: Product( <C>[, <func>][, <init>] )
gap> Product([0,1], 4, x->x+1);
Error, usage: Product( <C>[, <func>][, <init>] )

#############################################################################
#
# Filtered
#
gap> Filtered([1,2,3],x->x>1);
[ 2, 3 ]
gap> FilteredOp([1,,3],x->x>1);
[ 3 ]

#
gap> v:=ImmutableVector(GF(5),[Z(5)^0,Z(5)^2]);;
gap> Filtered(v, IsOne);
[ Z(5)^0 ]
gap> Filtered(M0, ReturnTrue);
[  ]
gap> Filtered(M1, ReturnTrue);
[ 1 ]
gap> Filtered(M2, ReturnTrue);
[ 0, 1 ]

#############################################################################
#
# Number
#
gap> Number([1,2,3]);
3
gap> Number([1,2,3],x->x>1);
2
gap> NumberOp([1,,3]);
2
gap> NumberOp([1,,3],x->x>1);
1

#
gap> v:=ImmutableVector(GF(5),[Z(5)^0,Z(5)^2]);;
gap> Number(v);
2
gap> Number(v, IsOne);
1
gap> Number(M0);
0
gap> Number(M1);
1
gap> Number(M2);
2

# input validation
gap> Number();
Error, usage: Number( <C>[, <func>] )

#############################################################################
#
# ForAll
# ForAny
#
gap> ForAll([], ReturnTrue);
true
gap> ForAll([], ReturnFalse);
true
gap> ForAll([1], ReturnTrue);
true
gap> ForAll([1], ReturnFalse);
false

#
gap> ForAny([], ReturnTrue);
false
gap> ForAny([], ReturnFalse);
false
gap> ForAny([1], ReturnTrue);
true
gap> ForAny([1], ReturnFalse);
false

# test non-dense argument of the operation (bypassing the special case
# for all plists in the ForAll and ForAny functions)
gap> ForAllOp([1,,3], ReturnTrue);
true
gap> ForAllOp([1,,3], ReturnFalse);
false
gap> ForAnyOp([1,,3], ReturnTrue);
true
gap> ForAnyOp([1,,3], ReturnFalse);
false

#############################################################################
#
# ListX
# SetX
# SumX
# ProductX
#
gap> ListX([1..3], [1..3], {a,b}->[a,b]);
[ [ 1, 1 ], [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 2, 2 ], [ 2, 3 ], [ 3, 1 ], 
  [ 3, 2 ], [ 3, 3 ] ]
gap> ListX([1..3], n -> [1..n], {a,b}->[a,b]);
[ [ 1, 1 ], [ 2, 1 ], [ 2, 2 ], [ 3, 1 ], [ 3, 2 ], [ 3, 3 ] ]
gap> ListX([1..3], [1..3], \<, {a,b}->[a,b]);
[ [ 1, 2 ], [ 1, 3 ], [ 2, 3 ] ]

#
gap> args:=[ [1..3], [1..3], \+ ];;
gap> CallFuncList(SetX, args) = Set(CallFuncList(ListX, args));
true
gap> CallFuncList(SumX, args) = Sum(CallFuncList(ListX, args));
true
gap> CallFuncList(ProductX, args) = Product(CallFuncList(ListX, args));
true

#
gap> args:=[ [1..3], [1..3], \<, \+ ];;
gap> CallFuncList(SetX, args) = Set(CallFuncList(ListX, args));
true
gap> CallFuncList(SumX, args) = Sum(CallFuncList(ListX, args));
true
gap> CallFuncList(ProductX, args) = Product(CallFuncList(ListX, args));
true

#
gap> args:=[ [1..3], n -> [1..n], \+ ];;
gap> CallFuncList(SetX, args) = Set(CallFuncList(ListX, args));
true
gap> CallFuncList(SumX, args) = Sum(CallFuncList(ListX, args));
true
gap> CallFuncList(ProductX, args) = Product(CallFuncList(ListX, args));
true

#############################################################################
#
# Perform
#
gap> Perform([1,2,3], Display);
1
2
3

#############################################################################
#
# IsSubset
#
# TODO

#############################################################################
#
# Intersection
# Intersection2
#
gap> Intersection([]);
[  ]
gap> Intersection([1]);
Error, Intersection: arguments must be lists or collections

# for two lists (not necessarily in the same family)
gap> Intersection2([0,1], [0,Z(2)]);
[ 0 ]

# for two lists or collections, the second being empty
gap> Intersection2([1], []);
[  ]

# for two lists or collections, the first being empty
gap> Intersection2([], [1]);
[  ]

# for two collections in the same family, both lists
gap> Intersection2([0], [0,1]);
[ 0 ]
gap> Intersection2([0,1], [0]);
[ 0 ]

# for two collections in different families
gap> Intersection2(Rationals, GF(2));
[  ]

# for two collections in the same family, the second being a list
gap> Intersection2(M2, [0,1]);
[ 0, 1 ]
gap> Intersection2(Rationals, [0,1]);
[ 0, 1 ]

# for two collections in the same family, the first being a list
gap> Intersection2([0,1], M2);
[ 0, 1 ]
gap> Intersection2([0,1], Rationals);
[ 0, 1 ]

# for two collections in the same family
gap> Intersection2(M2, M2) = M2;
true
gap> Intersection2(M2, Rationals) = M2;
true
gap> Intersection2(Rationals, M2) = M2;
true

# test some formerly buggy cases
gap> Intersection([ -1 .. 1 ], [ -1 .. 1 ]); # previously was empty
[ -1 .. 1 ]
gap> Intersection([ 2, 4 .. 10 ], [ 3 .. 5 ]); # previously was [ 4, 6 ]
[ 4 ]
gap> Intersection([1..3], [4..5], [6,7]);
[  ]

#############################################################################
#
# Union
# Union2
#
# see union.tst

# for two collections that are lists
gap> Union2([0,1], [0,Z(2)]);
[ 0, 1, Z(2)^0 ]

# for two lists
gap> Union2([0,1], [0]);
[ 0, 1 ]
gap> Union2([0], [0,1]);
[ 0, 1 ]

# for two collections, the second being a list
gap> Union2(M1, [0,1]);
[ 0, 1 ]
gap> Union2(c1, AsList(c1)) = c1;
true

# for two collections, the first being a list
gap> Union2([0,1], M1);
[ 0, 1 ]
gap> Union2(AsList(c1), c1) = c1;
true

# for two collections
gap> Union2(M1, M2);
[ 0, 1 ]

#############################################################################
#
# Difference
#
gap> Difference([], M1);
[  ]
gap> Difference(M1, []) = M1;
true
gap> Difference([1,2],[1,Z(2)]);
[ 2 ]
gap> Difference([1,2],[1,3]);
[ 2 ]

# for two collections in different families
gap> Difference(M1, c2) = M1;
true

# for two collections in the same family
gap> Difference(M2, M1);
[ 0 ]

# FIXME/TODO: the following test is for now disabled, as it fails when
# the ResClasses package is loaded, which installs a buggy method
#gap> Difference(M2, Rationals);
#[  ]
# The following test only terminates if the FGA package is loaded
gap> not IsPackageMarkedForLoading("fga","") or Difference(c1, c2) = c1;
true

# for two collections, the first being a list
gap> Difference([0,1], M1);
[ 0 ]
gap> Difference([0,1], Rationals);
[  ]

# for two collections, the second being a list
gap> Difference(M2, [1]);
[ 0 ]

#
gap> STOP_TEST( "coll.tst", 1);