Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/GAP/tst/testinstall/   (GAP Algebra Version 4.15.1©)  Datei vom 18.9.2025 mit Größe 16 kB image not shown  

Quelle  list.tst   Sprache: unbekannt

 
Spracherkennung für: .tst vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

gap> START_TEST("list.tst");

# EQ: for two small lists, 1
gap> [1] = [2];
false
gap> [1] = [1];
true
gap> [21] = [2];
false
gap> [4] = [45];
false

# EQ: for two lists, the first or second being empty
gap> l := [0];;
gap> HasIsEmpty(l);
false
gap> l = [];
false
gap> [] = l;
false

#
# assignment / extraction, also with selectors
#
gap> a := [ [ [ 1 ] ] ];
[ [ [ 1 ] ] ]
gap> a[1];
[ [ 1 ] ]
gap> a[1,1];
1 ]
gap> a[1,1,1];
Syntax error: '[]' only supports 1 or 2 indices in stream:1
a[1,1,1];
       ^

#
gap> a := [ [ [12], [34] ], [ [56], [78] ] ];
[ [ [ 12 ], [ 34 ] ], [ [ 56 ], [ 78 ] ] ]
gap> a{[1]};
[ [ [ 12 ], [ 34 ] ] ]
gap> a{[1]}[1];
[ [ 12 ] ]
gap> a{[1]}[1,2];
2 ]
gap> a{[1]}{[1]};
[ [ [ 12 ] ] ]
gap> a{[1]}{[1]}[1];
[ [ 1 ] ]
gap> a{[1]}{[1]}[1,1];
Error, List Element: <list> must be a list (not the integer 1)

#
gap> a{[1,,2]}:=1;
Error, List Assignments: <rhss> must be a dense list (not the integer 1)
gap> a{[1,,2]}:=[1,2];
Error, List Assignments: <poss> must be a dense list of positive integers

#
gap> a{[1]}{[1]}[1] := 42;
Error, List Assignments: <objs> must be a dense list (not the integer 42)
gap> a{[1]}{[1]}[1] := [ 42 ];
Error, List Assignments: <objs> must be a dense list (not the integer 42)
gap> a{[1]}{[1]}[1] := [ [ 42 ] ];
[ [ 42 ] ]
gap> a;
[ [ [ 422 ], [ 34 ] ], [ [ 56 ], [ 78 ] ] ]

#
gap> a{[1]}{[1]} := 19;
Error, List Assignments: <objs> must be a dense list (not the integer 19)
gap> a{[1]}{[1]} := [ 1819 ];
Error, List Assignments: <objs> must have the same length as <lists> (lengths \
are 2 and 1)
gap> a{[1]}{[1]} := [ [ 1819 ] ] ;
Error, List Assignments: <objs> must have the same length as <poss> (lengths a\
re 2 and 1)
gap> a{[1]}{[1,,3]} := [ [ [ 1819 ] ] ];
Error, List Assignments: <poss> must be a dense list of positive integers
gap> a{[1]}{[1]} := [ [ [ 1819 ] ] ];
[ [ [ 1819 ] ] ]
gap> a;
[ [ [ 1819 ], [ 34 ] ], [ [ 56 ], [ 78 ] ] ]

#
gap> a := [ [ [ 1 ] ] ];
[ [ [ 1 ] ] ]
gap> a[1] := [ [ 42 ] ];
[ [ 42 ] ]
gap> a[1,1] := [ 43 ];
43 ]
gap> a[1,1,1] := 44;
Syntax error: '[]' only supports 1 or 2 indices in stream:1
a[1,1,1] := 44;
       ^
gap> IsBound(a[1,1,1]);
Syntax error: '[]' only supports 1 or 2 indices in stream:1
IsBound(a[1,1,1]);
               ^
gap> Unbind(a[1,1,1]);
Syntax error: '[]' only supports 1 or 2 indices in stream:1
Unbind(a[1,1,1]);
              ^
gap> a := [1,,3];;
gap> IsBound(a[1]);
true
gap> IsBound(a[2]);
false
gap> IsBound(a[3]);
true
gap> IsBound(a[4]);
false
gap> IsBound(a[2^100]);
false

#
# slices
#
gap> 1{1};
Error, List Elements: <poss> must be a dense list of positive integers
gap> 1{[1]};
Error, List Elements: <list> must be a list (not the integer 1)

