Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/GAP/pkg/semigroups/tst/standard/tools/   (GAP Algebra Version 4.15.1©)  Datei vom 29.7.2025 mit Größe 14 kB image not shown  

Quelle  io.tst   Sprache: unbekannt

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

#############################################################################
##
#W  standard/tools/io.tst
#Y  Copyright (C) 2016-2022                              James D. Mitchell
##
##  Licensing information can be found in the README file of this package.
##
#############################################################################
##

#@local file, fname, gens, it, name, table, tables, x
gap> START_TEST("Semigroups package: standard/tools/io.tst");
gap> LoadPackage("semigroups", false);;

#
gap> SEMIGROUPS.StartTest();

# Test IteratorFromGeneratorsFile
gap> it := IteratorFromGeneratorsFile(Concatenation(SEMIGROUPS.PackageDir,
> "/non-existant-file.gz"));
fail
gap> it := IteratorFromGeneratorsFile(Concatenation(SEMIGROUPS.PackageDir,
> "/data/tst/testdata"));
<iterator>
gap> NextIterator(it);
[ <identity partial perm on [ 123 ]>, <identity partial perm on [ 13 ]> 
 ]
gap> NextIterator(it);
[ <identity partial perm on [ 134 ]>, [1,2](3)(4) ]
gap> IsDoneIterator(it);
false
gap> for x in it do od;
gap> IsDoneIterator(it);
true
gap> it := ShallowCopy(it);
<iterator>
gap> NextIterator(it);
[ <identity partial perm on [ 123 ]>, <identity partial perm on [ 13 ]> 
 ]
gap> NextIterator(it);
[ <identity partial perm on [ 134 ]>, [1,2](3)(4) ]
gap> IsDoneIterator(it);
false
gap> for x in it do od;
gap> IsDoneIterator(it);
true

# Test ReadGenerators
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/testdata");;
gap> gens := ReadGenerators(name);;
gap> Length(gens);
13
gap> ReadGenerators(name, 2);
[ <identity partial perm on [ 134 ]>, [1,2](3)(4) ]
gap> ReadGenerators(name, 23);
Error, there should be 1 or 2 arguments
gap> ReadGenerators("non-existant-file");
Error, could not open the file non-existant-file
gap> file := IO_CompressedFile(name, "r");;
gap> ReadGenerators(file, 2);
[ <identity partial perm on [ 134 ]>, [1,2](3)(4) ]
gap> ReadGenerators(file, -1);
Error, the 2nd argument is not a positive integer
gap> ReadGenerators(file, 2000);
Error, the file only has 11 further entries
gap> ReadGenerators(3);
Error, the 1st argument is not a string or a file
gap> IO_Close(file);
true

# Test WriteGenerators
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/testdata");;
gap> gens := ReadGenerators(name);;
gap> name := Filename(DirectoryTemporary(), "testdata");;
gap> WriteGenerators(name, gens);
IO_OK
gap> WriteGenerators(name, gens, "w");
IO_OK
gap> WriteGenerators(name, gens, "w", 2);
Error, the 3rd or 4th argument is not a function
gap> WriteGenerators(name, gens, "x");
Error, the 3rd argument is not "a" or "w"
gap> file := IO_CompressedFile(name, "w");;
gap> WriteGenerators(file, gens);
IO_OK
gap> IO_Close(file);
true
gap> WriteGenerators(3, gens);
Error, the 1st argument is not a string or a file
gap> name := Filename(DirectoryTemporary(), "tmpfile");; 
gap> WriteGenerators(name, [FullTransformationMonoid(3)]);
IO_OK
gap> Length(ReadGenerators(name)[1]);
4
gap> WriteGenerators(name, gens, 1);
Error, the 3rd argument is not a string or a function
gap> WriteGenerators(12345);
Error, there should be 23, or 4 arguments
gap> WriteGenerators(name, [], "w");
Error, the 2nd argument is not a non-empty list

# Test ReadGenerators
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/trans3");;
gap> ReadGenerators(name);
[ [ Transformation( [ 111 ] ) ], [ Transformation( [ 112 ] ) ], 
  [ Transformation( [ 11 ] ) ], [ IdentityTransformation ], 
  [ Transformation( [ 132 ] ) ], [ Transformation( [ 211 ] ) ], 
  [ Transformation( [ 231 ] ) ] ]
