1# Test file for pickling/unpickling: 2 3# Preparations: 4x := X(Rationals); 5InstallMethod( EQ, [ IsStraightLineProgram, IsStraightLineProgram ], 6 function(a,b) 7 return LinesOfStraightLineProgram(a) = LinesOfStraightLineProgram(b) and 8 NrInputsOfStraightLineProgram(a) = NrInputsOfStraightLineProgram(b); 9 end ); 10InstallMethod( PrintObj, 11 "for element in Z/pZ (ModulusRep)", 12 [ IsZmodpZObj and IsModulusRep ], 13 function( x ) 14 Print( "ZmodnZObj( ", x![1], ", ", Characteristic( x ), " )" ); 15 end ); 16InstallMethod( String, 17 "for element in Z/pZ (ModulusRep)", 18 [ IsZmodpZObj and IsModulusRep ], 19 function( x ) 20 return Concatenation( "ZmodnZObj(", String(x![1]), ",", 21 String(Characteristic( x )), ")" ); 22 end ); 23 24# HACK" for GAP before 4.9. avoid warning about 25# "computing Conway polynomial". 26old:=InfoLevel(InfoWarning); 27SetInfoLevel(InfoWarning, 0); 28Z(65537^2); 29SetInfoLevel(InfoWarning, old); 30 31 32# Build up a variety of different GAP objects in a list: 33l := [ 34 35false, 36true, 37fail, 380, 39-1, 401, 411234567123512636523123561311223123123123234234234, 421.0, 43-1.0, 441.23456789123456789 45-0., # Note, we test floats further at Error(36) 460., 471.0/0.0, # inf 48(-1.0)/0.0, # -inf 493.141^100, 503.141^-100, 51Transformation([]), 52Transformation([3,2,1]), 53Transformation([1,1,1]), 54Transformation([3,3,3]), 55Transformation([100],[100]), 56Transformation([100],[103]), 57PartialPerm([]), 58PartialPerm([2],[3]), 59PartialPerm([1000],[999]), 60PartialPerm([1000,1001],[1000,3]), 61PartialPerm([9,10,20],[30,40,50]), 62"Max", 63'M', 64E(4), 65E(4)+E(4)^3, 66StraightLineProgram([[1,1,2,1,1,-1],[3,1,2,-1]],2), 67Z(2), 68Z(2)^0, 690*Z(2), 70Z(2^3), 71Z(2^3)^0, 720*Z(2^3), 73Z(3), 74Z(3)^0, 750*Z(3), 76Z(3^5), 77Z(3^5)^0, 780*Z(3^5), 79Z(257), 800*Z(257), 81Z(257)^0, 82Z(257^4), 830*Z(257^4), 84Z(257^4)^0, 85Z(65537), 86Z(65537)^0, 870*Z(65537), 88Z(65537^2), 89Z(65537^2)^0, 900*Z(65537^2), 91(1,2,3,4), 92,,,, # a gap 93x^2+x+1, 94x^-3+1+x^4, 95(x+1)/(x+2), 96rec( a := 1, b := "Max" ), 97rec( c := 3, d := "Till" ), 98 99]; 100 101MakeImmutable(l[Length(l)]); 102 103v := [Z(5),0*Z(5),Z(5)^2]; 104ConvertToVectorRep(v,5); 105Add(l,v); 106vecpos := Length(l); 107w := ShallowCopy(v); 108MakeImmutable(w); 109Add(l,w); 110vv := [Z(7),0*Z(7),Z(7)^2]; 111ConvertToVectorRep(vv,7^2); 112Add(l,vv); 113ww := ShallowCopy(vv); 114MakeImmutable(ww); 115Add(l,ww); 116vvv := [Z(2),0*Z(2)]; 117ConvertToVectorRep(vvv,2); 118Add(l,vvv); 119www := ShallowCopy(vvv); 120MakeImmutable(www); 121Add(l,www); 122 123# compressed matrices: 124m := [[Z(5),0*Z(5),Z(5)^2]]; 125ConvertToMatrixRep(m,5); 126Add(l,m); 127n := MutableCopyMat(m); 128ConvertToMatrixRep(n,5); 129MakeImmutable(n); 130Add(l,n); 131mm := [[Z(7),0*Z(7),Z(7)^2]]; 132ConvertToMatrixRep(mm,7^2); 133Add(l,mm); 134nn := MutableCopyMat(mm); 135ConvertToMatrixRep(nn,7^2); 136MakeImmutable(nn); 137Add(l,nn); 138mmm := [[Z(2),0*Z(2)]]; 139ConvertToMatrixRep(mmm,2); 140Add(l,mmm); 141nnn := MutableCopyMat(mmm); 142ConvertToMatrixRep(nnn,2); 143MakeImmutable(nnn); 144Add(l,nnn); 145 146# Finally self-references: 147r := rec( l := l, x := 1 ); 148r.r := r; 149Add(l,l); 150Add(l,r); 151 152s := ""; 153f := IO_WrapFD(-1,false,s); 154if IO_Pickle(f,l) <> IO_OK then Error(1); fi; 155if IO_Pickle(f,"End") <> IO_OK then Error(2); fi; 156IO_Close(f); 157 158# Print("Bytes pickled: ",Length(s),"\n"); 159 160f := IO_WrapFD(-1,s,false); 161ll := IO_Unpickle(f); 162for i in [1..Length(l)-2] do 163 if not( (not(IsBound(l[i])) and not(IsBound(ll[i]))) or 164 (IsBound(l[i]) and IsBound(ll[i]) and l[i] = ll[i]) ) then 165 Error(3); 166 fi; 167od; 168if not(IsIdenticalObj(ll,ll[Length(ll)-1])) then Error(4); fi; 169if not(IsIdenticalObj(ll,ll[Length(ll)].l)) then Error(5); fi; 170if not(IsIdenticalObj(ll[Length(ll)],ll[Length(ll)].r)) then Error(6); fi; 171if ll[Length(ll)].x <> l[Length(l)].x then Error(7); fi; 172if not(IsMutable(ll[vecpos-2])) then Error(8); fi; 173if IsMutable(ll[vecpos-1]) then Error(9); fi; 174if not(Is8BitVectorRep(ll[vecpos])) then Error(10); fi; 175if not(IsMutable(ll[vecpos])) then Error(11); fi; 176if not(Is8BitVectorRep(ll[vecpos+1])) then Error(12); fi; 177if IsMutable(ll[vecpos+1]) then Error(13); fi; 178if not(Is8BitVectorRep(ll[vecpos+2])) then Error(14); fi; 179if not(IsMutable(ll[vecpos+2])) then Error(15); fi; 180if not(Is8BitVectorRep(ll[vecpos+3])) then Error(16); fi; 181if IsMutable(ll[vecpos+3]) then Error(17); fi; 182if not(IsGF2VectorRep(ll[vecpos+4])) then Error(18); fi; 183if not(IsMutable(ll[vecpos+4])) then Error(19); fi; 184if not(IsGF2VectorRep(ll[vecpos+5])) then Error(20); fi; 185if IsMutable(ll[vecpos+5]) then Error(21); fi; 186if not(Is8BitMatrixRep(ll[vecpos+6])) then Error(22); fi; 187if not(IsMutable(ll[vecpos+6])) or not(IsMutable(ll[vecpos+6][1])) then 188 Error(23); 189fi; 190if not(Is8BitMatrixRep(ll[vecpos+7])) then Error(24); fi; 191if IsMutable(ll[vecpos+7]) or IsMutable(ll[vecpos+7]) then Error(25); fi; 192if not(Is8BitMatrixRep(ll[vecpos+8])) then Error(26); fi; 193if not(IsMutable(ll[vecpos+8])) or not(IsMutable(ll[vecpos+8])) then 194 Error(27); 195fi; 196if not(Is8BitMatrixRep(ll[vecpos+9])) then Error(28); fi; 197#if IsMutable(ll[vecpos+9]) or IsMutable(ll[vecpos+9][1]) then Error(29); fi; 198if not(IsGF2MatrixRep(ll[vecpos+10])) then Error(30); fi; 199if not(IsMutable(ll[vecpos+10])) or not(IsMutable(ll[vecpos+10][1])) then 200 Error(31); 201fi; 202if not(IsGF2MatrixRep(ll[vecpos+11])) then Error(32); fi; 203#if IsMutable(ll[vecpos+11]) or IsMutable(ll[vecpos+11][1]) then Error(33); fi; 204 205ee := IO_Unpickle(f); 206if ee <> "End" then Error(34); fi; 207 208if IO_Unpickle(f) <> IO_Nothing then Error(35); fi; 209 210IO_Close(f); 211 212floatlist := [-0.0, 0.0, 0.0/0.0, 1.0/0.0, -1.0/0.0, 1.23456789123456789]; 213 214pickledlist := IO_Unpickle(IO_Pickle(floatlist)); 215 216# ExtRepOfObj deals with issues like infinity, -0 vs +0, nan, etc. 217 218if List(floatlist, x -> ExtRepOfObj(x)) <> 219 List(pickledlist, x -> ExtRepOfObj(x)) then 220 Error(36); 221fi; 222 223rng:= IO_Unpickle( IO_Pickle( [ 1 .. 1000 ] ) );; 224if rng <> [ 1 .. 1000 ] then 225 Error( 37 ); 226elif not IsRangeRep( rng ) then 227 Error( 38 ); 228fi; 229 230g:= SymmetricGroup( 6 );; tbl:= CharacterTable( g );; Irr( tbl );; 231tbl2:= IO_Unpickle( IO_Pickle( tbl ) );; 232if not ( HasIrr( tbl ) and HasIrr( tbl2 ) ) then 233 Error( 39 ); 234elif Irr( tbl ) <> Irr( tbl2 ) then 235 Error( 40 ); 236elif not ( HasConjugacyClasses( UnderlyingGroup( tbl ) ) 237 and HasConjugacyClasses( UnderlyingGroup( tbl2 ) ) ) then 238 Error( 41 ); 239elif ConjugacyClasses( UnderlyingGroup( tbl ) ) 240 <> ConjugacyClasses( UnderlyingGroup( tbl2 ) ) then 241 Error( 42 ); 242fi; 243 244