# ... for blists
gap> list := [true,false,true];;
gap> list{1};
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list;  # with a plist as selector
true
gap> list{[1,2^100,3]};
Error, List Elements: position is too large for this type of list
gap> list{[1..3]} = list;  # with a range as selector
true
gap> list{[1..4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[4..5]};
Error, List Elements: <list>[4] must have an assigned value

# ... for plists
gap> list := [124];;
gap> list{1};
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list;  # with a plist as selector
true
gap> list{[1,2^100,3]};
Error, List Elements: position is too large for this type of list
gap> list{[1..3]} = list;  # with a range as selector
true
gap> list{[1..4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[4..5]};
Error, List Elements: <list>[4] must have an assigned value

# ... for ranges
gap> list := [1..3];;
gap> list{1};
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list;  # with a plist as selector
true
gap> list{[1,2^100,3]};
Error, List Elements: position is too large for this type of list
gap> list{[1..3]} = list;  # with a range as selector
true
gap> list{[1..4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[4..5]};
Error, List Elements: <list>[4] must have an assigned value

# ... for strings
gap> list := "abc";;
gap> list{1};
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list;  # with a plist as selector
true
gap> list{[1,2^100,3]};
Error, List Elements: position is too large for this type of list
gap> list{[1..3]} = list;  # with a range as selector
true
gap> list{[1..4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[4..5]};
Error, List Elements: <list>[4] must have an assigned value

# ListWithIdenticalEntries: errors
gap> ListWithIdenticalEntries(fail, true);
Error, ListWithIdenticalEntries: <n> must be a non-negative small integer (not\
 the value 'fail')
gap> ListWithIdenticalEntries(-1, fail);
Error, ListWithIdenticalEntries: <n> must be a non-negative small integer (not\
 the integer -1)

# ListWithIdenticalEntries: 0 length
gap> l := ListWithIdenticalEntries(0, 'w');
""
gap> IsStringRep(l);
true
gap> l := ListWithIdenticalEntries(0, true);
[  ]
gap> IsBlistRep(l);
true
gap> l := ListWithIdenticalEntries(0, fail);
[  ]
gap> IsPlistRep(l);
true

# ListWithIdenticalEntries: strings
gap> l := ListWithIdenticalEntries(1, 'y');
"y"
gap> IsStringRep(l);
true
gap> l := ListWithIdenticalEntries(2, 'z');
"zz"
gap> IsStringRep(l);
true
gap> l := ListWithIdenticalEntries(76, '#');
"############################################################################"
gap> IsStringRep(l);
true

# ListWithIdenticalEntries: blists
gap> l := ListWithIdenticalEntries(1, true);
[ true ]
gap> IsBlistRep(l);
true
gap> l := ListWithIdenticalEntries(2, true);
[ true, true ]
gap> IsBlistRep(l);
true
gap> l := ListWithIdenticalEntries(3, true);
[ true, true, true ]
gap> IsBlistRep(l);
true
gap> ForAll([1 .. 100],
>           i -> ForAll(ListWithIdenticalEntries(i, true), x -> x));
true
gap> l := ListWithIdenticalEntries(1, false);
[ false ]
gap> IsBlistRep(l);
true
gap> l := ListWithIdenticalEntries(2, false);
[ false, false ]
gap> IsBlistRep(l);
true
gap> l := ListWithIdenticalEntries(3, false);
[ false, false, false ]
gap> IsBlistRep(l);
true
gap> ForAny([1 .. 100],
>           i -> ForAny(ListWithIdenticalEntries(i, false), x -> x));
false

# ListWithIdenticalEntries: other
gap> l := ListWithIdenticalEntries(2, Group(()));
[ Group(()), Group(()) ]
gap> IsPlistRep(l);
true
gap> IsIdenticalObj(l[1], l[2]);
true
gap> l := ListWithIdenticalEntries(10, "GAP");;
gap> TNAM_OBJ(l);
"homogeneous plain list"
gap> l;
[ "GAP", "GAP", "GAP", "GAP", "GAP", "GAP", "GAP", "GAP", "GAP", "GAP" ]
gap> TNAM_OBJ(l);
"plain list (table)"
gap> l := ListWithIdenticalEntries(10, PrimitiveRoot(GF(5)));
[ Z(5), Z(5), Z(5), Z(5), Z(5), Z(5), Z(5), Z(5), Z(5), Z(5) ]
gap> TNAM_OBJ(l);
"plain list of small finite field elements"
gap> l := ListWithIdenticalEntries(105 / 7);
5/75/75/75/75/75/75/75/75/75/7 ]
gap> TNAM_OBJ(l);
"plain list of cyclotomics"
gap> l := ListWithIdenticalEntries(5, -1);
[ -1, -1, -1, -1, -1 ]
gap> TNAM_OBJ(l);
"plain list of cyclotomics"
gap> l := ListWithIdenticalEntries(58);
88888 ]
gap> TNAM_OBJ(l);
"plain list of cyclotomics"
gap> l := ListWithIdenticalEntries(50);
00000 ]
gap> TNAM_OBJ(l);
"plain list of cyclotomics"
gap> l := ListWithIdenticalEntries(5, infinity);
[ infinity, infinity, infinity, infinity, infinity ]
gap> TNAM_OBJ(l);
"homogeneous plain list"
gap> l := ListWithIdenticalEntries(4, []);;
gap> TNAM_OBJ(l);
"homogeneous plain list"
gap> l;
[ [  ], [  ], [  ], [  ] ]
gap> TNAM_OBJ(l);
"plain list (rectangular table)"
gap> l := ListWithIdenticalEntries(4, [5]);;
gap> TNAM_OBJ(l);
"homogeneous plain list"
gap> l;
[ [ 5 ], [ 5 ], [ 5 ], [ 5 ] ]
gap> TNAM_OBJ(l);
"plain list (rectangular table)"

# Check PlainListCopy
gap> checkPlainListCopy := function(l)
>   local copy, tnum;
>   tnum := TNUM_OBJ(l);
>   copy := PlainListCopy(l);
>   return IsPlistRep(copy) and l = copy and
>          not IsIdenticalObj(l,copy) and TNUM_OBJ(l) = tnum;
> end;;
gap> checkPlainListCopy([]);
true
gap> checkPlainListCopy([1, ,()]);
true
gap> checkPlainListCopy([1..5]);
true
gap> checkPlainListCopy([10,8..-4]);
true
gap> checkPlainListCopy("");
true
gap> checkPlainListCopy("abc");
true
gap> checkPlainListCopy(ListWithIdenticalEntries(3, false));
true
gap> checkPlainListCopy(NewZeroVector(IsGF2VectorRep, GF(2), 10));
true
gap> checkPlainListCopy(NewZeroVector(Is8BitVectorRep, GF(3), 10));
true
gap> PlainListCopy(6);
Error, PlainListCopy: <list> must be a small list (not the integer 6)
gap> PlainListCopy((1,2,3));
Error, PlainListCopy: <list> must be a small list (not a permutation (small))
#@if IsHPCGAP
gap> PlainListCopy(Group((1,2)));
Error, PlainListCopy: <list> must be a small list (not an atomic component object)
#@else
gap> PlainListCopy(Group((1,2)));
Error, PlainListCopy: <list> must be a small list (not a component object)
#@fi

# Check TNUM behaviours
gap> x := [1,,"cheese"];;
gap> x[2] := 2;;
gap> IsSSortedList(x);;
gap> TNAM_OBJ(x);
"dense plain list"
gap> x := [1,,"cheese"];;
gap> x[2] := 2;
2
gap> y := Immutable(x);;
gap> IsIdenticalObj(x,y);
false
gap> TNAM_OBJ(x);
"plain list"
gap> TNAM_OBJ(y);
"immutable plain list"
gap> IsSSortedList(y);;
gap> TNAM_OBJ(y);
"immutable dense non-homogeneous strictly-sorted plain list"

# String, for a range
gap> l := [5 .. 10];
5 .. 10 ]
gap> String(l);
"[ 5 .. 10 ]"
gap> l := [212325];
212325 ]
gap> IsRange(l);
true
gap> String(l);
"[ 2123 .. 25 ]"
gap> l := [1020];
1020 ]
gap> IsRange(l);
true
gap> String(l);
"[ 1020 .. 20 ]"
gap> l := [21018263442];
21018263442 ]
gap> IsRange(l);
true
gap> String(l);
"[ 210 .. 42 ]"
gap> l := [50403020100, -10];
50403020100, -10 ]
gap> IsRange(l);
true
gap> String(l);
"[ 5040 .. -10 ]"
gap> EvalString(String(l)) = l;
true