gap> ReadGenerators(name, 4);
[ IdentityTransformation ]
gap> ReadGenerators(name, 23);
Error, there should be 1 or 2 arguments
gap> ReadGenerators("non-existant-file");
Error, could not open the file non-existant-file
gap> file := IO_CompressedFile(name, "r");;
gap> ReadGenerators(file, 2);
[ Transformation( [ 112 ] ) ]
gap> ReadGenerators(file, -1);
Error, the 2nd argument is not a positive integer
gap> ReadGenerators(file, 2000);
Error, the file only has 5 further entries
gap> IO_Close(file);
true
gap> ReadGenerators(3);
Error, the 1st argument is not a string or a file
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/bipart4");;
gap> ReadGenerators(name);
[ [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234, -1, -2, -3 ], [ -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234, -1, -2 ], [ -3, -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234, -1, -2 ], [ -3 ], [ -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234, -1 ], [ -2, -3, -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234, -1 ], [ -2, -3 ], [ -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234, -1 ], [ -2 ], [ -3 ], [ -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234 ], [ -1, -2, -3, -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234 ], [ -1, -2, -3 ], [ -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234 ], [ -1, -2 ], [ -3, -4 ]> ], 
  [ <block bijection: [ 1234, -1, -2, -3, -4 ]>, 
      <bipartition: [ 1234 ], [ -1, -2 ], [ -3 ], [ -4 ]> ] ]
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/pperm10");;
gap> ReadGenerators(name);
[ [ [3,7][8,1,2,6,9][10,5] ] ]

# Test IteratorFromGeneratorsFile
gap> it := IteratorFromGeneratorsFile("non-existant-file.gz");
fail
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/trans3");;
gap> it := IteratorFromGeneratorsFile(name);
<iterator>
gap> NextIterator(it);
[ Transformation( [ 111 ] ) ]
gap> NextIterator(it);
[ Transformation( [ 112 ] ) ]
gap> IsDoneIterator(it);
false
gap> for x in it do od;
gap> IsDoneIterator(it);
true
gap> it := ShallowCopy(it);
<iterator>
gap> NextIterator(it);
[ Transformation( [ 111 ] ) ]
gap> NextIterator(it);
[ Transformation( [ 112 ] ) ]
gap> IsDoneIterator(it);
false
gap> for x in it do od;
gap> IsDoneIterator(it);
true

# Test ReadMultiplicationTable
# The following tests regularly fail in the CI cygwin jobs, and so are disabled
#@if not ARCH_IS_WINDOWS()
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/tables.gz");;
gap> tables := ReadMultiplicationTable(name);;
gap> Length(tables);
48
gap> ReadMultiplicationTable(name, 3);
[ [ 1134567891 ], [ 12345678910 ], 
  [ 3345678913 ], [ 4456789134 ], 
  [ 5567891345 ], [ 6678913456 ], 
  [ 7789134567 ], [ 8891345678 ], 
  [ 9913456789 ], [ 11034567892 ] ]
gap> ReadMultiplicationTable(name, 34);
Error, there should be 1 or 2 arguments
gap> ReadMultiplicationTable("non-existant-file");
Error, could not open the file "non-existant-file"
gap> file := IO_CompressedFile(name, "r");;
gap> ReadMultiplicationTable(file, 2);
[ [ 11345678910 ], [ 12345678910 ], 
  [ 33678191045 ], [ 44786910153 ], 
  [ 55867101934 ], [ 66191034578 ], 
  [ 77910145386 ], [ 88101953467 ], 
  [ 99453786101 ], [ 101053486719 ] ]
gap> ReadGenerators(file, -1);
Error, the 2nd argument is not a positive integer
gap> ReadMultiplicationTable(file, -2);
Error, the 2nd argument is not a positive integer
gap> ReadMultiplicationTable(file, 100);
Error, the file only has 46 lines
gap> ReadMultiplicationTable(32);
Error, the 1st argument is not a string or a file
gap> IO_Close(file);
true
#@fi

# Test WriteMultiplicationTable
# The following tests regularly fail in the CI cygwin jobs, and so are disabled
#@if not ARCH_IS_WINDOWS()
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/tables.gz");;
gap> tables := ReadMultiplicationTable(name);;
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/tmptables");;
gap> WriteMultiplicationTable(name, tables);
IO_OK
gap> WriteMultiplicationTable(name, tables, "w");
IO_OK
gap> WriteMultiplicationTable(name, tables, "w", 2);
Error, there must be 2 or 3 arguments
gap> WriteMultiplicationTable(name, tables, "x");
Error, the 3rd argument is not "a" or "w"
gap> file := IO_CompressedFile(name, "w");;
gap> WriteMultiplicationTable(file, tables);
IO_OK
gap> IO_Close(file);
true
gap> WriteMultiplicationTable(3, tables);
Error, the 1st argument is not a string or a file
gap> name := Concatenation(SEMIGROUPS.PackageDir, "/data/tst/tmptables");;
gap> table := [[1234], [123, false], [2341], [4321]];;
gap> WriteMultiplicationTable(name, [table]);
Error, the 2nd argument is not a collection of rectangular tables containing o\
nly integers
gap> table := [[123], [12], [321]];;
gap> WriteMultiplicationTable(name, [table]);
Error, the 2nd argument is not a collection of rectangular tables containing o\
nly integers
gap> table := [[12345678910111213141516],
> [24678911112131431551610],
> [36591081213111151421647],
> [47911112214315561681013],
> [58101111314215341667912],
> [69812131131514216541071],
> [71122143456168910111315],
> [81113142155416671091123],
> [91211315146165410871312],
> [10131153216645978121114],
> [11141554168710911312236],
> [12314616591087131111524],
> [13152166410978121113145],
> [14516871011113122153469],
> [15164109713121113214658],
> [16107131211532146459811]];;
gap> WriteMultiplicationTable(name, [table]);
IO_OK
gap> WriteMultiplicationTable(name, [table + 250]);
Error, the 2nd argument is not a collection of rectangular tables with integer\
 entries from [12, ..., n] (where n equals the number of rows of the table)
