Changeset 1088 for code/branches/network/src/network/diffTest.cc
- Timestamp:
- Apr 17, 2008, 1:15:58 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/diffTest.cc
r1008 r1088 38 38 if ( g1->id != g2->id ) { 39 39 std::cout << "\t--> GameStates are not comparable -> not same id" << std::endl; 40 return 1;40 return true; 41 41 } 42 42 else if ( g1->size != g2->size ) { … … 51 51 } 52 52 } 53 std::cout << "\t--> GameStates are identical (compareData)" << std::endl; 53 //std::cout << "\t--> GameData are identical (compareData)" << std::endl; 54 return true; 55 } 56 57 bool compareData2( GameState* g1, GameState* g2 ) { 58 int length = g1->size; 59 for ( int i=0; i<length; i++ ) { 60 if ( g1->data[i] != g2->data[i] ) { 61 return false; 62 } 63 } 64 //std::cout << "\t--> GameData are identical (compareData)" << std::endl; 54 65 return true; 55 66 } … … 67 78 return false; 68 79 } 69 else if ( !compareData ( g1, g2 ) ) {80 else if ( !compareData2( g1, g2 ) ) { 70 81 std::cout << "\t==> GameState data are not identical (GameStateCompare)" << std::endl; 71 82 return false; 72 83 } 73 std::cout << "\t==> GameStates are identical (GameStateCompare)" << std::endl;84 //std::cout << "\t==> GameStates are identical (GameStateCompare)" << std::endl; 74 85 return true; 75 86 } … … 132 143 b->size = length; 133 144 for ( int i=0; i<length; i++ ) { 134 if ( i%(rand()%((length)/11) ) == 0 ) b->data[i] =rand()%255;145 if ( i%(rand()%((length)/11)+rand()) == 0 ) b->data[i] = (char)rand()%255; 135 146 else b->data[i] = a->data[i]; 136 147 } … … 141 152 b->size = s; 142 153 for ( int i=0; i<length; i++ ) { 143 if ( i%10 == 0 ) b->data[i] = rand()%255;154 if ( i%10 == 0 ) b->data[i] = (char)rand()%255; 144 155 else b->data[i] = a->data[i]; 145 156 } 146 157 for( int i=length; i<s; i++ ) { 147 b->data[i] = rand()%255;158 b->data[i] = (char)rand()%255; 148 159 } 149 160 } … … 153 164 b->size = s; 154 165 for ( int i=0; i<length; i++ ) { 155 if ( i%(rand()%(length) ) == 0 ) b->data[i] =rand()%255;166 if ( i%(rand()%(length)+rand()) == 0 ) b->data[i] = (char)rand()%255; 156 167 else b->data[i] = a->data[i]; 157 168 } … … 165 176 b->size = s; 166 177 for ( int i=0; i<s; i++ ) { 167 if ( i%10 == 0 ) b->data[i] = rand()%255;178 if ( i%10 == 0 ) b->data[i] = (char)rand()%255; 168 179 else b->data[i] = a->data[i]; 169 180 } … … 260 271 printGameState( g_undiff2 ); 261 272 262 if( !compareData( g_undiff1, g_undiff2 ) ) std::cout << " BUT THAT'S HOW IT HAS TO BE" << std::endl;273 if( !compareData( g_undiff1, g_undiff2 ) ) std::cout << " DATA not identical.. ok" << std::endl; 263 274 264 275 g_diffed = g_manager->testDiff( g_undiff1, g_undiff2 ); … … 279 290 280 291 std::cout << "---Diffed Gamestates before compressed and after uncompress comparsion" << std::endl; 281 compareGameStates( g_resultDiffed, g_diffed );292 if ( compareGameStates( g_resultDiffed, g_diffed ) ) std::cout << "GAMESTATES IDENTICAL" << std::endl; 282 293 283 294 g_resultUndiffed = g_client->testUndiff( g_undiff1, g_resultDiffed ); 284 295 std::cout << "---New Gamestate of pseudo Server compared with new gamestate that Client gets" << std::endl; 285 compareGameStates( g_resultUndiffed, g_undiff2 );296 if ( compareGameStates( g_resultUndiffed, g_undiff2 ) ) std::cout << "GAMESTATES IDENTICAL" << std::endl; 286 297 287 298 return; 299 } 300 301 bool testNCompressWithDiff( int n, int size, int modeCreateData, int modeChangeData ) { 302 303 GameStateClient* g_client; 304 GameStateManager* g_manager;; 305 306 GameStateCompressed* gc = new GameStateCompressed; 307 GameState* g_undiff1 = new GameState; 308 GameState* g_undiff2 = new GameState; 309 GameState* g_diffed; 310 GameState* g_resultDiffed; 311 GameState* g_resultUndiffed; 312 313 g_undiff1->data = createData( size, modeCreateData ); 314 g_undiff1->size = size; 315 g_undiff1->id = 1; 316 g_undiff1->diffed = false; 317 //l = -1; 318 g_undiff2 = changeGameStateABit( g_undiff1, modeChangeData ); 319 320 while( compareData2( g_undiff1, g_undiff2 ) ) { 321 delete g_undiff2->data; 322 g_undiff2 = changeGameStateABit( g_undiff1, modeChangeData ); 323 } 324 //l = -2; 325 g_diffed = g_manager->testDiff( g_undiff1, g_undiff2 ); 326 gc = g_manager->testCompress( g_diffed ); 327 g_resultDiffed = g_client->testDecompress( gc ); 328 329 if ( !compareGameStates( g_resultDiffed, g_diffed ) ) return false; 330 //l = -3; 331 g_resultUndiffed = g_client->testUndiff( g_undiff1, g_resultDiffed ); 332 if ( !compareGameStates( g_resultUndiffed, g_undiff2 ) ) return false; 333 //l = 1; 334 /*if ( gc != NULL && gc->data != NULL ) 335 delete gc->data; 336 //l = 2; 337 //if ( gc != NULL ) 338 //delete gc; 339 //l = 3; 340 if ( g_undiff1 != NULL && g_undiff1->data != NULL ) 341 delete g_undiff1->data; 342 //l = 4; 343 //if ( g_undiff1 != NULL ) 344 //delete g_undiff1; 345 //l = 5; 346 if ( g_undiff2 != NULL && g_undiff2->data ) 347 delete g_undiff2->data; 348 //l = 6; 349 //if ( g_undiff2 != NULL ) 350 //delete g_undiff2; 351 //l = 7; 352 if ( g_diffed != NULL && g_diffed->data ) 353 //delete g_diffed->data; 354 //l = 8; 355 //if ( g_diffed ) 356 //delete g_diffed; 357 //l = 9; 358 if ( g_resultDiffed != NULL && g_resultDiffed->data ) 359 delete g_resultDiffed->data; 360 //l = 10; 361 //if ( g_resultDiffed ) 362 //delete g_resultDiffed; 363 //l = 11;*/ 364 365 return true; 366 } 367 368 bool testNCompression( int n, int size, int mode ) { 369 GameStateClient* g_client; 370 GameStateManager* g_manager;; 371 372 GameState* g_new = new GameState; 373 GameState* g_old = new GameState; 374 GameStateCompressed* gc = new GameStateCompressed; 375 376 g_old->data = createData( size, mode ); 377 g_old->size = size; 378 g_old->id = 0; 379 g_old->diffed = false; 380 381 gc = g_manager->testCompress( g_old ); 382 383 g_new = g_client->testDecompress( gc ); 384 385 if ( !compareGameStates( g_new, g_old ) ) return false; 386 387 388 if ( g_new != NULL && g_new->data != NULL ) 389 delete g_new->data; 390 391 if ( g_old != NULL && g_old->data != NULL ) 392 delete g_old->data; 393 394 if ( gc != NULL && gc->data ) 395 delete gc->data; 396 397 return true; 288 398 } 289 399 … … 521 631 522 632 int main( int argc, char* argv[] ) { 523 int a,b,c ;633 int a,b,c,n; 524 634 std::string dec = "nothing"; 525 635 std::cout << "############### START TEST (quit q) ###############" << std::endl; … … 527 637 std::cout << "displayModes:\t\t modes" << std::endl; 528 638 std::cout << "testCompression:\t tc [datalength] [mode Data]" << std::endl; 639 std::cout << "testNCompression:\t tnc [#of loops] [datalength] [mode Data]" << std::endl; 529 640 std::cout << "testDifferentiation:\t td [datalength] [mode Data] [mode Change]" << std::endl; 530 641 std::cout << "testCompressWithDiff:\t tcd [datalength] [mode Data] [mode Change]" << std::endl; 642 std::cout << "testNCompressWithDiff:\t tncd [#of loops] [datalength] [mode Data] [mode Change]" << std::endl; 531 643 std::cout << "testClientObjectMapping: tcom [#clients]" << std::endl; 532 644 std::cout << "testClientInformation:\t tci [#clients] (call with >10)" << std::endl; … … 558 670 else if ( dec.compare("tbuf") == 0 ) { 559 671 testPacketBuffer(); 560 } 672 } 673 else if ( dec.compare("tncd") == 0 ) { 674 std::cin >> n; std::cin >> a; std::cin >> b; std::cin >> c; 675 for ( int i=1; i<=n; i++ ) { 676 std::cout << i << " s" << a << " "; 677 //std::cout << "start loop test " << i << std::endl; 678 if ( !testNCompressWithDiff( i, a, b, c ) ) { 679 std::cout << "#COMPARSION ERROR->VERYVERY BAD" << std::endl; 680 break; 681 } 682 } 683 std::cout << "end loop comparsion test" << std::endl; 684 } 685 else if ( dec.compare("tnc") == 0 ) { 686 std::cin >> n; std::cin >> a; std::cin >> b; 687 for ( int i=1; i<=n; i++ ) { 688 std::cout << i << " s" << a << " "; 689 //std::cout << "start loop test " << i << std::endl; 690 if ( !testNCompression( i, a, b ) ) { 691 std::cout << "#COMPARSION ERROR->VERYVERY BAD" << std::endl; 692 break; 693 } 694 } 695 std::cout << "end loop comparsion test" << std::endl; 696 } 697 else std::cout << "invalid input" << std::endl; 561 698 std::cout << "################## END ONE TURN ##################@" << std::endl; 562 699 }
Note: See TracChangeset
for help on using the changeset viewer.