# Representative, for two lists
gap> l := Filtered([1 .. 20], IsPrimeInt);;
gap> Representative(l);
2
gap> Representative([]);
Error, <list> must be nonempty to have a representative
gap> Representative(EmptyPlist(0));
Error, <list> must be nonempty to have a representative
gap> l := EmptyPlist(4);;
gap> l[3] := 5;;
gap> Representative(l);
5

# RepresentativeSmallest, for an empty list
gap> RepresentativeSmallest(EmptyPlist(0));
Error, <C> must be nonempty to have a representative

# RepresentativeSmallest, for a strictly sorted list
gap> l := [12 .. 40];;
gap> RepresentativeSmallest(l);
12

# RepresentativeSmallest, for a list
gap> l := [4039 .. 10];;
gap> RepresentativeSmallest(l);
10

# First
gap> First([0,1,2,3]);
0
gap> First([0..3]);
0
gap> First(Enumerator(Integers));
0
gap> First([0,1,2,3], IsFFE);
fail
gap> First([0..3], IsFFE);
fail
gap> First([0,1,2,3], IsPosInt);
1
gap> First([0..3], IsPosInt);
1
gap> First(Enumerator(Integers), IsPosInt);
1

# Last
gap> Last([0,1,2,3]);
3
gap> Last([0..3]);
3
gap> Last(Enumerator(Integers));
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `LastOp' on 1 arguments
gap> Last([0,1,2,3], IsFFE);
fail
gap> Last([0..3], IsFFE);
fail
gap> Last([0,1,2,3], IsZero);
0
gap> Last([0..3], IsZero);
0
gap> Last(Enumerator(Integers), IsZero);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `LastOp' on 2 arguments

