1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905
|
# -*- tcl -*-
# graph.test: tests for the graph structure.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands. Sourcing this file into Tcl runs the tests and
# generates output for errors. No output means no errors were found.
#
# Copyright (c) 1998-2000 by Ajuba Solutions.
# All rights reserved.
#
# RCS: @(#) $Id: graph1.test,v 1.10 2009/11/03 17:38:30 andreas_kupries Exp $
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.2
testsNeedTcltest 1.0
testing {
useLocal graph1.tcl struct::graph
}
# ---------------------------------------------------
test graph1-0.1 {graph errors} {
struct::graph mygraph
catch {struct::graph mygraph} msg
mygraph destroy
set msg
} "command \"mygraph\" already exists, unable to create graph"
test graph1-0.2 {graph errors} {
struct::graph mygraph
catch {mygraph} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph option ?arg arg ...?\""
test graph1-0.3 {graph errors} {
struct::graph mygraph
catch {mygraph foo} msg
mygraph destroy
set msg
} "bad option \"foo\": must be arc, arcs, destroy, get, getall, keys, keyexists, node, nodes, set, swap, unset, or walk"
test graph1-0.4 {graph errors} {
catch {struct::graph set} msg
set msg
} "command \"set\" already exists, unable to create graph"
test graph1-0.5 {graph errors} {
struct::graph mygraph
catch {mygraph arc foo} msg
mygraph destroy
set msg
} "bad option \"foo\": must be append, delete, exists, get, getall, insert, keys, keyexists, lappend, set, source, target, or unset"
test graph1-0.6 {graph errors} {
struct::graph mygraph
catch {mygraph node foo} msg
mygraph destroy
set msg
} "bad option \"foo\": must be append, degree, delete, exists, get, getall, insert, keys, keyexists, lappend, opposite, set, or unset"
# ---------------------------------------------------
test graph1-1.1 {create} {
struct::graph mygraph
set result [string equal [info commands ::mygraph] "::mygraph"]
mygraph destroy
set result
} 1
test graph1-1.2 {create} {
set name [struct::graph]
set result [list $name [string equal [info commands ::$name] "::$name"]]
$name destroy
set result
} [list graph1 1]
test graph1-1.3 {destroy} {
struct::graph mygraph
mygraph destroy
string equal [info commands ::mygraph] ""
} 1
# ---------------------------------------------------
test graph1-2.1 {arc delete} {
struct::graph mygraph
catch {mygraph arc delete arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-2.2 {arc delete} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc delete arc0
set result [mygraph arc exists arc0]
mygraph destroy
set result
} {0}
# ---------------------------------------------------
test graph1-3.1 {arc exists} {
struct::graph mygraph
set result [list]
lappend result [mygraph arc exists arc1]
mygraph node insert node1
mygraph node insert node2
mygraph arc insert node1 node2 arc1
lappend result [mygraph arc exists arc1]
mygraph arc delete arc1
lappend result [mygraph arc exists arc1]
mygraph destroy
set result
} {0 1 0}
# ---------------------------------------------------
test graph1-4.1 {arc get gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc get arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-4.2 {arc get gives error on bogus key} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc get arc0 -key bogus} msg
mygraph destroy
set msg
} "invalid key \"bogus\" for arc \"arc0\""
test graph1-4.3 {arc get uses data as default key} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 foobar
set result [mygraph arc get arc0]
mygraph destroy
set result
} "foobar"
test graph1-4.4 {arc get respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key boom foobar
set result [mygraph arc get arc0 -key boom]
mygraph destroy
set result
} "foobar"
# ---------------------------------------------------
test graph1-5.1 {arc insert gives error on duplicate arc name} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc insert node0 node1 arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" already exists in graph \"mygraph\""
test graph1-5.2 {arc insert creates and initializes arc} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [list ]
lappend result [mygraph arc exists arc0]
lappend result [mygraph arc source arc0]
lappend result [mygraph arc target arc0]
lappend result [mygraph arc set arc0]
mygraph destroy
set result
} {1 node0 node1 {}}
test graph1-5.3 {arc insert arcs in correct location} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc insert node0 node1 arc1
mygraph arc insert node0 node1 arc2
set result [lsort [mygraph arcs -out node0]]
mygraph destroy
set result
} {arc0 arc1 arc2}
test graph1-5.4 {arc insert gives error when trying to insert to a fake node} {
struct::graph mygraph
catch {mygraph arc insert node0 node1 arc0} msg
mygraph destroy
set msg
} "source node \"node0\" does not exist in graph \"mygraph\""
test graph1-5.5 {arc insert gives error when trying to insert to a fake node} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph arc insert node0 node1 arc0} msg
mygraph destroy
set msg
} "target node \"node1\" does not exist in graph \"mygraph\""
test graph1-5.6 {arc insert generates arc name when none is given} {
struct::graph mygraph
mygraph node insert n0
set result [list [mygraph arc insert n0 n0]]
lappend result [mygraph arc insert n0 n0]
mygraph arc insert n0 n0 arc3
lappend result [mygraph arc insert n0 n0]
mygraph destroy
set result
} [list arc1 arc2 arc4]
if {0} {
# if feature used, fix this test...
test graph1-5.6 {arc insert generates arc name when none is given} {
struct::graph mygraph
set result [list [mygraph insert root end]]
lappend result [mygraph insert root end]
mygraph insert root end arc3
lappend result [mygraph insert root end]
mygraph destroy
set result
} [list arc1 arc2 arc4] ; # {}
}
# ---------------------------------------------------
test graph1-6.1 {arc set gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc set arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-6.2 {arc set with arc name gets/sets "data" value} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 foobar
set result [mygraph arc set arc0]
mygraph destroy
set result
} "foobar"
test graph1-6.3 {arc set with arc name and key gets/sets key value} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key baz foobar
set result [list [mygraph arc set arc0] [mygraph arc set arc0 -key baz]]
mygraph destroy
set result
} [list "" "foobar"]
test graph1-6.4 {arc set with too many args gives error} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc set arc0 foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph arc set arc0 ?-key key? ?value?\""
test graph1-6.5 {arc set with bad args} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc set arc0 foo bar} msg
mygraph destroy
set msg
} "invalid option \"foo\": should be key"
test graph1-6.6 {arc set with bad args} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc set arc0 foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"foo\": should be key"
test graph1-6.7 {arc set with bad key gives error} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc set arc0 -key foo} msg
mygraph destroy
set msg
} "invalid key \"foo\" for arc \"arc0\""
# ---------------------------------------------------
test graph1-7.1 {arc source gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc source arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-7.2 {arc source} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [mygraph arc source arc0]
mygraph destroy
set result
} node0
# ---------------------------------------------------
test graph1-8.1 {arc target gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc target arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-8.2 {arc target} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [mygraph arc target arc0]
mygraph destroy
set result
} node1
# ---------------------------------------------------
test graph1-9.1 {arc unset gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc unset arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-9.2 {arc unset does not give error on bogus key} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [catch {mygraph arc unset arc0 -key bogus}]
mygraph destroy
set result
} 0
test graph1-9.3 {arc unset removes a keyed value from a arc} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key foobar foobar
mygraph arc unset arc0 -key foobar
catch {mygraph arc get arc0 -key foobar} msg
mygraph destroy
set msg
} "invalid key \"foobar\" for arc \"arc0\""
test graph1-9.4 {arc unset requires -key} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key foobar foobar
catch {mygraph arc unset arc0 flaboozle foobar} msg
mygraph destroy
set msg
} "invalid option \"flaboozle\": should be \"mygraph arc unset arc0 ?-key key?\""
# ---------------------------------------------------
test graph1-10.1 {arcs} {
struct::graph mygraph
set result [mygraph arcs]
mygraph destroy
set result
} {}
test graph1-10.2 {arcs} {
struct::graph mygraph
catch {mygraph arcs -foo} msg
mygraph destroy
set msg
} {invalid restriction "-foo": should be -in, -out, -adj, -inner, -embedding, -key or -value}
test graph1-10.3 {arcs} {
struct::graph mygraph
catch {mygraph arcs -in} msg
mygraph destroy
set msg
} {no nodes specified: should be "mygraph arcs ?-key key? ?-value value? ?-in|-out|-adj|-inner|-embedding node node...?"}
test graph1-10.4 {arcs} {
struct::graph mygraph
catch {mygraph arcs -in node0} msg
mygraph destroy
set msg
} {node "node0" does not exist in graph "mygraph"}
test graph1-10.5 {arcs} {
struct::graph mygraph
mygraph node insert node1
mygraph node insert node2
mygraph node insert node3
mygraph node insert node4
mygraph node insert node5
mygraph node insert node6
mygraph arc insert node4 node1 arcA
mygraph arc insert node5 node2 arcB
mygraph arc insert node6 node3 arcC
mygraph arc insert node3 node1 arcD
mygraph arc insert node1 node2 arcE
mygraph arc insert node2 node3 arcF
set result [list \
[lsort [mygraph arcs ]] \
\
[lsort [mygraph arcs -in node1 node2 node3]] \
[lsort [mygraph arcs -out node1 node2 node3]] \
[lsort [mygraph arcs -adj node1 node2 node3]] \
[lsort [mygraph arcs -inner node1 node2 node3]] \
[lsort [mygraph arcs -embedding node1 node2 node3]] \
\
[lsort [mygraph arcs -in node4 node5 node6]] \
[lsort [mygraph arcs -out node4 node5 node6]] \
[lsort [mygraph arcs -adj node4 node5 node6]] \
[lsort [mygraph arcs -inner node4 node5 node6]] \
[lsort [mygraph arcs -embedding node4 node5 node6]] \
]
mygraph destroy
set result
} [list \
{arcA arcB arcC arcD arcE arcF} \
\
{arcA arcB arcC arcD arcE arcF} \
{arcD arcE arcF} \
{arcA arcB arcC arcD arcE arcF} \
{arcD arcE arcF} \
{arcA arcB arcC} \
\
{} \
{arcA arcB arcC} \
{arcA arcB arcC} \
{} \
{arcA arcB arcC} \
]
test graph1-10.6 {arcs} {
struct::graph mygraph
mygraph node insert node1
mygraph node insert node2
mygraph arc insert node1 node2 arcE
mygraph arc insert node2 node1 arcF
set result [lsort [mygraph arcs -adj node1 node2]]
mygraph destroy
set result
} {arcE arcF}
test graph1-10.7 {arcs} {
struct::graph mygraph
mygraph node insert n0
mygraph node insert n1
mygraph arc insert n0 n1 a1
mygraph arc insert n0 n1 a2
mygraph arc set a1 -key foobar 1
mygraph arc set a2 -key blubber 2
catch {mygraph arcs -key foobar} msg
mygraph destroy
set msg
} {a1}
test graph1-10.8 {arcs} {
struct::graph mygraph
mygraph node insert n0
mygraph node insert n1
mygraph arc insert n0 n1 a1
mygraph arc insert n0 n1 a2
mygraph arc set a1 -key foobar 1
mygraph arc set a2 -key foobar 2
catch {mygraph arcs -key foobar -value 1} msg
mygraph destroy
set msg
} {a1}
test graph1-10.9 {arcs, multiple -key, illegal} {
struct::graph mygraph
catch {mygraph arcs -key foobar -value 1 -key foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-key"}
test graph1-10.10 {arcs, multiple -value, illegal} {
struct::graph mygraph
catch {mygraph arcs -key foobar -value 1 -value foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-value"}
test graph1-10.11 {arcs, multiple -in, illegal} {
struct::graph mygraph
catch {mygraph arcs -key foobar -in -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
test graph1-10.12 {arcs, -in / -out exclusion, illegal} {
struct::graph mygraph
catch {mygraph arcs -key foobar -out -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
# ---------------------------------------------------
test graph1-11.1 {node degree} {
struct::graph mygraph
catch {mygraph node degree} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph node degree ?-in|-out? node\""
test graph1-11.2 {node degree} {
struct::graph mygraph
catch {mygraph node degree foo bar baz} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph node degree ?-in|-out? node\""
test graph1-11.3 {node degree} {
struct::graph mygraph
catch {mygraph node degree node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-11.4 {node degree} {
struct::graph mygraph
catch {mygraph node degree -foo node0} msg
mygraph destroy
set msg
} "invalid option \"-foo\": should be -in or -out"
test graph1-11.5 {node degree} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph node insert node2
mygraph node insert node3
mygraph node insert node4
mygraph node insert node5
mygraph arc insert node1 node2 arc0
mygraph arc insert node3 node3 arc1
mygraph arc insert node4 node5 arc2
mygraph arc insert node4 node5 arc3
mygraph arc insert node4 node5 arc4
mygraph arc insert node5 node2 arc5
set result [list \
[mygraph node degree node0] \
[mygraph node degree -in node0] \
[mygraph node degree -out node0] \
[mygraph node degree node1] \
[mygraph node degree -in node1] \
[mygraph node degree -out node1] \
[mygraph node degree node2] \
[mygraph node degree -in node2] \
[mygraph node degree -out node2] \
[mygraph node degree node3] \
[mygraph node degree -in node3] \
[mygraph node degree -out node3] \
[mygraph node degree node4] \
[mygraph node degree -in node4] \
[mygraph node degree -out node4] \
[mygraph node degree node5] \
[mygraph node degree -in node5] \
[mygraph node degree -out node5] \
]
mygraph destroy
set result
} [list 0 0 0 \
1 0 1 \
2 2 0 \
2 1 1 \
3 0 3 \
4 3 1
]
# ---------------------------------------------------
test graph1-12.1 {node delete} {
struct::graph mygraph
catch {mygraph node delete node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-12.2 {node delete} {
struct::graph mygraph
mygraph node insert node0
mygraph node delete node0
set result [mygraph node exists node0]
mygraph destroy
set result
} {0}
test graph1-12.3 {node delete} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph node delete node0
set result [list \
[mygraph node exists node0] \
[mygraph node exists node1] \
[mygraph arc exists arc0] \
]
mygraph destroy
set result
} {0 1 0}
test graph1-12.4 {node delete} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph node delete node1
set result [list \
[mygraph node exists node0] \
[mygraph node exists node1] \
[mygraph arc exists arc0] \
]
mygraph destroy
set result
} {1 0 0}
# ---------------------------------------------------
test graph1-13.1 {node exists} {
struct::graph mygraph
set result [list]
lappend result [mygraph node exists node1]
mygraph node insert node1
lappend result [mygraph node exists node1]
mygraph node delete node1
lappend result [mygraph node exists node1]
mygraph destroy
set result
} {0 1 0}
# ---------------------------------------------------
test graph1-14.1 {node get gives error on bogus node} {
struct::graph mygraph
catch {mygraph node get node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-14.2 {node get gives error on bogus key} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node get node0 -key bogus} msg
mygraph destroy
set msg
} "invalid key \"bogus\" for node \"node0\""
test graph1-14.3 {node get uses data as default key} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 foobar
set result [mygraph node get node0]
mygraph destroy
set result
} "foobar"
test graph1-14.4 {node get respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key boom foobar
set result [mygraph node get node0 -key boom]
mygraph destroy
set result
} "foobar"
# ---------------------------------------------------
test graph1-15.1 {node insert gives error on duplicate node name} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node insert node0} msg
mygraph destroy
set msg
} "node \"node0\" already exists in graph \"mygraph\""
test graph1-15.2 {node insert creates and initializes node} {
struct::graph mygraph
mygraph node insert node0
set result [list ]
lappend result [mygraph node exists node0]
lappend result [mygraph node set node0]
mygraph destroy
set result
} {1 {}}
test graph1-15.3 {node insert generates node name when none is given} {
struct::graph mygraph
set result [list [mygraph node insert]]
lappend result [mygraph node insert]
mygraph node insert node3
lappend result [mygraph node insert]
mygraph destroy
set result
} [list node1 node2 node4]
if {0} {
# fix if this feature is used ...
test graph1-15.x {node insert generates node name when none is given} {
struct::graph mygraph
set result [list [mygraph node insert root end]]
lappend result [mygraph node insert root end]
mygraph node insert root end node3
lappend result [mygraph node insert root end]
mygraph destroy
set result
} [list node1 node2 node4] ; # {}
}
# ---------------------------------------------------
test graph1-16.1 {node opposite gives error on bogus node} {
struct::graph mygraph
catch {mygraph node opposite node0 arc0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-16.2 {node opposite gives error on bogus arc} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node opposite node0 arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-16.3 {node opposite gives error on bogus node/arc combination} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph node insert node2
mygraph arc insert node1 node2 arc0
catch {mygraph node opposite node0 arc0} msg
mygraph destroy
set msg
} "node \"node0\" and arc \"arc0\" are not connected in graph \"mygraph\""
test graph1-16.4 {node opposite} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [list \
[mygraph node opposite node0 arc0] \
[mygraph node opposite node1 arc0] \
]
mygraph destroy
set result
} {node1 node0}
test graph1-16.5 {node opposite} {
struct::graph mygraph
mygraph node insert node0
mygraph arc insert node0 node0 arc0
set result [mygraph node opposite node0 arc0]
mygraph destroy
set result
} {node0}
# ---------------------------------------------------
test graph1-17.1 {node set gives error on bogus node} {
struct::graph mygraph
catch {mygraph node set node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-17.2 {node set with node name gets/sets "data" value} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 foobar
set result [mygraph node set node0]
mygraph destroy
set result
} "foobar"
test graph1-17.3 {node set with node name and key gets/sets key value} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key baz foobar
set result [list [mygraph node set node0] [mygraph node set node0 -key baz]]
mygraph destroy
set result
} [list "" "foobar"]
test graph1-17.4 {node set with too many args gives error} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node set node0 foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph node set node0 ?-key key? ?value?\""
test graph1-17.5 {node set with bad args} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node set node0 foo bar} msg
mygraph destroy
set msg
} "invalid option \"foo\": should be key"
test graph1-17.6 {node set with bad args} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node set node0 foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"foo\": should be key"
test graph1-17.7 {node set with bad key gives error} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node set node0 -key foo} msg
mygraph destroy
set msg
} "invalid key \"foo\" for node \"node0\""
# ---------------------------------------------------
test graph1-18.1 {node unset gives error on bogus node} {
struct::graph mygraph
catch {mygraph node unset node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-18.2 {node unset does not give error on bogus key} {
struct::graph mygraph
mygraph node insert node0
set result [catch {mygraph node unset node0 -key bogus}]
mygraph destroy
set result
} 0
test graph1-18.3 {node unset removes a keyed value from a node} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key foobar foobar
mygraph node unset node0 -key foobar
catch {mygraph node get node0 -key foobar} msg
mygraph destroy
set msg
} "invalid key \"foobar\" for node \"node0\""
test graph1-18.4 {unset requires -key} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key foobar foobar
catch {mygraph node unset node0 flaboozle foobar} msg
mygraph destroy
set msg
} "invalid option \"flaboozle\": should be \"mygraph node unset node0 ?-key key?\""
# ---------------------------------------------------
test graph1-19.1 {nodes} {
struct::graph mygraph
set result [mygraph nodes]
mygraph destroy
set result
} {}
test graph1-19.2 {nodes} {
struct::graph mygraph
catch {mygraph nodes -foo} msg
mygraph destroy
set msg
} {invalid restriction "-foo": should be -in, -out, -adj, -inner, -embedding, -key or -value}
test graph1-19.3 {nodes} {
struct::graph mygraph
catch {mygraph nodes -in} msg
mygraph destroy
set msg
} {no nodes specified: should be "mygraph nodes ?-key key? ?-value value? ?-in|-out|-adj|-inner|-embedding node node...?"}
test graph1-19.4 {nodes} {
struct::graph mygraph
catch {mygraph nodes -in node0} msg
mygraph destroy
set msg
} {node "node0" does not exist in graph "mygraph"}
test graph1-19.5 {nodes} {
struct::graph mygraph
mygraph node insert node1
mygraph node insert node2
mygraph node insert node3
mygraph node insert node4
mygraph node insert node5
mygraph node insert node6
mygraph arc insert node4 node1 arcA
mygraph arc insert node5 node2 arcB
mygraph arc insert node6 node3 arcC
mygraph arc insert node3 node1 arcD
mygraph arc insert node1 node2 arcE
mygraph arc insert node2 node3 arcF
set result [list \
[lsort [mygraph nodes ]] \
\
[lsort [mygraph nodes -in node1 node2 node3]] \
[lsort [mygraph nodes -out node1 node2 node3]] \
[lsort [mygraph nodes -adj node1 node2 node3]] \
[lsort [mygraph nodes -inner node1 node2 node3]] \
[lsort [mygraph nodes -embedding node1 node2 node3]] \
\
[lsort [mygraph nodes -in node4 node5 node6]] \
[lsort [mygraph nodes -out node4 node5 node6]] \
[lsort [mygraph nodes -adj node4 node5 node6]] \
[lsort [mygraph nodes -inner node4 node5 node6]] \
[lsort [mygraph nodes -embedding node4 node5 node6]] \
]
mygraph destroy
set result
} [list \
{node1 node2 node3 node4 node5 node6} \
\
{node1 node2 node3 node4 node5 node6} \
{node1 node2 node3} \
{node1 node2 node3 node4 node5 node6} \
{node1 node2 node3} \
{node4 node5 node6} \
\
{} \
{node1 node2 node3} \
{node1 node2 node3} \
{} \
{node1 node2 node3} \
]
test graph1-19.6 {nodes} {
struct::graph mygraph
mygraph node insert node1
mygraph node insert node2
mygraph node insert node3
mygraph arc insert node1 node2 arcE
mygraph arc insert node1 node2 arcD
mygraph arc insert node2 node3 arcF
mygraph arc insert node2 node3 arcG
set result [lsort [mygraph nodes -embedding node1 node3]]
mygraph destroy
set result
} {node2}
test graph1-19.7 {nodes} {
struct::graph mygraph
mygraph node insert n0
mygraph node insert n1
mygraph node set n0 -key foobar 1
mygraph node set n1 -key blubber 2
catch {mygraph nodes -key foobar} msg
mygraph destroy
set msg
} {n0}
test graph1-19.8 {nodes} {
struct::graph mygraph
mygraph node insert n0
mygraph node insert n1
mygraph node set n0 -key foobar 1
mygraph node set n1 -key foobar 2
catch {mygraph nodes -key foobar -value 1} msg
mygraph destroy
set msg
} {n0}
test graph1-19.9 {nodes, multiple -keys, illegal} {
struct::graph mygraph
catch {mygraph nodes -key foobar -key 1} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-key"}
test graph1-19.10 {nodes, multiple -value, illegal} {
struct::graph mygraph
catch {mygraph nodes -key foobar -value 1 -value foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-value"}
test graph1-19.11 {nodes, multiple -in, illegal} {
struct::graph mygraph
catch {mygraph nodes -key foobar -in -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
test graph1-19.12 {nodes, -in / -out exclusion, illegal} {
struct::graph mygraph
catch {mygraph nodes -key foobar -out -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
# ---------------------------------------------------
test graph1-20.1 {swap gives error when trying to swap non existant node} {
struct::graph mygraph
catch {mygraph swap node0 node1} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-20.2 {swap gives error when trying to swap non existant node} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph swap node0 node1} msg
mygraph destroy
set msg
} "node \"node1\" does not exist in graph \"mygraph\""
test graph1-20.3 {swap gives error when trying to swap node with self} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph swap node0 node0} msg
mygraph destroy
set msg
} "cannot swap node \"node0\" with itself"
test graph1-20.4 {swap swaps node relationships correctly} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node0.1
mygraph node insert node0.2
mygraph node insert node0.1.1
mygraph node insert node0.1.2
mygraph arc insert node0 node0.1 a1
mygraph arc insert node0 node0.2 a2
mygraph arc insert node0.1 node0.1.1 a3
mygraph arc insert node0.1 node0.1.2 a4
mygraph swap node0 node0.1
set result [list \
[lsort [mygraph nodes -out node0]] \
[lsort [mygraph nodes -out node0.1]] \
]
mygraph destroy
set result
} {{node0.1.1 node0.1.2} {node0 node0.2}}
test graph1-20.5 {swap swaps node relationships correctly} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node0.1
mygraph node insert node0.2
mygraph node insert node0.1.1
mygraph node insert node0.1.2
mygraph arc insert node0 node0.1 a1
mygraph arc insert node0 node0.2 a2
mygraph arc insert node0.1 node0.1.1 a3
mygraph arc insert node0.1 node0.1.2 a4
mygraph swap node0 node0.1.1
set result [list \
[lsort [mygraph nodes -out node0]] \
[lsort [mygraph nodes -out node0.1.1]] \
]
mygraph destroy
set result
} {{} {node0.1 node0.2}}
test graph1-20.6 {swap swaps node relationships correctly} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node0.1
mygraph node insert node0.2
mygraph node insert node0.1.1
mygraph node insert node0.1.2
mygraph arc insert node0 node0.1 a1
mygraph arc insert node0 node0.2 a2
mygraph arc insert node0.1 node0.1.1 a3
mygraph arc insert node0.1 node0.1.2 a4
mygraph swap node0.1 node0
set result [list \
[lsort [mygraph nodes -out node0]] \
[lsort [mygraph nodes -out node0.1]] \
]
mygraph destroy
set result
} {{node0.1.1 node0.1.2} {node0 node0.2}}
test graph1-22.1 {arc getall gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc getall arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-22.2 {arc getall gives error when key specified} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc getall arc0 -key data} msg
mygraph destroy
set msg
} "wrong # args: should be none"
test graph1-22.3 {arc getall with node name returns list of key/value pairs} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 foobar
mygraph arc set arc0 -key other thing
set results [mygraph arc getall arc0]
mygraph destroy
lsort $results
} "data foobar other thing"
test graph1-23.1 {node getall gives error on bogus node} {
struct::graph mygraph
catch {mygraph node getall node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-23.2 {node getall gives error when key specified} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node getall node0 -key data} msg
mygraph destroy
set msg
} "wrong # args: should be none"
test graph1-23.3 {node getall with node name returns list of key/value pairs} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 foobar
mygraph node set node0 -key other thing
set results [mygraph node getall node0]
mygraph destroy
lsort $results
} "data foobar other thing"
test graph1-24.1 {arc keys gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc keys arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-24.2 {arc keys gives error when key specified} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch { mygraph arc keys arc0 -key bogus } msg
mygraph destroy
set msg
} "wrong # args: should be none"
test graph1-24.3 {arc keys with arc name returns list of keys} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key other things
set results [mygraph arc keys arc0]
mygraph destroy
lsort $results
} "data other"
test graph1-25.1 {node keys gives error on bogus node} {
struct::graph mygraph
catch {mygraph node keys node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-25.2 {node keys gives error when key specified} {
struct::graph mygraph
mygraph node insert node0
catch { mygraph node keys node0 -key bogus } msg
mygraph destroy
set msg
} "wrong # args: should be none"
test graph1-25.3 {node keys with node name returns list of keys} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key other things
set results [mygraph node keys node0]
mygraph destroy
lsort $results
} "data other"
test graph1-26.1 {arc keyexists gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc keyexists arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-26.2 {arc keyexists returns false on non-existant key} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [mygraph arc keyexists arc0 -key bogus]
mygraph destroy
set result
} "0"
test graph1-26.3 {arc keyexists uses data as default key} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
set result [mygraph arc keyexists arc0]
mygraph destroy
set result
} "1"
test graph1-26.4 {arc keyexists respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key boom foobar
set result [mygraph arc keyexists arc0 -key boom]
mygraph destroy
set result
} "1"
test graph1-27.1 {node keyexists gives error on bogus node} {
struct::graph mygraph
catch {mygraph node keyexists node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-27.2 {node keyexists returns false on non-existant key} {
struct::graph mygraph
mygraph node insert node0
set result [mygraph node keyexists node0 -key bogus]
mygraph destroy
set result
} "0"
test graph1-27.3 {node keyexists uses data as default key} {
struct::graph mygraph
mygraph node insert node0
set result [mygraph node keyexists node0]
mygraph destroy
set result
} "1"
test graph1-27.4 {node keyexists respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key boom foobar
set result [mygraph node keyexists node0 -key boom]
mygraph destroy
set result
} "1"
test graph1-28.1 {arc append gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc append arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-28.2 {arc append with arc name appends to "data" value} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 foo
set result [mygraph arc append arc0 bar]
mygraph destroy
set result
} "foobar"
test graph1-28.3 {arc append with arc name and key appends key value} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key baz foo
set result [mygraph arc append arc0 -key baz bar]
mygraph destroy
set result
} "foobar"
test graph1-28.4 {arc append with too many args gives error} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc append arc0 foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph arc append arc0 ?-key key? value\""
test graph1-28.5 {arc append with bad args} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc append arc0 -foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"-foo\": should be -key"
test graph1-28.6 {arc append respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key baz foo
set result [mygraph arc append arc0 -key baz bar]
mygraph destroy
set result
} "foobar"
test graph1-29.1 {arc lappend gives error on bogus arc} {
struct::graph mygraph
catch {mygraph arc lappend arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"mygraph\""
test graph1-29.2 {arc lappend with node arc lappends to "data" value} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 foo
set result [mygraph arc lappend arc0 bar]
mygraph destroy
set result
} "foo bar"
test graph1-29.3 {arc lappend with arc name and key lappends key value} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key baz foo
set result [mygraph arc lappend arc0 -key baz bar]
mygraph destroy
set result
} "foo bar"
test graph1-29.4 {arc lappend with too many args gives error} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc lappend arc0 foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph arc lappend arc0 ?-key key? value\""
test graph1-29.5 {arc lappend with bad args} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
catch {mygraph arc lappend arc0 -foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"-foo\": should be -key"
test graph1-29.6 {arc lappend respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 arc0
mygraph arc set arc0 -key baz foo
set result [mygraph arc lappend arc0 -key baz bar]
mygraph destroy
set result
} "foo bar"
test graph1-30.1 {node append gives error on bogus node} {
struct::graph mygraph
catch {mygraph node append node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-30.2 {node append with node name appends to "data" value} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 foo
set result [mygraph node append node0 bar]
mygraph destroy
set result
} "foobar"
test graph1-30.3 {node append with node name and key appends key value} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key baz foo
set result [mygraph node append node0 -key baz bar]
mygraph destroy
set result
} "foobar"
test graph1-30.4 {node append with too many args gives error} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node append node0 foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph node append node0 ?-key key? value\""
test graph1-30.5 {node append with bad args} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node append node0 -foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"-foo\": should be -key"
test graph1-30.6 {node append respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key baz foo
set result [mygraph node append node0 -key baz bar]
mygraph destroy
set result
} "foobar"
test graph1-31.1 {node lappend gives error on bogus node} {
struct::graph mygraph
catch {mygraph node lappend node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-32.2 {node lappend with node name lappends to "data" value} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 foo
set result [mygraph node lappend node0 bar]
mygraph destroy
set result
} "foo bar"
test graph1-32.3 {node lappend with node name and key lappends key value} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key baz foo
set result [mygraph node lappend node0 -key baz bar]
mygraph destroy
set result
} "foo bar"
test graph1-32.4 {node lappend with too many args gives error} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node lappend node0 foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph node lappend node0 ?-key key? value\""
test graph1-32.5 {node lappend with bad args} {
struct::graph mygraph
mygraph node insert node0
catch {mygraph node lappend node0 -foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"-foo\": should be -key"
test graph1-32.6 {node lappend respects -key flag} {
struct::graph mygraph
mygraph node insert node0
mygraph node set node0 -key baz foo
set result [mygraph node lappend node0 -key baz bar]
mygraph destroy
set result
} "foo bar"
# ---------------------------------------------------
proc makegraph {} {
struct::graph mygraph
mygraph node insert i
mygraph node insert ii
mygraph node insert iii
mygraph node insert iv
mygraph node insert v
mygraph node insert vi
mygraph node insert vii
mygraph node insert viii
mygraph node insert ix
mygraph arc insert i ii 1
mygraph arc insert ii iii 2
mygraph arc insert ii iii 3
mygraph arc insert ii iii 4
mygraph arc insert iii iv 5
mygraph arc insert iii iv 6
mygraph arc insert iv v 7
mygraph arc insert v vi 8
mygraph arc insert vi viii 9
mygraph arc insert viii i 10
mygraph arc insert i ix 11
mygraph arc insert ix ix 12
mygraph arc insert i vii 13
mygraph arc insert vii vi 14
}
test graph1-21.1 {walk with too few args} {badTest} {
struct::graph mygraph
catch {mygraph walk} msg
mygraph destroy
set msg
} "no value given for parameter \"node\" to \"::struct::graph::_walk\""
test graph1-21.2 {walk with too few args} {
struct::graph mygraph
catch {mygraph walk node0} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph walk node0 ?-dir forward|backward? ?-order pre|post|both? ?-type {bfs|dfs}? -command cmd\""
test graph1-21.3 {walk with too many args} {
struct::graph mygraph
catch {mygraph walk node0 -foo bar -baz boo -foo2 boo -foo3 baz -foo4 baz} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph walk node0 ?-dir forward|backward? ?-order pre|post|both? ?-type {bfs|dfs}? -command cmd\""
test graph1-21.4 {walk with fake node} {
struct::graph mygraph
catch {mygraph walk node0 -command {}} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"mygraph\""
test graph1-21.5 {walk using unknown option} {
makegraph
catch {mygraph walk i -foo x -command {}} msg
mygraph destroy
set msg
} "unknown option \"-foo\": should be \"mygraph walk i ?-dir forward|backward? ?-order pre|post|both? ?-type {bfs|dfs}? -command cmd\""
test graph1-21.6 {walk with empty command} {
makegraph
catch {mygraph walk i -command {}} msg
mygraph destroy
set msg
} "no command specified: should be \"mygraph walk i ?-dir forward|backward? ?-order pre|post|both? ?-type {bfs|dfs}? -command cmd\""
test graph1-21.7 {walk with illegal specifications} {
makegraph
catch {mygraph walk i -command foo -type foo} msg
mygraph destroy
set msg
} "invalid search type \"foo\": should be dfs, or bfs"
test graph1-21.8 {walk with illegal specifications} {
makegraph
catch {mygraph walk i -command foo -type dfs -dir oneway} msg
mygraph destroy
set msg
} "invalid search direction \"oneway\": should be forward or backward"
test graph1-21.9 {walk with illegal specifications} {
makegraph
catch {mygraph walk i -command foo -type dfs -dir forward -order none} msg
mygraph destroy
set msg
} "invalid search order \"none\": should be both, pre or post"
test graph1-21.10 {forward pre-order dfs is default walk} {
makegraph
set t [list ]
mygraph walk i -command {lappend t}
mygraph destroy
set t
} [list \
enter mygraph i enter mygraph ii enter mygraph iii \
enter mygraph iv enter mygraph v enter mygraph vi \
enter mygraph viii enter mygraph ix enter mygraph vii \
]
test graph1-21.11 {forward post-order dfs walk} {
makegraph
set t [list ]
mygraph walk i -order post -command {lappend t}
mygraph destroy
set t
} [list \
leave mygraph viii leave mygraph vi leave mygraph v \
leave mygraph iv leave mygraph iii leave mygraph ii \
leave mygraph ix leave mygraph vii leave mygraph i \
]
test graph1-21.12 {forward both-order dfs walk} {
makegraph
set t [list ]
mygraph walk i -order both -command {lappend t}
mygraph destroy
set t
} [list \
enter mygraph i enter mygraph ii enter mygraph iii \
enter mygraph iv enter mygraph v enter mygraph vi \
enter mygraph viii leave mygraph viii leave mygraph vi \
leave mygraph v leave mygraph iv leave mygraph iii \
leave mygraph ii enter mygraph ix leave mygraph ix \
enter mygraph vii leave mygraph vii leave mygraph i \
]
test graph1-21.13 {forward pre-order bfs walk} {
makegraph
set t [list ]
mygraph walk i -type bfs -command {lappend t}
mygraph destroy
set t
} [list \
enter mygraph i enter mygraph ii enter mygraph ix \
enter mygraph vii enter mygraph iii enter mygraph vi \
enter mygraph iv enter mygraph viii enter mygraph v \
]
test graph1-21.14 {backward pre-order bfs walk} {
makegraph
set t [list ]
mygraph walk ix -type bfs -dir backward -command {lappend t}
mygraph destroy
set t
} [list \
enter mygraph ix enter mygraph i enter mygraph viii \
enter mygraph vi enter mygraph v enter mygraph vii \
enter mygraph iv enter mygraph iii enter mygraph ii \
]
test graph1-21.15 {backward pre-order dfs walk} {
makegraph
set t [list ]
mygraph walk ix -dir backward -command {lappend t}
mygraph destroy
set t
} [list \
enter mygraph ix enter mygraph i enter mygraph viii \
enter mygraph vi enter mygraph v enter mygraph iv \
enter mygraph iii enter mygraph ii enter mygraph vii \
]
test graph1-21.16 {backward post-order dfs walk} {
makegraph
set t [list ]
mygraph walk ix -dir backward -order post -command {lappend t}
mygraph destroy
set t
} [list \
leave mygraph ii leave mygraph iii leave mygraph iv \
leave mygraph v leave mygraph vii leave mygraph vi \
leave mygraph viii leave mygraph i leave mygraph ix \
]
test graph1-21.17 {backward both-order dfs walk} {
makegraph
set t [list ]
mygraph walk ix -dir backward -order both -command {lappend t}
mygraph destroy
set t
} [list \
enter mygraph ix enter mygraph i enter mygraph viii \
enter mygraph vi enter mygraph v enter mygraph iv \
enter mygraph iii enter mygraph ii leave mygraph ii \
leave mygraph iii leave mygraph iv leave mygraph v \
enter mygraph vii leave mygraph vii leave mygraph vi \
leave mygraph viii leave mygraph i leave mygraph ix \
]
test graph1-21.18 {walk, option without value} {
makegraph
catch {mygraph walk ix -type dfs -order} msg
mygraph destroy
set msg
} "value for \"-order\" missing: should be \"mygraph walk ix ?-dir forward|backward? ?-order pre|post|both? ?-type {bfs|dfs}? -command cmd\""
test graph1-21.19 {forward post-order bfs walk not implemented} {
makegraph
catch {mygraph walk i -order post -type bfs -command {lappend t}} msg
mygraph destroy
set msg
} {unable to do a post-order breadth first walk}
test graph1-21.20 {forward both-order bfs walk not implemented} {
makegraph
catch {mygraph walk i -order both -type bfs -command {lappend t}} msg
mygraph destroy
set msg
} {unable to do a both-order breadth first walk}
test graph1-21.21 {backward post-order bfs walk not implemented} {
makegraph
catch {mygraph walk i -dir backward -order post -type bfs -command {lappend t}} msg
mygraph destroy
set msg
} {unable to do a post-order breadth first walk}
test graph1-21.22 {backward both-order bfs walk not implemented} {
makegraph
catch {mygraph walk i -dir backward -order both -type bfs -command {lappend t}} msg
mygraph destroy
set msg
} {unable to do a both-order breadth first walk}
# ---------------------------------------------------
test graph1-33.1 {get gives error on bogus key} {
struct::graph mygraph
catch {mygraph get -key bogus} msg
mygraph destroy
set msg
} "invalid key \"bogus\" for graph \"mygraph\""
test graph1-33.2 {get uses data as default key} {
struct::graph mygraph
mygraph set foobar
set result [mygraph get]
mygraph destroy
set result
} "foobar"
test graph1-33.3 {get respects -key flag} {
struct::graph mygraph
mygraph set -key boom foobar
set result [mygraph get -key boom]
mygraph destroy
set result
} "foobar"
# ---------------------------------------------------
test graph1-34.1 {set alone gets/sets "data" value} {
struct::graph mygraph
mygraph set foobar
set result [mygraph set]
mygraph destroy
set result
} "foobar"
test graph1-34.2 {set with key gets/sets key value} {
struct::graph mygraph
mygraph set -key baz foobar
set result [list [mygraph set] [mygraph set -key baz]]
mygraph destroy
set result
} [list "" "foobar"]
test graph1-34.3 {set with too many args gives error} {
struct::graph mygraph
catch {mygraph set foo bar baz boo} msg
mygraph destroy
set msg
} "wrong # args: should be \"mygraph set ?-key key? ?value?\""
test graph1-34.4 {set with bad args} {
struct::graph mygraph
catch {mygraph set foo bar} msg
mygraph destroy
set msg
} "invalid option \"foo\": should be key"
test graph1-34.5 {set with bad args} {
struct::graph mygraph
catch {mygraph set foo bar baz} msg
mygraph destroy
set msg
} "invalid option \"foo\": should be key"
test graph1-34.6 {set with bad key gives error} {
struct::graph mygraph
catch {mygraph set -key foo} msg
mygraph destroy
set msg
} "invalid key \"foo\" for graph \"mygraph\""
# ---------------------------------------------------
test graph1-35.1 {unset does not give error on bogus key} {
struct::graph mygraph
set result [catch {mygraph unset -key bogus}]
mygraph destroy
set result
} 0
test graph1-35.2 {unset removes a keyed value} {
struct::graph mygraph
mygraph set -key foobar foobar
mygraph unset -key foobar
catch {mygraph get -key foobar} msg
mygraph destroy
set msg
} "invalid key \"foobar\" for graph \"mygraph\""
test graph1-35.3 {unset requires -key} {
struct::graph mygraph
mygraph set -key foobar foobar
catch {mygraph unset flaboozle foobar} msg
mygraph destroy
set msg
} "invalid option \"flaboozle\": should be \"mygraph unset ?-key key?\""
# ---------------------------------------------------
test graph1-36.1 {getall gives error when key specified} {
struct::graph mygraph
catch {mygraph getall -key data} msg
mygraph destroy
set msg
} "wrong # args: should be none"
test graph1-36.2 {getall returns list of key/value pairs} {
struct::graph mygraph
mygraph set foobar
mygraph set -key other thing
set results [mygraph getall]
mygraph destroy
lsort $results
} "data foobar other thing"
test graph1-37.1 {keys gives error when key specified} {
struct::graph mygraph
catch { mygraph keys -key bogus } msg
mygraph destroy
set msg
} "wrong # args: should be none"
test graph1-37.2 {keys returns list of keys} {
struct::graph mygraph
mygraph set -key other things
set results [mygraph keys]
mygraph destroy
lsort $results
} "data other"
test graph1-38.1 {keyexists returns false on non-existant key} {
struct::graph mygraph
set result [mygraph keyexists -key bogus]
mygraph destroy
set result
} "0"
test graph1-38.2 {keyexists uses data as default key} {
struct::graph mygraph
set result [mygraph keyexists]
mygraph destroy
set result
} "1"
test graph1-38.3 {keyexists respects -key flag} {
struct::graph mygraph
mygraph set -key boom foobar
set result [mygraph keyexists -key boom]
mygraph destroy
set result
} "1"
# ---------------------------------------------------
# Big cleanup, get out of the way of graph v2.
#
# Currently the order of test files is graph, graph1, graphops, and
# the first and last use graph v2. Leaving the class command of graph
# v1 in place will mess up the handling of accelerated operations.
rename struct::graph {}
# ---------------------------------------------------
testsuiteCleanup
|