gap> table := MultiplicationTable(PcGroupCode(0257));;
gap> WriteMultiplicationTable(name, [table]);
Error, the 2nd argument is not a collection of rectangular tables with at most\
 255 rows
gap> Exec("rm ", name);
#@fi

# Test IteratorFromMultiplicationTableFile
# The following tests regularly fail in the CI cygwin jobs, and so are disabled
#@if not ARCH_IS_WINDOWS()
gap> it := IteratorFromMultiplicationTableFile(Concatenation(SEMIGROUPS.PackageDir,
> "/non-existant-file.gz"));
fail
gap> it := IteratorFromMultiplicationTableFile(Concatenation(SEMIGROUPS.PackageDir,
> "/data/tst/tables.gz"));
<iterator>
gap> NextIterator(it);
[ [ 11345678910 ], [ 12345678910 ], 
  [ 33456789101 ], [ 44567891013 ], 
  [ 55678910134 ], [ 66789101345 ], 
  [ 77891013456 ], [ 88910134567 ], 
  [ 99101345678 ], [ 101013456789 ] ]
gap> NextIterator(it);
[ [ 11345678910 ], [ 12345678910 ], 
  [ 33678191045 ], [ 44786910153 ], 
  [ 55867101934 ], [ 66191034578 ], 
  [ 77910145386 ], [ 88101953467 ], 
  [ 99453786101 ], [ 101053486719 ] ]
gap> IsDoneIterator(it);
false
gap> for x in it do od;
gap> IsDoneIterator(it);
true
gap> it := ShallowCopy(it);
<iterator>
gap> NextIterator(it);
[ [ 11345678910 ], [ 12345678910 ], 
  [ 33456789101 ], [ 44567891013 ], 
  [ 55678910134 ], [ 66789101345 ], 
  [ 77891013456 ], [ 88910134567 ], 
  [ 99101345678 ], [ 101013456789 ] ]
gap> NextIterator(it);
[ [ 11345678910 ], [ 12345678910 ], 
  [ 33678191045 ], [ 44786910153 ], 
  [ 55867101934 ], [ 66191034578 ], 
  [ 77910145386 ], [ 88101953467 ], 
  [ 99453786101 ], [ 101053486719 ] ]
gap> IsDoneIterator(it);
false
gap> for x in it do od;
gap> IsDoneIterator(it);
true
#@fi

# Test read from an old format file
gap> ReadGenerators(Filename(DirectoriesPackageLibrary("semigroups",
>                                                      "data/tst/")[1], 
>                            "trans3-old"));
[ [ Transformation( [ 111 ] ) ], [ Transformation( [ 112 ] ) ], 
  [ Transformation( [ 11 ] ) ], [ IdentityTransformation ], 
  [ Transformation( [ 132 ] ) ], [ Transformation( [ 211 ] ) ], 
  [ Transformation( [ 231 ] ) ] ]

# Test write using old format
gap> fname := Filename(DirectoryTemporary(), "tmpfile");;
gap> WriteGenerators(fname,
>                    [FullTransformationMonoid(3)],
>                    SEMIGROUPS.WriteGeneratorsLine);
IO_OK
gap> FullTransformationMonoid(3) = Semigroup(ReadGenerators(fname)[1]);
true
gap> WriteGenerators(fname,
>                    [[Bipartition([[13, -3, -5, -6], [247], [5689, -8, -9],
>                                   [10, -1, -4], [-2, -7], [-10]])]],
>                    SEMIGROUPS.WriteGeneratorsLine);
IO_OK
gap> ReadGenerators(fname);
[ [ <bipartition: [ 13, -3, -5, -6 ], [ 247 ], [ 5689, -8, -9 ], 
         [ 10, -1, -4 ], [ -2, -7 ], [ -10 ]> ] ]
gap> WriteGenerators(fname,
>                    [[PartialPerm([1245671112], 
>                                  [358124197])]], 
>                    "a",
>                    SEMIGROUPS.WriteGeneratorsLine);
IO_OK
gap> ReadGenerators(fname);
[ [ <bipartition: [ 13, -3, -5, -6 ], [ 247 ], [ 5689, -8, -9 ], 
         [ 10, -1, -4 ], [ -2, -7 ], [ -10 ]> ], 
  [ [2,5,12,7,1,3][6,4,8][11,9] ] ]
gap> WriteGenerators(fname, 
>                    [[Matrix(Integers, [[0]])]], 
>                    "w",
>                    SEMIGROUPS.WriteGeneratorsLine);
Error, the 2nd argument is incompatible with the file format

#
gap> SEMIGROUPS.StopTest();
gap> STOP_TEST("Semigroups package: standard/tools/io.tst");

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