# Positions
gap> ll := [ 123212 ];;
gap> Positions( ll, 1 );
15 ]
gap> Positions( ll, 4 );
[  ]
gap> HasIsSSortedList( Positions( ll, 2 ) );
true

# PositionSortedBy on plist
gap> ll := [ 13 ];;
gap> PositionSortedBy(ll, 0, x -> x);
1
gap> PositionSortedBy(ll, 1, x -> x);
1
gap> PositionSortedBy(ll, 2, x -> x);
2
gap> PositionSortedBy(ll, 3, x -> x);
2
gap> PositionSortedBy(ll, 4, x -> x);
3
gap> PositionSortedBy([], 0, x -> x);
1
gap> for ll in [ [1], [1,2], [1,2,3], [1,2,3,4], [1,4] ] do
>   for a in [0..5] do
>     p := PositionSortedBy(ll, a, x -> x);
>     Assert(0, p = 1 or ll[p-1] < a);
>     Assert(0, p = Length(ll) + 1 or a <= ll[p]);
>   od;
> od;

# PositionSortedBy on range
gap> ll := [ 13 .. 3 ];;
gap> PositionSortedBy(ll, 0, x -> x);
1
gap> PositionSortedBy(ll, 1, x -> x);
1
gap> PositionSortedBy(ll, 2, x -> x);
2
gap> PositionSortedBy(ll, 3, x -> x);
2
gap> PositionSortedBy(ll, 4, x -> x);
3
gap> for ll in [ [1..2], [1..3], [1..4], [1,4..4] ] do
>   for a in [0..5] do
>     p := PositionSortedBy(ll, a, x -> x);
>     Assert(0, p = 1 or ll[p-1] < a);
>     Assert(0, p = Length(ll) + 1 or a <= ll[p]);
>   od;
> od;

# PositionsProperty
gap> ll := [ 1, , "s" ];;
gap> PositionsProperty( ll, ReturnTrue );
13 ]
gap> PositionsProperty( ll, IsInt );
1 ]
gap> ll := [ 123 ];;
gap> PositionsProperty( ll, ReturnTrue );
123 ]
gap> PositionsProperty( ll, IsInt );
123 ]
gap> HasIsSSortedList( PositionsProperty( ll, IsPrimeInt ) );
true

# PositionProperty
gap> ll := [ 1, , "s" ];;
gap> PositionProperty( ll, ReturnTrue, 0);
1
gap> PositionProperty( ll, ReturnTrue, 1);
3
gap> PositionProperty( ll, IsInt, 0);
1
gap> PositionProperty( ll, IsInt, 1);
fail
gap> ll := [ 123 ];;
gap> PositionProperty( ll, ReturnTrue, 0);
1
gap> PositionProperty( ll, ReturnTrue, 1);
2
gap> PositionProperty( ll, ReturnTrue, 2);
3
gap> PositionProperty( ll, ReturnTrue, 3);
fail

