/************************************************************************* Tests for swapping functions *************************************************************************/ private static bool testserializationfunctions(bool silent) { bool result = new bool(); bool okb = new bool(); bool oki = new bool(); bool okr = new bool(); int nb = 0; int ni = 0; int nr = 0; int i = 0; rec4serialization r0 = new rec4serialization(); rec4serialization r1 = new rec4serialization(); result = true; okb = true; oki = true; okr = true; for(nb=1; nb<=4; nb++) { for(ni=1; ni<=4; ni++) { for(nr=1; nr<=4; nr++) { r0.b = new bool[nb]; for(i=0; i<=nb-1; i++) { r0.b[i] = math.randominteger(2)!=0; } r0.i = new int[ni]; for(i=0; i<=ni-1; i++) { r0.i[i] = math.randominteger(10)-5; } r0.r = new double[nr]; for(i=0; i<=nr-1; i++) { r0.r[i] = 2*math.randomreal()-1; } { // // This code passes data structure through serializers // (serializes it to string and loads back) // serializer _local_serializer; string _local_str; _local_serializer = new serializer(); _local_serializer.alloc_start(); testalglibbasicsunit.rec4serializationalloc(_local_serializer, r0); _local_serializer.sstart_str(); testalglibbasicsunit.rec4serializationserialize(_local_serializer, r0); _local_serializer.stop(); _local_str = _local_serializer.get_string(); _local_serializer = new serializer(); _local_serializer.ustart_str(_local_str); testalglibbasicsunit.rec4serializationunserialize(_local_serializer, r1); _local_serializer.stop(); } if( (ap.len(r0.b)==ap.len(r1.b) & ap.len(r0.i)==ap.len(r1.i)) & ap.len(r0.r)==ap.len(r1.r) ) { for(i=0; i<=nb-1; i++) { okb = okb & ((r0.b[i] & r1.b[i]) | (!r0.b[i] & !r1.b[i])); } for(i=0; i<=ni-1; i++) { oki = oki & r0.i[i]==r1.i[i]; } for(i=0; i<=nr-1; i++) { okr = okr & (double)(r0.r[i])==(double)(r1.r[i]); } } else { oki = false; } } } } // // summary // result = result & okb; result = result & oki; result = result & okr; if( !silent ) { if( result ) { System.Console.Write("SERIALIZATION FUNCTIONS: OK"); System.Console.WriteLine(); } else { System.Console.Write("SERIALIZATION FUNCTIONS: FAILED"); System.Console.WriteLine(); System.Console.Write("* BOOLEAN - - - - - - - - - - - - - - - "); if( okb ) { System.Console.Write("OK"); System.Console.WriteLine(); } else { System.Console.Write("FAILED"); System.Console.WriteLine(); } System.Console.Write("* INTEGER - - - - - - - - - - - - - - - "); if( oki ) { System.Console.Write("OK"); System.Console.WriteLine(); } else { System.Console.Write("FAILED"); System.Console.WriteLine(); } System.Console.Write("* REAL - - - - - - - - - - - - - - - - "); if( okr ) { System.Console.Write("OK"); System.Console.WriteLine(); } else { System.Console.Write("FAILED"); System.Console.WriteLine(); } } } return result; }
public static void rec4serializationserialize(alglib.serializer s, rec4serialization v) { int i = 0; // // boolean fields // s.serialize_int(ap.len(v.b)); for(i=0; i<=ap.len(v.b)-1; i++) { s.serialize_bool(v.b[i]); } // // integer fields // s.serialize_int(ap.len(v.i)); for(i=0; i<=ap.len(v.i)-1; i++) { s.serialize_int(v.i[i]); } // // real fields // s.serialize_int(ap.len(v.r)); for(i=0; i<=ap.len(v.r)-1; i++) { s.serialize_double(v.r[i]); } }
public static void rec4serializationunserialize(alglib.serializer s, rec4serialization v) { int i = 0; int k = 0; bool bv = new bool(); int iv = 0; double rv = 0; // // boolean fields // k = s.unserialize_int(); if( k>0 ) { v.b = new bool[k]; for(i=0; i<=k-1; i++) { bv = s.unserialize_bool(); v.b[i] = bv; } } // // integer fields // k = s.unserialize_int(); if( k>0 ) { v.i = new int[k]; for(i=0; i<=k-1; i++) { iv = s.unserialize_int(); v.i[i] = iv; } } // // real fields // k = s.unserialize_int(); if( k>0 ) { v.r = new double[k]; for(i=0; i<=k-1; i++) { rv = s.unserialize_double(); v.r[i] = rv; } } }
public static void rec4serializationalloc(alglib.serializer s, rec4serialization v) { int i = 0; // // boolean fields // s.alloc_entry(); for(i=0; i<=ap.len(v.b)-1; i++) { s.alloc_entry(); } // // integer fields // s.alloc_entry(); for(i=0; i<=ap.len(v.i)-1; i++) { s.alloc_entry(); } // // real fields // s.alloc_entry(); for(i=0; i<=ap.len(v.r)-1; i++) { s.alloc_entry(); } }