Changeset 7d51ef8 for tests/list/dlist-insert-remove-2.cfa
- Timestamp:
- May 11, 2021, 9:52:18 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1e5cd9a, 67b421c
- Parents:
- 8d1ad36
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/list/dlist-insert-remove-2.cfa
r8d1ad36 r7d51ef8 55 55 //////////////////////////////////////////////////////////// 56 56 57 void printMyFredsFwd(diref(fred, fred.mine) f) { 57 void printMyFredsFwd(fred & f) { 58 with( DLINK_VIA( fred, fred.mine ) ) 58 59 do { 59 60 sout | f.adatum; … … 61 62 } 62 63 63 void printMyFredsRev(diref(fred, fred.mine) f) { 64 void printMyFredsRev(fred & f) { 65 with( DLINK_VIA( fred, fred.mine ) ) 64 66 do { 65 67 sout | f.adatum; … … 75 77 } 76 78 if (&f1) { 77 printMyFredsFwd(f1 `from); sout | '-';78 printMyFredsRev(f1 `from); sout | '-';79 printMyFredsFwd(f1); sout | '-'; 80 printMyFredsRev(f1); sout | '-'; 79 81 } else { 80 82 sout | '-'; sout | '-'; 81 83 } 82 84 if (&f2) { 83 printMyFredsFwd(f2 `from); sout | '-';84 printMyFredsRev(f2 `from); sout | '-';85 printMyFredsFwd(f2); sout | '-'; 86 printMyFredsRev(f2); sout | '-'; 85 87 } else { 86 88 sout | '-'; sout | '-'; … … 88 90 } 89 91 90 void printYourFredsFwd(diref(fred, fred.yours) f) { 92 void printYourFredsFwd(fred & f) { 93 with( DLINK_VIA( fred, fred.yours ) ) 91 94 do { 92 95 sout | f.adatum; … … 94 97 } 95 98 96 void printYourFredsRev(diref(fred, fred.yours) f) { 99 void printYourFredsRev(fred & f) { 100 with( DLINK_VIA( fred, fred.yours ) ) 97 101 do { 98 102 sout | f.adatum; … … 107 111 } 108 112 if (&f1) { 109 printYourFredsFwd(f1 `from); sout | '-';110 printYourFredsRev(f1 `from); sout | '-';113 printYourFredsFwd(f1); sout | '-'; 114 printYourFredsRev(f1); sout | '-'; 111 115 } else { 112 116 sout | '-'; sout | '-'; 113 117 } 114 118 if (&f2) { 115 printYourFredsFwd(f2 `from); sout | '-';116 printYourFredsRev(f2 `from); sout | '-';119 printYourFredsFwd(f2); sout | '-'; 120 printYourFredsRev(f2); sout | '-'; 117 121 } else { 118 122 sout | '-'; sout | '-'; … … 275 279 // All three tests exercise the case of creating an empty container and 276 280 // adding two items to it. 277 278 281 void test__insertfirst_two_on_empty__fred_mine() { 279 282 … … 317 320 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 318 321 } 319 320 322 void test__insertfirst_two_on_empty__mary() { 321 323 … … 323 325 mary m2 = {0.5}; 324 326 325 dlist(mary , mary) lm;327 dlist(mary) lm; 326 328 327 329 verify(validate(lm)); … … 392 394 mary m2 = {0.5}; 393 395 394 dlist(mary , mary) lm;396 dlist(mary) lm; 395 397 396 398 verify(validate(lm)); … … 421 423 dlist(fred, fred.mine) lf; 422 424 423 assert( ! lf`first);424 assert( ! lf`last);425 assert( & lf`first == 0p ); 426 assert( & lf`last == 0p ); 425 427 426 428 insert_first(lf, f1); 427 429 428 assert( DUMB_COMPARE(lf`first, & f1));429 assert( DUMB_COMPARE(lf`last , & f1));430 assert( & lf`first == & f1 ); 431 assert( & lf`last == & f1 ); 430 432 431 433 verify(validate(lf)); 432 434 433 diref(fred, fred.mine) f1_mine = f1`from; 434 insert_after(f1_mine, f2); 435 with ( DLINK_VIA(fred, fred.mine) ) insert_after(f1, f2); 435 436 436 437 verify(validate(lf)); … … 439 440 printYourFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) 440 441 441 assert( DUMB_COMPARE(lf`first, & f1));442 assert( DUMB_COMPARE(lf`last , & f2));442 assert( & lf`first == & f1 ); 443 assert( & lf`last == & f2 ); 443 444 } 444 445 … … 450 451 dlist(fred, fred.yours) lf; 451 452 452 assert( ! lf`first);453 assert( ! lf`last);453 assert( & lf`first == 0p ); 454 assert( & lf`last == 0p ); 454 455 455 456 insert_first(lf, f1); 456 457 457 assert( DUMB_COMPARE(lf`first, & f1));458 assert( DUMB_COMPARE(lf`last , & f1));458 assert( & lf`first == & f1 ); 459 assert( & lf`last == & f1 ); 459 460 460 461 verify(validate(lf)); 461 462 462 diref(fred, fred.yours) f1_yours = f1`from; 463 insert_after(f1_yours, f2); 463 with ( DLINK_VIA(fred, fred.yours) ) insert_after(f1, f2); 464 464 465 465 verify(validate(lf)); … … 468 468 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 469 469 470 assert( DUMB_COMPARE(lf`first, & f1));471 assert( DUMB_COMPARE(lf`last , & f2));470 assert( & lf`first == & f1 ); 471 assert( & lf`last == & f2 ); 472 472 } 473 473 … … 477 477 mary m2 = {0.5}; 478 478 479 dlist(mary , mary) lm;480 481 assert( ! lm`first);482 assert( ! lm`last);479 dlist(mary) lm; 480 481 assert( & lm`first == 0p ); 482 assert( & lm`last == 0p ); 483 483 484 484 insert_first(lm, m1); 485 485 486 assert( DUMB_COMPARE(lm`first, & m1));487 assert( DUMB_COMPARE(lm`last , & m1));486 assert( & lm`first == & m1 ); 487 assert( & lm`last == & m1 ); 488 488 489 489 verify(validate(lm)); … … 495 495 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 496 496 497 assert( DUMB_COMPARE(lm`first, & m1));498 assert( DUMB_COMPARE(lm`last , & m2));497 assert( & lm`first == & m1 ); 498 assert( & lm`last == & m2 ); 499 499 } 500 500 … … 516 516 dlist(fred, fred.mine) lf; 517 517 518 assert( ! lf`first);519 assert( ! lf`last);518 assert( & lf`first == 0p ); 519 assert( & lf`last == 0p ); 520 520 521 521 insert_last(lf, f2); 522 522 523 assert( DUMB_COMPARE(lf`first, & f2));524 assert( DUMB_COMPARE(lf`last , & f2));523 assert( & lf`first == & f2 ); 524 assert( & lf`last == & f2 ); 525 525 526 526 verify(validate(lf)); 527 527 528 diref(fred, fred.mine) f2_mine = f2`from; 529 insert_before(f2_mine, f1); 528 with ( DLINK_VIA(fred, fred.mine) ) insert_before(f2, f1); 530 529 531 530 verify(validate(lf)); … … 534 533 printYourFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) 535 534 536 assert( DUMB_COMPARE(lf`first, & f1));537 assert( DUMB_COMPARE(lf`last , & f2));535 assert( & lf`first == & f1 ); 536 assert( & lf`last == & f2 ); 538 537 } 539 538 … … 545 544 dlist(fred, fred.yours) lf; 546 545 547 assert( ! lf`first);548 assert( ! lf`last);546 assert( & lf`first == 0p ); 547 assert( & lf`last == 0p ); 549 548 550 549 insert_last(lf, f2); 551 550 552 assert( DUMB_COMPARE(lf`first, & f2));553 assert( DUMB_COMPARE(lf`last , & f2));551 assert( & lf`first == & f2 ); 552 assert( & lf`last == & f2 ); 554 553 555 554 verify(validate(lf)); 556 555 557 diref(fred, fred.yours) f2_yours = f2`from; 558 insert_before(f2_yours, f1); 556 with ( DLINK_VIA(fred, fred.yours) )insert_before(f2, f1); 559 557 560 558 verify(validate(lf)); … … 563 561 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 564 562 565 assert( DUMB_COMPARE(lf`first, & f1));566 assert( DUMB_COMPARE(lf`last , & f2));563 assert( & lf`first == & f1 ); 564 assert( & lf`last == & f2 ); 567 565 } 568 566 … … 572 570 mary m2 = {0.5}; 573 571 574 dlist(mary , mary) lm;575 576 assert( ! lm`first);577 assert( ! lm`last);572 dlist(mary) lm; 573 574 assert( & lm`first == 0p ); 575 assert( & lm`last == 0p ); 578 576 579 577 insert_last(lm, m2); 580 578 581 assert( DUMB_COMPARE(lm`first, & m2));582 assert( DUMB_COMPARE(lm`last , & m2));579 assert( & lm`first == & m2 ); 580 assert( & lm`last == & m2 ); 583 581 584 582 verify(validate(lm)); … … 590 588 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 591 589 592 assert(DUMB_COMPARE(lm`first, & m1)); 593 assert(DUMB_COMPARE(lm`last , & m2)); 594 } 595 590 assert( & lm`first == & m1 ); 591 assert( & lm`last == & m2 ); 592 } 596 593 #if 0 597 594 … … 900 897 verify(validate(flm)); 901 898 902 diref(fred, fred.mine) f1_mine = f1`from; 903 remove(f1_mine); 899 with( DLINK_VIA(fred, fred.mine) ) remove(f1); 904 900 905 901 verify(validate(fly)); … … 916 912 // assert(f1.$links_mine.prev.is_terminator == false); 917 913 } 914 918 915 919 916 void test__remove_at_head__fred_yours() { … … 939 936 verify(validate(flm)); 940 937 941 diref(fred, fred.yours) f1_yours = f1`from; 942 remove(f1_yours); 938 with( DLINK_VIA(fred, fred.yours) ) remove(f1); 943 939 944 940 verify(validate(fly)); … … 962 958 mary m3 = {3.7}; 963 959 964 dlist(mary , mary) ml;960 dlist(mary) ml; 965 961 insert_last(ml, m1); 966 962 insert_last(ml, m2); … … 1017 1013 verify(validate(flm)); 1018 1014 1019 diref(fred, fred.mine) f3_mine = f3`from; 1020 remove(f3_mine); 1015 with( DLINK_VIA(fred, fred.mine) ) remove(f3); 1021 1016 1022 1017 verify(validate(fly)); … … 1056 1051 verify(validate(flm)); 1057 1052 1058 diref(fred, fred.yours) f3_yours = f3`from; 1059 remove(f3_yours); 1053 with( DLINK_VIA(fred, fred.yours) ) remove(f3); 1060 1054 1061 1055 verify(validate(fly)); … … 1079 1073 mary m3 = {3.7}; 1080 1074 1081 dlist(mary , mary) ml;1075 dlist(mary) ml; 1082 1076 insert_last(ml, m1); 1083 1077 insert_last(ml, m2); … … 1128 1122 verify(validate(flm)); 1129 1123 1130 diref(fred, fred.mine) f_mine = f`from; 1131 remove(f_mine); 1132 1133 verify(validate(fly)); 1134 verify(validate(flm)); 1135 1136 assert(! flm`first); 1137 assert(! flm`last); 1124 with( DLINK_VIA(fred, fred.mine) ) remove(f); 1125 1126 verify(validate(fly)); 1127 verify(validate(flm)); 1128 1129 assert( & flm`first == 0p ); 1130 assert( & flm`last == 0p ); 1138 1131 1139 1132 printYourFreddies(fly`first, fly`last, 0); // 0.7; 0.7; 0.7; 0.7 (unmodified) … … 1168 1161 verify(validate(flm)); 1169 1162 1170 diref(fred, fred.yours) f_yours = f`from; 1171 remove(f_yours); 1172 1173 verify(validate(fly)); 1174 verify(validate(flm)); 1175 1176 assert(! fly`first); 1177 assert(! fly`last); 1163 with( DLINK_VIA(fred, fred.yours) ) remove(f); 1164 1165 verify(validate(fly)); 1166 verify(validate(flm)); 1167 1168 assert( & fly`first == 0p ); 1169 assert( & fly`last == 0p ); 1178 1170 1179 1171 printYourFreddies(flm`first, flm`last, 0); // 0.7; 0.7; 0.7; 0.7 (unmodified) … … 1196 1188 mary m = {0.7}; 1197 1189 1198 dlist(mary , mary) ml;1190 dlist(mary) ml; 1199 1191 insert_last(ml, m); 1200 1192 … … 1207 1199 verify(validate(ml)); 1208 1200 1209 assert( ! ml`first);1210 assert( ! ml`last);1201 assert( & ml`first == 0p ); 1202 assert( & ml`last == 0p ); 1211 1203 1212 1204 // observe f is solo in mine (now unlisted); in yours, it was just traversed … … 1256 1248 verify(validate(flm)); 1257 1249 1258 fred & popped = remove(flm`first);1250 fred & popped = try_pop_front(flm); 1259 1251 1260 1252 verify(validate(fly)); … … 1292 1284 verify(validate(flm)); 1293 1285 1294 fred & popped = remove(fly`first);1286 fred & popped = try_pop_front(fly); 1295 1287 1296 1288 verify(validate(fly)); … … 1312 1304 mary m3 = {3.7}; 1313 1305 1314 dlist(mary , mary) ml;1306 dlist(mary) ml; 1315 1307 insert_last(ml, m1); 1316 1308 insert_last(ml, m2); … … 1321 1313 verify(validate(ml)); 1322 1314 1323 mary & popped = remove(ml`first);1315 mary & popped = try_pop_front(ml); 1324 1316 1325 1317 verify(validate(ml)); … … 1355 1347 verify(validate(flm)); 1356 1348 1357 fred & popped = remove(flm`last);1349 fred & popped = try_pop_back(flm); 1358 1350 1359 1351 verify(validate(fly)); … … 1391 1383 verify(validate(flm)); 1392 1384 1393 fred & popped = remove(fly`last);1385 fred & popped = try_pop_back(fly); 1394 1386 1395 1387 verify(validate(fly)); … … 1411 1403 mary m3 = {3.7}; 1412 1404 1413 dlist(mary , mary) ml;1405 dlist(mary) ml; 1414 1406 insert_last(ml, m1); 1415 1407 insert_last(ml, m2); … … 1420 1412 verify(validate(ml)); 1421 1413 1422 mary & popped = remove(ml`last);1414 mary & popped = try_pop_back(ml); 1423 1415 1424 1416 verify(validate(ml)); … … 1431 1423 assert( &popped == &m3 ); 1432 1424 } 1433 1434 1425 1435 1426 //////////////////////////////////////////////////////////// … … 1450 1441 mary m3 = {3.7}; 1451 1442 1452 dlist(mary , mary) ml;assert( ml`isEmpty);1443 dlist(mary) ml; assert( ml`isEmpty); 1453 1444 1454 1445 insert_last(ml, m1); assert(!ml`isEmpty); … … 1486 1477 mary m3 = {3.7}; 1487 1478 1488 dlist(mary , mary) ml;1479 dlist(mary) ml; 1489 1480 1490 1481 mary &m1r = *0p; … … 1588 1579 mary m1 = {1.7}; 1589 1580 1590 dlist(mary , mary) ml;1581 dlist(mary) ml; 1591 1582 mary & mlorigin = ml`elems; 1592 1583
Note: See TracChangeset
for help on using the changeset viewer.