Changeset 366 for trunk/src/cutest_zAVLTree.c
- Timestamp:
- Oct 30, 2011, 9:03:25 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cutest_zAVLTree.c
r363 r366 8 8 struct ztest { 9 9 char name[32]; 10 int iname; 10 11 }; 11 12 … … 18 19 } 19 20 21 static zAVLKey ztest_intkey(void const *item) 22 { 23 return (&((struct ztest *)item)->iname); 24 } 25 26 20 27 static void free_node (void * inptr) 21 28 { 22 29 struct ztest * ptr = (struct ztest *) inptr; 23 30 ptr->name[0] = '\0'; 31 ptr->iname = 0; 24 32 } 25 33 … … 30 38 int counter = 0; 31 39 32 struct ztest z1 = { "abc" }; 33 struct ztest z2 = { "aac" }; 34 struct ztest z3 = { "aaa1" }; 35 struct ztest z4 = { "aaa3" }; 36 struct ztest z5 = { "aaa2" }; 37 struct ztest z6 = { "aaa6" }; 38 struct ztest z7 = { "aaa5" }; 39 struct ztest z8 = { "aaa4" }; 40 struct ztest z1 = { "abc" , 1 }; 41 struct ztest z2 = { "aac" , 2 }; 42 struct ztest z3 = { "aaa1" , 3 }; 43 struct ztest z4 = { "aaa3" , 4 }; 44 struct ztest z5 = { "aaa2" , 5 }; 45 struct ztest z6 = { "aaa6" , 6 }; 46 struct ztest z7 = { "aaa5" , 7 }; 47 struct ztest z8 = { "aaa4" , 8 }; 48 49 struct ztest iz1 = { "aaa1" , 8 }; 50 struct ztest iz2 = { "aaa2" , 7 }; 51 struct ztest iz3 = { "aaa3" , 1 }; 52 struct ztest iz4 = { "aaa4" , 3 }; 53 struct ztest iz5 = { "aaa5" , 2 }; 54 struct ztest iz6 = { "aaa5" , 6 }; 55 struct ztest iz7 = { "aaa7" , 5 }; 56 struct ztest iz8 = { "aaa8" , 4 }; 40 57 41 58 struct ztest * ptr; … … 245 262 CuAssertTrue (tc, z7.name[0] == '\0'); 246 263 CuAssertTrue (tc, z8.name[0] == '\0'); 264 265 266 /* Numeric key here */ 267 268 counter = 0; 269 ztest_tree = NULL; 270 271 ptr = zAVLFirst(&cursor, ztest_tree); 272 CuAssertTrue(tc, NULL == ptr); 273 274 ztest_tree = zAVLAllocTree (ztest_intkey, zAVL_KEY_INT); 275 CuAssertPtrNotNull(tc, ztest_tree); 276 277 do { 278 279 ++counter; 280 281 result = zAVLInsert(ztest_tree, &iz1); 282 CuAssertTrue(tc, 0 == result); 283 result = zAVLInsert(ztest_tree, &iz2); 284 CuAssertTrue(tc, 0 == result); 285 result = zAVLInsert(ztest_tree, &iz3); 286 CuAssertTrue(tc, 0 == result); 287 result = zAVLInsert(ztest_tree, &iz4); 288 CuAssertTrue(tc, 0 == result); 289 result = zAVLInsert(ztest_tree, &iz5); 290 CuAssertTrue(tc, 0 == result); 291 result = zAVLInsert(ztest_tree, &iz6); 292 CuAssertTrue(tc, 0 == result); 293 result = zAVLInsert(ztest_tree, &iz7); 294 CuAssertTrue(tc, 0 == result); 295 result = zAVLInsert(ztest_tree, &iz8); 296 CuAssertTrue(tc, 0 == result); 297 298 ptr = zAVLFirst(&cursor, ztest_tree); 299 CuAssertStrEquals(tc, ptr->name, iz3.name); 300 ptr = zAVLNext(&cursor); 301 CuAssertStrEquals(tc, ptr->name, iz5.name); 302 ptr = zAVLNext(&cursor); 303 CuAssertStrEquals(tc, ptr->name, iz4.name); 304 ptr = zAVLNext(&cursor); 305 CuAssertStrEquals(tc, ptr->name, iz8.name); 306 ptr = zAVLNext(&cursor); 307 CuAssertStrEquals(tc, ptr->name, iz7.name); 308 ptr = zAVLNext(&cursor); 309 CuAssertStrEquals(tc, ptr->name, iz6.name); 310 ptr = zAVLNext(&cursor); 311 CuAssertStrEquals(tc, ptr->name, iz2.name); 312 ptr = zAVLNext(&cursor); 313 CuAssertStrEquals(tc, ptr->name, iz1.name); 314 ptr = zAVLNext(&cursor); 315 CuAssertTrue(tc, NULL == ptr); 316 317 result = zAVLInsert(ztest_tree, &iz8); 318 CuAssertTrue(tc, 0 != result); 319 result = zAVLInsert(ztest_tree, &iz7); 320 CuAssertTrue(tc, 0 != result); 321 result = zAVLInsert(ztest_tree, &iz6); 322 CuAssertTrue(tc, 0 != result); 323 result = zAVLInsert(ztest_tree, &iz5); 324 CuAssertTrue(tc, 0 != result); 325 326 ptr = zAVLSearch(ztest_tree, &(iz1.iname)); 327 CuAssertIntEquals(tc, ptr->iname, iz1.iname); 328 ptr = zAVLSearch(ztest_tree, &(iz2.iname)); 329 CuAssertIntEquals(tc, ptr->iname, iz2.iname); 330 ptr = zAVLSearch(ztest_tree, &(iz3.iname)); 331 CuAssertIntEquals(tc, ptr->iname, iz3.iname); 332 ptr = zAVLSearch(ztest_tree, &(iz6.iname)); 333 CuAssertIntEquals(tc, ptr->iname, iz6.iname); 334 ptr = zAVLSearch(ztest_tree, &(iz4.iname)); 335 CuAssertIntEquals(tc, ptr->iname, iz4.iname); 336 337 ptr = zAVLSearch(ztest_tree, &(iz2.iname)); 338 CuAssertIntEquals(tc, ptr->iname, iz2.iname); 339 ptr = zAVLSearch(ztest_tree, &(iz3.iname)); 340 CuAssertIntEquals(tc, ptr->iname, iz3.iname); 341 ptr = zAVLSearch(ztest_tree, &(iz7.iname)); 342 CuAssertIntEquals(tc, ptr->iname, iz7.iname); 343 344 ptr = zAVLFirst(&cursor, ztest_tree); 345 CuAssertStrEquals(tc, ptr->name, iz3.name); 346 ptr = zAVLNext(&cursor); 347 CuAssertStrEquals(tc, ptr->name, iz5.name); 348 ptr = zAVLNext(&cursor); 349 CuAssertStrEquals(tc, ptr->name, iz4.name); 350 ptr = zAVLNext(&cursor); 351 CuAssertStrEquals(tc, ptr->name, iz8.name); 352 ptr = zAVLNext(&cursor); 353 CuAssertStrEquals(tc, ptr->name, iz7.name); 354 ptr = zAVLNext(&cursor); 355 CuAssertStrEquals(tc, ptr->name, iz6.name); 356 ptr = zAVLNext(&cursor); 357 CuAssertStrEquals(tc, ptr->name, iz2.name); 358 ptr = zAVLNext(&cursor); 359 CuAssertStrEquals(tc, ptr->name, iz1.name); 360 ptr = zAVLNext(&cursor); 361 CuAssertTrue(tc, NULL == ptr); 362 363 364 ptr = zAVLSearch(ztest_tree, &(iz5.iname)); 365 CuAssertStrEquals(tc, ptr->name, iz5.name); 366 ptr = zAVLSearch(ztest_tree, &(iz6.iname)); 367 CuAssertStrEquals(tc, ptr->name, iz6.name); 368 ptr = zAVLSearch(ztest_tree, &(iz7.iname)); 369 CuAssertStrEquals(tc, ptr->name, iz7.name); 370 ptr = zAVLSearch(ztest_tree, &(iz8.iname)); 371 CuAssertStrEquals(tc, ptr->name, iz8.name); 372 ptr = zAVLSearch(ztest_tree, &(z1.iname)); /* been set to 0 */ 373 CuAssertTrue(tc, NULL == ptr); 374 375 result = zAVLDelete(ztest_tree, &(iz8.iname)); 376 CuAssertTrue(tc, 0 == result); 377 ptr = zAVLSearch(ztest_tree, &(iz8.iname)); 378 CuAssertTrue(tc, NULL == ptr); 379 380 result = zAVLDelete(ztest_tree, &(iz3.iname)); 381 CuAssertTrue(tc, 0 == result); 382 ptr = zAVLSearch(ztest_tree, &(iz3.iname)); 383 CuAssertTrue(tc, NULL == ptr); 384 385 result = zAVLDelete(ztest_tree, &(iz1.iname)); 386 CuAssertTrue(tc, 0 == result); 387 ptr = zAVLSearch(ztest_tree, &(iz1.iname)); 388 CuAssertTrue(tc, NULL == ptr); 389 390 result = zAVLInsert(ztest_tree, &iz1); 391 CuAssertTrue(tc, 0 == result); 392 result = zAVLInsert(ztest_tree, &iz8); 393 CuAssertTrue(tc, 0 == result); 394 result = zAVLInsert(ztest_tree, &iz3); 395 CuAssertTrue(tc, 0 == result); 396 397 ptr = zAVLFirst(&cursor, ztest_tree); 398 CuAssertIntEquals(tc, ptr->iname, iz3.iname); 399 ptr = zAVLNext(&cursor); 400 CuAssertStrEquals(tc, ptr->name, iz5.name); 401 ptr = zAVLNext(&cursor); 402 CuAssertStrEquals(tc, ptr->name, iz4.name); 403 ptr = zAVLNext(&cursor); 404 CuAssertIntEquals(tc, ptr->iname, iz8.iname); 405 ptr = zAVLNext(&cursor); 406 CuAssertStrEquals(tc, ptr->name, iz7.name); 407 ptr = zAVLNext(&cursor); 408 CuAssertStrEquals(tc, ptr->name, iz6.name); 409 ptr = zAVLNext(&cursor); 410 CuAssertIntEquals(tc, ptr->iname, iz2.iname); 411 ptr = zAVLNext(&cursor); 412 CuAssertStrEquals(tc, ptr->name, iz1.name); 413 ptr = zAVLNext(&cursor); 414 CuAssertTrue(tc, NULL == ptr); 415 416 result = zAVLDelete(ztest_tree, &(iz1.iname)); 417 CuAssertTrue(tc, 0 == result); 418 ptr = zAVLSearch(ztest_tree, &(iz1.iname)); 419 CuAssertTrue(tc, NULL == ptr); 420 421 result = zAVLDelete(ztest_tree, &(iz2.iname)); 422 CuAssertTrue(tc, 0 == result); 423 ptr = zAVLSearch(ztest_tree, &(iz2.iname)); 424 CuAssertTrue(tc, NULL == ptr); 425 426 result = zAVLDelete(ztest_tree, &(iz3.iname)); 427 CuAssertTrue(tc, 0 == result); 428 ptr = zAVLSearch(ztest_tree, &(iz3.iname)); 429 CuAssertTrue(tc, NULL == ptr); 430 431 result = zAVLDelete(ztest_tree, &(iz4.iname)); 432 CuAssertTrue(tc, 0 == result); 433 ptr = zAVLSearch(ztest_tree, &(iz4.iname)); 434 CuAssertTrue(tc, NULL == ptr); 435 436 result = zAVLDelete(ztest_tree, &(iz5.iname)); 437 CuAssertTrue(tc, 0 == result); 438 ptr = zAVLSearch(ztest_tree, &(iz5.iname)); 439 CuAssertTrue(tc, NULL == ptr); 440 441 result = zAVLDelete(ztest_tree, &(iz6.iname)); 442 CuAssertTrue(tc, 0 == result); 443 ptr = zAVLSearch(ztest_tree, &(iz6.iname)); 444 CuAssertTrue(tc, NULL == ptr); 445 446 result = zAVLDelete(ztest_tree, &(iz7.iname)); 447 CuAssertTrue(tc, 0 == result); 448 ptr = zAVLSearch(ztest_tree, &(iz7.iname)); 449 CuAssertTrue(tc, NULL == ptr); 450 451 result = zAVLDelete(ztest_tree, &(iz8.iname)); 452 CuAssertTrue(tc, 0 == result); 453 ptr = zAVLSearch(ztest_tree, &(iz8.iname)); 454 CuAssertTrue(tc, NULL == ptr); 455 456 } while (counter < 100); 457 458 result = zAVLInsert(ztest_tree, &iz1); 459 CuAssertTrue(tc, 0 == result); 460 result = zAVLInsert(ztest_tree, &iz2); 461 CuAssertTrue(tc, 0 == result); 462 result = zAVLInsert(ztest_tree, &iz3); 463 CuAssertTrue(tc, 0 == result); 464 result = zAVLInsert(ztest_tree, &iz4); 465 CuAssertTrue(tc, 0 == result); 466 result = zAVLInsert(ztest_tree, &iz5); 467 CuAssertTrue(tc, 0 == result); 468 result = zAVLInsert(ztest_tree, &iz6); 469 CuAssertTrue(tc, 0 == result); 470 result = zAVLInsert(ztest_tree, &iz7); 471 CuAssertTrue(tc, 0 == result); 472 result = zAVLInsert(ztest_tree, &iz8); 473 CuAssertTrue(tc, 0 == result); 474 475 zAVLFreeTree (ztest_tree, free_node); 476 CuAssertTrue (tc, iz1.iname == 0); 477 CuAssertTrue (tc, iz2.iname == 0); 478 CuAssertTrue (tc, iz3.iname == 0); 479 CuAssertTrue (tc, iz4.iname == 0); 480 CuAssertTrue (tc, iz5.iname == 0); 481 CuAssertTrue (tc, iz6.iname == 0); 482 CuAssertTrue (tc, iz7.iname == 0); 483 CuAssertTrue (tc, iz8.iname == 0); 484 485 247 486 }
Note:
See TracChangeset
for help on using the changeset viewer.