# PositionBound
gap> PositionBound( [] );
fail
gap> PositionBound( [ 1 .. 3 ] );
1
gap> PositionBound( [ 234 ] );
1
gap> PositionBound( [ ,, 1 ] );
3

# PositionsBound
gap> PositionsBound( [] );
[  ]
gap> PositionsBound( [ 1 .. 3 ] );
1 .. 3 ]
gap> PositionsBound( [ 123 ] );
1 .. 3 ]
gap> PositionsBound( [ 1,, 2 ] );
13 ]
gap> HasIsSSortedList( PositionsBound( [ 1,, 2 ] ) );
true

# AsSet
gap> l := ["a", "b", "c"];
[ "a", "b", "c" ]
gap> MakeImmutable(l);;
gap> IsSet(l);
true
gap> IsIdenticalObj(AsSet(l), l);
true
gap> l := [true, false];
[ true, false ]
gap> MakeImmutable(l);;
gap> IsSet(l);
true
gap> IsIdenticalObj(AsSet(l), l);
true
gap> l := [1..3];
1 .. 3 ]
gap> MakeImmutable(l);;
gap> IsIdenticalObj(AsSet(l), l);
true

# IteratorList
# immutable dense list
gap> tmp := MakeImmutable([1234]);
1234 ]
gap> it := IteratorList(tmp);
<iterator>
gap> for x in it do Print(x); od; Print("\n");
1234
gap> IsDoneIterator(it);
true
gap> NextIterator(it);
Error, List Element: <list>[5] must have an assigned value
gap> IsDoneIterator(it);
true

# mutable dense list
gap> tmp := [1 .. 4];;
gap> it := IteratorList(tmp);
<iterator>
gap> for x in it do Print(x); od; Print("\n");
1234
gap> IsDoneIterator(it);
true
gap> NextIterator(it);
Error, <iter> is exhausted
gap> IsDoneIterator(it);
true

# immutable non-dense list
gap> tmp := MakeImmutable([, 23, , 56,]);
[ , 23,, 56 ]
gap> it := IteratorList(tmp);
<iterator>
gap> for x in it do Print(x); od; Print("\n");
2356
gap> IsDoneIterator(it);
true
gap> NextIterator(it);
Error, <iter> is exhausted
gap> IsDoneIterator(it);
true

# mutable non-dense list
gap> tmp := [, 23, , 56,];
[ , 23,, 56 ]
gap> it := IteratorList(tmp);
<iterator>
gap> for x in it do Print(x); od; Print("\n");
2356
gap> IsDoneIterator(it);
true
gap> NextIterator(it);
Error, <iter> is exhausted
gap> IsDoneIterator(it);
true

# Sublist search
gap> a:=[4,2,3,1,5,2,4,2,1,4,1,4,1,4,2,1,5,1,2,1,4,5,1,2,4];;
gap> PositionSublist(a,[4,2,1,4,1,4,1,4]);
7
gap> PositionSublist(a,[4,2,1,4,1,4,1,4],7);
fail
gap> PositionSublist(a,[4]);
1
gap> PositionSublist(a,[2,4]);
6
gap> PositionSublist(a,[2,4],6);
24
gap> PositionSublist(a,[2,4],24);
fail
gap> PositionSublist(a,[2,4,1]);
fail
gap> PositionSublist(a,[4,2,1]);
7
gap> PositionSublist(a,[4,2,1],6);
7
gap> PositionSublist(a,[4,2,1],7);
14
gap> PositionSublist(a,[4,2,1],14);
fail
gap> PositionSublist(a,[]);
1
gap> PositionSublist(a,[],1);
2

# Verify SetIsSSortedList works on plain lists. For background, see
# <https://github.com/gap-system/gap/issues/4459>.
gap> l:= [ 132 ];
132 ]
gap> HasIsSSortedList( l );
false
gap> SetIsSSortedList( l, false );
gap> HasIsSSortedList( l );
true
gap> IsSSortedList( l );
false
gap> HasIsSSortedList( l );
true

#
gap> l:= [ 135 ];
135 ]
gap> HasIsSSortedList( l );
false
gap> SetIsSSortedList( l, true );
gap> HasIsSSortedList( l );
true

#
gap> STOP_TEST("list.tst");

[Dauer der Verarbeitung: 0.16 Sekunden, vorverarbeitet 2026-06-17]