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 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035
|
# -*- 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: graph.test,v 1.20 2005/09/28 04:51:23 andreas_kupries Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
# -------------------------------------------------------------------------
# Ensure we test _this_ local copy and one installed somewhere else.
#
package forget struct::graph
package forget struct::list
catch {namespace delete ::struct::graph}
catch {namespace delete ::struct::list}
if {[catch {source [file join [file dirname [info script]] graph.tcl]} msg]} {
puts "skipped [file tail [info script]] (graph.tcl): $msg"
return
}
if {[catch {source [file join [file dirname [info script]] list.tcl]} msg]} {
puts "skipped [file tail [info script]] (list.tcl): $msg"
return
}
package require struct::graph
package require struct::list
puts "- struct::graph [package present struct::graph]"
catch {puts " - cgraph [package present cgraph]"}
puts " - struct::list [package present struct::list]"
namespace import ::struct::graph::graph
#----------------------------------------------------------------------
# Takes a dictionary, returns a list containing the same dictionary,
# however the keys are sorted alphabetically. This allows for a true
# comparison of dictionary results.
proc dictsort {dict} {
array set a $dict
set out [list]
foreach key [lsort [array names a]] {
lappend out $key $a($key)
}
return $out
}
# Validate a serialization against the graph it
# was generated from.
proc validate_serial {g serial {nodes {}}} {
# Need a list with length a multiple of 3, plus one.
if {[llength $serial] % 3 != 1} {
return serial/wrong#elements
}
set gattr [lindex $serial end]
if {[llength $gattr] % 2} {
return attr/graph/wrong#elements
}
if {![string equal \
[dictsort $gattr] \
[dictsort [$g getall]]]} {
return attr/graph/data-mismatch
}
# Check node attrs and arcs information
array set an {}
array set ne {}
foreach {node attr arcs} [lrange $serial 0 end-1] {
# Must not list nodes outside of origin
if {![$g node exists $node]} {
return node/$node/unknown
}
# Node structure correct ?
if {[llength $attr] % 2} {
return node/$node/attr/wrong#elements
}
# Node attribues matching ?
if {![string equal \
[dictsort $attr] \
[dictsort [$g node getall $node]]]} {
return node/$node/attr/data-mismatch
}
# Remember nodes for reverse check.
set ne($node) .
# Go through the attached arcs.
foreach a $arcs {
# Structure correct ?
if {[llength $a] != 3} {
return node/$node/arc/wrong#elements
}
# Decode structure
foreach {arc dst aattr} $a break
# Already handled ?
if {[info exists an($arc)]} {
return arc/$arc/duplicate-definition
}
# Must not list arc outside of origin
if {![$g arc exists $arc]} {
return arc/$arc/unknown
}
# Attribute structure correct ?
if {[llength $aattr] % 2} {
return arc/$arc/attr/wrong#elements
}
# Attribute data correct ?
if {![string equal \
[dictsort $aattr] \
[dictsort [$g arc getall $arc]]]} {
return arc/$arc/attr/data-mismatch
}
# Arc information, node reference ok ?
if {![string is integer -strict $dst]} {
return arc/$arc/dst/not-an-integer
}
if {$dst < 0} {
return arc/$arc/dst/out-of-bounds
}
if {$dst >= [llength $serial]} {
return arc/$arc/dts/out-of-bounds
}
# Arc information matching origin ?
if {![string equal $node [$g arc source $arc]]} {
return arc/$arc/src/mismatch/$node/[$g arc source $arc]
}
if {![string equal [lindex $serial $dst] [$g arc target $arc]]} {
return arc/$arc/dst/mismatch/$node/[$g arc target $arc]
}
# Remember for check for multiples
set an($arc) .
}
}
# Nodes ... All must exist in graph ...
# ... Spanning nodes have to be in serialization
if {[llength $nodes] == 0} {
set nodes [lsort [$g nodes]]
} else {
set nodes [lsort $nodes]
}
# Reverse check ...
if {[array size ne] != [llength $nodes]} {
return nodes/mismatch/#nodes
}
if {![string equal [lsort [array names ne]] $nodes]} {
return nodes/mismatch/data
}
# Arcs ... All must exist in graph ...
# ... src / dst has to exist, has to match data in graph.
# ... All arcs between nodes in 'n' have to be in 'a'
foreach k [$g arcs] {
set s [$g arc source $k]
set e [$g arc target $k]
if {[info exists ne($s)] && [info exists ne($e)] && ![info exists an($k)]} {
return arc/$k/missing/should-have-been-listed
}
}
return ok
}
#----------------------------------------------------------------------
test graph-0.1 {graph errors} {
graph mygraph
catch {graph mygraph} msg
mygraph destroy
set msg
} "command \"::mygraph\" already exists, unable to create graph"
test graph-0.2 {graph errors} {
graph mygraph
catch {mygraph} msg
mygraph destroy
set msg
} "wrong # args: should be \"::mygraph option ?arg arg ...?\""
test graph-0.3 {graph errors} {
graph mygraph
catch {mygraph foo} msg
mygraph destroy
set msg
} "bad option \"foo\": must be -->, =, append, arc, arcs, deserialize, destroy, get, getall, keyexists, keys, lappend, node, nodes, serialize, set, swap, unset, or walk"
test graph-0.4 {graph errors} {
catch {graph set} msg
set msg
} "command \"::set\" already exists, unable to create graph"
test graph-0.5 {graph errors} {
graph mygraph
catch {mygraph arc foo} msg
mygraph destroy
set msg
} "bad option \"foo\": must be append, attr, delete, exists, get, getall, insert, keyexists, keys, lappend, rename, set, source, target, or unset"
test graph-0.6 {graph errors} {
graph mygraph
catch {mygraph node foo} msg
mygraph destroy
set msg
} "bad option \"foo\": must be append, attr, degree, delete, exists, get, getall, insert, keyexists, keys, lappend, opposite, rename, set, or unset"
# ---------------------------------------------------
test graph-1.1 {create} {
graph mygraph
set result [string equal [info commands ::mygraph] "::mygraph"]
mygraph destroy
set result
} 1
test graph-1.2 {create} {
set name [graph]
set result [list $name [string equal [info commands $name] "$name"]]
$name destroy
set result
} {::graph1 1}
test graph-1.3 {destroy} {
graph mygraph
mygraph destroy
string equal [info commands ::mygraph] ""
} 1
# ---------------------------------------------------
test graph-2.1 {arc delete} {
graph mygraph
catch {mygraph arc delete arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"::mygraph\""
test graph-2.2 {arc delete} {
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 graph-3.1 {arc exists} {
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 graph-4.1 {arc get gives error on bogus arc} {
graph mygraph
catch {mygraph arc get {IT::EM 0} data} msg
mygraph destroy
set msg
} {arc "IT::EM 0" does not exist in graph "::mygraph"}
test graph-4.2 {arc get gives error on bogus key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
catch {mygraph arc get root bogus} msg
mygraph destroy
set msg
} {invalid key "bogus" for arc "root"}
test graph-4.3 {arc get gives error on bogus key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root foo far
catch {mygraph arc get root bogus} msg
mygraph destroy
set msg
} {invalid key "bogus" for arc "root"}
test graph-4.4 {arc get} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root boom foobar
set result [mygraph arc get root boom]
mygraph destroy
set result
} foobar
# ---------------------------------------------------
test graph-5.1 {arc insert gives error on duplicate arc name} {
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 graph-5.2 {arc insert creates and initializes arc} {
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 data ""]
mygraph destroy
set result
} {1 node0 node1 {}}
test graph-5.3 {arc insert arcs in correct location} {
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 graph-5.4 {arc insert gives error when trying to insert to a fake node} {
graph mygraph
catch {mygraph arc insert node0 node1 arc0} msg
mygraph destroy
set msg
} "source node \"node0\" does not exist in graph \"::mygraph\""
test graph-5.5 {arc insert gives error when trying to insert to a fake node} {
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 graph-5.6 {arc insert generates arc name when none is given} {
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 graph-5.6 {arc insert generates arc name when none is given} {
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 graph-6.1 {arc set, wrong # args} {
graph mygraph
catch {mygraph arc set root data foo far} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph arc set root key ?value?"}
test graph-6.2 {arc set gives error on bogus arc} {
graph mygraph
catch {mygraph arc set snarf data} msg
mygraph destroy
set msg
} {arc "snarf" does not exist in graph "::mygraph"}
test graph-6.3 {arc set retrieves and/or sets value} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root baz foobar
set result [mygraph arc set root baz]
mygraph destroy
set result
} foobar
test graph-6.4 {arc set with bad key gives error} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
catch {mygraph arc set root foo} msg
mygraph destroy
set msg
} {invalid key "foo" for arc "root"}
test graph-6.5 {arc set with bad key gives error} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root data ""
catch {mygraph arc set root foo} msg
mygraph destroy
set msg
} {invalid key "foo" for arc "root"}
# ---------------------------------------------------
test graph-7.1 {arc source gives error on bogus arc} {
graph mygraph
catch {mygraph arc source arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"::mygraph\""
test graph-7.2 {arc source} {
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 graph-8.1 {arc target gives error on bogus arc} {
graph mygraph
catch {mygraph arc target arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"::mygraph\""
test graph-8.2 {arc target} {
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 graph-9.1 {arc unset, wrong # args} {
graph mygraph
catch {mygraph arc unset root flaboozle foobar} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__arc_unset} {name arc key}]
test graph-9.2 {arc unset gives error on bogus arc} {
graph mygraph
catch {mygraph arc unset {IT::EM 0} data} msg
mygraph destroy
set msg
} {arc "IT::EM 0" does not exist in graph "::mygraph"}
test graph-9.3 {arc unset does not give error on bogus key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [catch {mygraph arc unset root bogus}]
mygraph destroy
set result
} 0
test graph-9.4 {arc unset does not give error on bogus key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root foo ""
set result [catch {mygraph arc unset root bogus}]
mygraph destroy
set result
} 0
test graph-9.5 {arc unset removes attribute from arc} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [list]
lappend result [mygraph arc keyexists root foobar]
mygraph arc set root foobar foobar
lappend result [mygraph arc keyexists root foobar]
mygraph arc unset root foobar
lappend result [mygraph arc keyexists root foobar]
mygraph destroy
set result
} {0 1 0}
test graph-9.6 {arc unset followed by arc delete} {
graph mygraph
set result [list]
mygraph node insert node0
mygraph node insert node1
set a [mygraph arc insert node0 node1 root]
mygraph arc set $a foo bar
mygraph arc unset $a foo
mygraph arc delete $a
set result [mygraph arc exists $a]
mygraph destroy
unset a
set result
} 0
# ---------------------------------------------------
test graph-10.1 {arcs} {
graph mygraph
set result [mygraph arcs]
mygraph destroy
set result
} {}
test graph-10.2 {arcs} {
graph mygraph
catch {mygraph arcs -foo} msg
mygraph destroy
set msg
} {invalid restriction "-foo": should be -in, -out, -adj, -inner, -embedding, -key, -value, or -filter}
test graph-10.3 {arcs} {
graph mygraph
catch {mygraph arcs -in} msg
mygraph destroy
set msg
} {no nodes specified: should be "::mygraph arcs ?-key key? ?-value value? ?-filter cmd? ?-in|-out|-adj|-inner|-embedding node node...?"}
test graph-10.4 {arcs} {
graph mygraph
catch {mygraph arcs -in node0} msg
mygraph destroy
set msg
} {node "node0" does not exist in graph "::mygraph"}
test graph-10.5 {arcs} {
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 set arcA volume 30
mygraph arc insert node5 node2 arcB
mygraph arc insert node6 node3 arcC ; mygraph arc set arcC volume 50
mygraph arc insert node3 node1 arcD
mygraph arc insert node1 node2 arcE
mygraph arc insert node2 node3 arcF
proc vol {g n} {
$g arc keyexists $n volume
}
proc vgt40 {g n} {
if {![$g arc keyexists $n volume]} {return 0}
expr {[$g arc get $n volume] > 40}
}
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]] \
\
[lsort [mygraph arcs -filter vol]] \
[lsort [mygraph arcs -filter vgt40]] \
]
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} \
\
{arcA arcC} \
{arcC} \
]
test graph-10.6 {arcs} {
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 graph-10.7 {arcs} {
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 foobar 1
mygraph arc set a2 blubber 2
catch {mygraph arcs -key foobar} msg
mygraph destroy
set msg
} {a1}
test graph-10.8 {arcs} {
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 foobar 1
mygraph arc set a2 foobar 2
catch {mygraph arcs -key foobar -value 1} msg
mygraph destroy
set msg
} {a1}
test graph-10.9 {arcs, multiple -key, illegal} {
graph mygraph
catch {mygraph arcs -key foobar -value 1 -key foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-key"}
test graph-10.10 {arcs, multiple -value, illegal} {
graph mygraph
catch {mygraph arcs -key foobar -value 1 -value foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-value"}
test graph-10.11 {arcs, multiple -filter, illegal} {
graph mygraph
catch {mygraph arcs -filter foobar -in -filter foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-filter"}
test graph-10.12 {arcs, multiple -in, illegal} {
graph mygraph
catch {mygraph arcs -filter foobar -in -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
test graph-10.13 {arcs, -in / -out exclusion, illegal} {
graph mygraph
catch {mygraph arcs -filter foobar -out -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
# ---------------------------------------------------
test graph-11.1 {node degree} {
graph mygraph
catch {mygraph node degree} msg
mygraph destroy
set msg
} "wrong # args: should be \"::mygraph node degree ?-in|-out? node\""
test graph-11.2 {node degree} {
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 graph-11.3 {node degree} {
graph mygraph
catch {mygraph node degree node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"::mygraph\""
test graph-11.4 {node degree} {
graph mygraph
catch {mygraph node degree -foo node0} msg
mygraph destroy
set msg
} "invalid option \"-foo\": should be -in or -out"
test graph-11.5 {node degree} {
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 graph-12.1 {node delete} {
graph mygraph
catch {mygraph node delete node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"::mygraph\""
test graph-12.2 {node delete} {
graph mygraph
mygraph node insert node0
mygraph node delete node0
set result [mygraph node exists node0]
mygraph destroy
set result
} {0}
test graph-12.3 {node delete} {
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 graph-12.4 {node delete} {
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 graph-13.1 {node exists} {
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 graph-14.1 {node get gives error on bogus node} {
graph mygraph
catch {mygraph node get {IT::EM 0} data} msg
mygraph destroy
set msg
} {node "IT::EM 0" does not exist in graph "::mygraph"}
test graph-14.2 {node get gives error on bogus key} {
graph mygraph
mygraph node insert root
catch {mygraph node get root bogus} msg
mygraph destroy
set msg
} {invalid key "bogus" for node "root"}
test graph-14.3 {node get gives error on bogus key} {
graph mygraph
mygraph node insert root
mygraph node set root foo far
catch {mygraph node get root bogus} msg
mygraph destroy
set msg
} {invalid key "bogus" for node "root"}
test graph-14.4 {node get} {
graph mygraph
mygraph node insert root
mygraph node set root boom foobar
set result [mygraph node get root boom]
mygraph destroy
set result
} foobar
# ---------------------------------------------------
test graph-15.1 {node insert gives error on duplicate node name} {
graph mygraph
mygraph node insert node0
catch {mygraph node insert node0} msg
mygraph destroy
set msg
} "node \"node0\" already exists in graph \"::mygraph\""
test graph-15.2 {node insert creates and initializes node} {
graph mygraph
mygraph node insert node0
set result [list ]
lappend result [mygraph node exists node0]
lappend result [mygraph node set node0 data ""]
mygraph destroy
set result
} {1 {}}
test graph-15.3 {node insert generates node name when none is given} {
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 graph-15.x {node insert generates node name when none is given} {
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 graph-16.1 {node opposite gives error on bogus node} {
graph mygraph
catch {mygraph node opposite node0 arc0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"::mygraph\""
test graph-16.2 {node opposite gives error on bogus arc} {
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 graph-16.3 {node opposite gives error on bogus node/arc combination} {
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 graph-16.4 {node opposite} {
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 graph-16.5 {node opposite} {
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 graph-17.1 {node set, wrong # args} {
graph mygraph
catch {mygraph node set root data foo far} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph node set root key ?value?"}
test graph-17.2 {node set gives error on bogus node} {
graph mygraph
catch {mygraph node set snarf data} msg
mygraph destroy
set msg
} {node "snarf" does not exist in graph "::mygraph"}
test graph-17.3 {node set retrieves and/or sets value} {
graph mygraph
mygraph node insert root
mygraph node set root baz foobar
set result [mygraph node set root baz]
mygraph destroy
set result
} foobar
test graph-17.4 {node set with bad key gives error} {
graph mygraph
mygraph node insert root
catch {mygraph node set root foo} msg
mygraph destroy
set msg
} {invalid key "foo" for node "root"}
test graph-17.5 {node set with bad key gives error} {
graph mygraph
mygraph node insert root
mygraph node set root data ""
catch {mygraph node set root foo} msg
mygraph destroy
set msg
} {invalid key "foo" for node "root"}
# ---------------------------------------------------
test graph-18.1 {node unset, wrong # args} {
graph mygraph
catch {mygraph node unset root flaboozle foobar} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__node_unset} {name node key}]
test graph-18.2 {node unset gives error on bogus node} {
graph mygraph
catch {mygraph node unset {IT::EM 0} data} msg
mygraph destroy
set msg
} {node "IT::EM 0" does not exist in graph "::mygraph"}
test graph-18.3 {node unset does not give error on bogus key} {
graph mygraph
mygraph node insert root
set result [catch {mygraph node unset root bogus}]
mygraph destroy
set result
} 0
test graph-18.4 {node unset does not give error on bogus key} {
graph mygraph
mygraph node insert root
mygraph node set root foo ""
set result [catch {mygraph node unset root bogus}]
mygraph destroy
set result
} 0
test graph-18.5 {node unset removes attribute from node} {
graph mygraph
mygraph node insert root
set result [list]
lappend result [mygraph node keyexists root foobar]
mygraph node set root foobar foobar
lappend result [mygraph node keyexists root foobar]
mygraph node unset root foobar
lappend result [mygraph node keyexists root foobar]
mygraph destroy
set result
} {0 1 0}
test graph-18.6 {node unset followed by node delete} {
graph mygraph
set result [list]
set n [mygraph node insert node0]
mygraph node set $n foo bar
mygraph node unset $n foo
mygraph node delete $n
set result [mygraph node exists $n]
mygraph destroy
unset n
set result
} 0
# ---------------------------------------------------
test graph-19.1 {nodes} {
graph mygraph
set result [mygraph nodes]
mygraph destroy
set result
} {}
test graph-19.2 {nodes} {
graph mygraph
catch {mygraph nodes -foo} msg
mygraph destroy
set msg
} {invalid restriction "-foo": should be -in, -out, -adj, -inner, -embedding, -key, -value, or -filter}
test graph-19.3 {nodes} {
graph mygraph
catch {mygraph nodes -in} msg
mygraph destroy
set msg
} {no nodes specified: should be "::mygraph nodes ?-key key? ?-value value? ?-filter cmd? ?-in|-out|-adj|-inner|-embedding node node...?"}
test graph-19.4 {nodes} {
graph mygraph
catch {mygraph nodes -in node0} msg
mygraph destroy
set msg
} {node "node0" does not exist in graph "::mygraph"}
test graph-19.5 {nodes} {
graph mygraph
mygraph node insert node1 ; mygraph node set node1 volume 30
mygraph node insert node2
mygraph node insert node3 ; mygraph node set node3 volume 50
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
proc vol {g n} {
$g node keyexists $n volume
}
proc vgt40 {g n} {
if {![$g node keyexists $n volume]} {return 0}
expr {[$g node get $n volume] > 40}
}
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]] \
\
[lsort [mygraph nodes -filter vol]] \
[lsort [mygraph nodes -filter vgt40]] \
]
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} \
\
{node1 node3} \
{node3} \
]
test graph-19.6 {nodes} {
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 graph-19.7 {nodes} {
graph mygraph
mygraph node insert n0
mygraph node insert n1
mygraph node set n0 foobar 1
mygraph node set n1 blubber 2
catch {mygraph nodes -key foobar} msg
mygraph destroy
set msg
} {n0}
test graph-19.8 {nodes} {
graph mygraph
mygraph node insert n0
mygraph node insert n1
mygraph node set n0 foobar 1
mygraph node set n1 foobar 2
catch {mygraph nodes -key foobar -value 1} msg
mygraph destroy
set msg
} {n0}
test graph-19.9 {nodes, multiple -keys, illegal} {
graph mygraph
catch {mygraph nodes -key foobar -key 1} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-key"}
test graph-19.10 {nodes, multiple -value, illegal} {
graph mygraph
catch {mygraph nodes -key foobar -value 1 -value foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-value"}
test graph-19.11 {nodes, multiple -filter, illegal} {
graph mygraph
catch {mygraph nodes -filter foobar -in -filter foo} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-filter"}
test graph-19.12 {nodes, multiple -in, illegal} {
graph mygraph
catch {mygraph nodes -filter foobar -in -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
test graph-19.13 {nodes, -in / -out exclusion, illegal} {
graph mygraph
catch {mygraph nodes -filter foobar -out -value foo -in} msg
mygraph destroy
set msg
} {invalid restriction: illegal multiple use of "-in"|"-out"|"-adj"|"-inner"|"-embedding"}
# ---------------------------------------------------
test graph-20.1 {swap gives error when trying to swap non existant node} {
graph mygraph
catch {mygraph swap node0 node1} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"::mygraph\""
test graph-20.2 {swap gives error when trying to swap non existant node} {
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 graph-20.3 {swap gives error when trying to swap node with self} {
graph mygraph
mygraph node insert node0
catch {mygraph swap node0 node0} msg
mygraph destroy
set msg
} "cannot swap node \"node0\" with itself"
test graph-20.4 {swap swaps node relationships correctly} {
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 graph-20.5 {swap swaps node relationships correctly} {
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 graph-20.6 {swap swaps node relationships correctly} {
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 graph-22.1 {arc getall, wrong # args} {
graph mygraph
catch {mygraph arc getall root data foo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__arc_getall} {name arc ?pattern?}]
test graph-22.2 {arc getall gives error on bogus arc} {
graph mygraph
catch {mygraph arc getall arc0} msg
mygraph destroy
set msg
} "arc \"arc0\" does not exist in graph \"::mygraph\""
test graph-22.3 {arc getall without attributes returns empty string} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set results [mygraph arc getall root]
mygraph destroy
set results
} {}
test graph-22.4 {arc getall returns dictionary} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root data foobar
mygraph arc set root other thing
set results [dictsort [mygraph arc getall root]]
mygraph destroy
set results
} {data foobar other thing}
test graph-22.5 {arc getall matches key pattern} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root data foobar
mygraph arc set root other thing
set results [dictsort [mygraph arc getall root d*]]
mygraph destroy
set results
} {data foobar}
# ---------------------------------------------------
test graph-23.1 {node getall, wrong # args} {
graph mygraph
catch {mygraph node getall root data foo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__node_getall} {name node ?pattern?}]
test graph-23.2 {node getall gives error on bogus arc} {
graph mygraph
catch {mygraph node getall node0} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"::mygraph\""
test graph-23.3 {node getall without attributes returns empty string} {
graph mygraph
mygraph node insert node0
set results [mygraph node getall node0]
mygraph destroy
set results
} {}
test graph-23.4 {node getall returns dictionary} {
graph mygraph
mygraph node insert root
mygraph node set root data foobar
mygraph node set root other thing
set results [dictsort [mygraph node getall root]]
mygraph destroy
set results
} {data foobar other thing}
test graph-23.5 {node getall matches key pattern} {
graph mygraph
mygraph node insert root
mygraph node set root data foobar
mygraph node set root other thing
set results [dictsort [mygraph node getall root d*]]
mygraph destroy
set results
} {data foobar}
# ---------------------------------------------------
test graph-24.1 {arc keys, wrong # args} {
graph mygraph
catch {mygraph arc keys root flaboozle foobar} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__arc_keys} {name arc ?pattern?}]
test graph-24.2 {arc keys gives error on bogus arc} {
graph mygraph
catch {mygraph arc keys {IT::EM 0}} msg
mygraph destroy
set msg
} {arc "IT::EM 0" does not exist in graph "::mygraph"}
test graph-24.3 {arc keys returns empty list for arcs without attributes} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set results [mygraph arc keys root]
mygraph destroy
set results
} {}
test graph-24.4 {arc keys returns list of keys} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root data foobar
mygraph arc set root other thing
set results [mygraph arc keys root]
mygraph destroy
lsort $results
} {data other}
test graph-24.5 {arc keys matches pattern} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root data foobar
mygraph arc set root other thing
set results [mygraph arc keys root d*]
mygraph destroy
set results
} data
# ---------------------------------------------------
test graph-25.1 {node keys, wrong # args} {
graph mygraph
catch {mygraph node keys root flaboozle foobar} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__node_keys} {name node ?pattern?}]
test graph-25.2 {node keys gives error on bogus arc} {
graph mygraph
catch {mygraph node keys {IT::EM 0}} msg
mygraph destroy
set msg
} {node "IT::EM 0" does not exist in graph "::mygraph"}
test graph-25.3 {node keys returns empty list for arcs without attributes} {
graph mygraph
mygraph node insert root
set results [mygraph node keys root]
mygraph destroy
set results
} {}
test graph-25.4 {node keys returns list of keys} {
graph mygraph
mygraph node insert root
mygraph node set root data foobar
mygraph node set root other thing
set results [mygraph node keys root]
mygraph destroy
lsort $results
} {data other}
test graph-25.5 {node keys matches pattern} {
graph mygraph
mygraph node insert root
mygraph node set root data foobar
mygraph node set root other thing
set results [mygraph node keys root d*]
mygraph destroy
set results
} data
# ---------------------------------------------------
test graph-26.1 {arc keyexists, wrong # args} {
graph mygraph
catch {mygraph arc keyexists root} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::__arc_keyexists} {name arc key} 2]
test graph-26.2 {arc keyexists, wrong # args} {
graph mygraph
catch {mygraph arc keyexists root foo far} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__arc_keyexists} {name arc key}]
test graph-26.3 {arc keyexists gives error on bogus node} {
graph mygraph
catch {mygraph arc keyexists {IT::EM 0} foo} msg
mygraph destroy
set msg
} {arc "IT::EM 0" does not exist in graph "::mygraph"}
test graph-26.4 {arc keyexists returns false on non-existant key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [mygraph arc keyexists root bogus]
mygraph destroy
set result
} 0
test graph-26.5 {arc keyexists returns false on non-existant key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root ok ""
set result [mygraph arc keyexists root bogus]
mygraph destroy
set result
} 0
test graph-26.6 {arc keyexists returns true for existing key} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
mygraph arc set root ok ""
set result [mygraph arc keyexists root ok]
mygraph destroy
set result
} 1
# ---------------------------------------------------
test graph-27.1 {node keyexists, wrong # args} {
graph mygraph
catch {mygraph node keyexists root} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::__node_keyexists} {name node key} 2]
test graph-27.2 {node keyexists, wrong # args} {
graph mygraph
catch {mygraph node keyexists root foo far} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__node_keyexists} {name node key}]
test graph-27.3 {node keyexists gives error on bogus node} {
graph mygraph
catch {mygraph node keyexists {IT::EM 0} foo} msg
mygraph destroy
set msg
} {node "IT::EM 0" does not exist in graph "::mygraph"}
test graph-27.4 {node keyexists returns false on non-existant key} {
graph mygraph
mygraph node insert root
set result [mygraph node keyexists root bogus]
mygraph destroy
set result
} 0
test graph-27.5 {node keyexists returns false on non-existant key} {
graph mygraph
mygraph node insert root
mygraph node set root ok ""
set result [mygraph node keyexists root bogus]
mygraph destroy
set result
} 0
test graph-27.6 {node keyexists returns true for existing key} {
graph mygraph
mygraph node insert root
mygraph node set root ok ""
set result [mygraph node keyexists root ok]
mygraph destroy
set result
} 1
# ---------------------------------------------------
test graph-28.1 {arc append with too many args gives error} {
graph mygraph
catch {mygraph arc append root foo bar baz boo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__arc_append} {name arc key value}]
test graph-28.2 {arc append gives error on bogus arc} {
graph mygraph
catch {mygraph arc append {IT::EM 0} data foo} msg
mygraph destroy
set msg
} {arc "IT::EM 0" does not exist in graph "::mygraph"}
test graph-28.3 {arc append creates missing attribute} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [list]
lappend result [mygraph arc keyexists root data]
lappend result [mygraph arc append root data bar]
lappend result [mygraph arc keyexists root data]
lappend result [mygraph arc get root data]
mygraph destroy
set result
} {0 bar 1 bar}
test graph-28.4 {arc append appends to attribute value} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [list]
lappend result [mygraph arc set root data foo]
lappend result [mygraph arc append root data bar]
lappend result [mygraph arc get root data]
mygraph destroy
set result
} {foo foobar foobar}
# ---------------------------------------------------
test graph-29.1 {arc lappend with too many args gives error} {
graph mygraph
catch {mygraph arc lappend root foo bar baz boo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__arc_lappend} {name arc key value}]
test graph-29.2 {arc lappend gives error on bogus arc} {
graph mygraph
catch {mygraph arc lappend {IT::EM 0} data foo} msg
mygraph destroy
set msg
} {arc "IT::EM 0" does not exist in graph "::mygraph"}
test graph-29.3 {arc lappend creates missing attribute} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [list]
lappend result [mygraph arc keyexists root data]
lappend result [mygraph arc lappend root data bar]
lappend result [mygraph arc keyexists root data]
lappend result [mygraph arc get root data]
mygraph destroy
set result
} {0 bar 1 bar}
test graph-29.4 {arc lappend appends to attribute value} {
graph mygraph
mygraph node insert node0
mygraph node insert node1
mygraph arc insert node0 node1 root
set result [list]
lappend result [mygraph arc set root data foo]
lappend result [mygraph arc lappend root data bar]
lappend result [mygraph arc get root data]
mygraph destroy
set result
} {foo {foo bar} {foo bar}}
# ---------------------------------------------------
test graph-30.1 {node append with too many args gives error} {
graph mygraph
catch {mygraph node append root foo bar baz boo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__node_append} {name node key value}]
test graph-30.2 {node append gives error on bogus node} {
graph mygraph
catch {mygraph node append {IT::EM 0} data foo} msg
mygraph destroy
set msg
} {node "IT::EM 0" does not exist in graph "::mygraph"}
test graph-30.3 {node append creates missing attribute} {
graph mygraph
mygraph node insert root
set result [list]
lappend result [mygraph node keyexists root data]
lappend result [mygraph node append root data bar]
lappend result [mygraph node keyexists root data]
lappend result [mygraph node get root data]
mygraph destroy
set result
} {0 bar 1 bar}
test graph-30.4 {node append appends to attribute value} {
graph mygraph
mygraph node insert root
set result [list]
lappend result [mygraph node set root data foo]
lappend result [mygraph node append root data bar]
lappend result [mygraph node get root data]
mygraph destroy
set result
} {foo foobar foobar}
# ---------------------------------------------------
test graph-31.1 {node lappend with too many args gives error} {
graph mygraph
catch {mygraph node lappend root foo bar baz boo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::__node_lappend} {name node key value}]
test graph-31.2 {node lappend gives error on bogus node} {
graph mygraph
catch {mygraph node lappend {IT::EM 0} data foo} msg
mygraph destroy
set msg
} {node "IT::EM 0" does not exist in graph "::mygraph"}
test graph-31.3 {node lappend creates missing attribute} {
graph mygraph
mygraph node insert root
set result [list]
lappend result [mygraph node keyexists root data]
lappend result [mygraph node lappend root data bar]
lappend result [mygraph node keyexists root data]
lappend result [mygraph node get root data]
mygraph destroy
set result
} {0 bar 1 bar}
test graph-31.4 {node lappend appends to attribute value} {
graph mygraph
mygraph node insert root
set result [list]
lappend result [mygraph node set root data foo]
lappend result [mygraph node lappend root data bar]
lappend result [mygraph node get root data]
mygraph destroy
set result
} {foo {foo bar} {foo bar}}
# ---------------------------------------------------
proc makegraph {} {
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 graph-21.1 {walk with too few args} {badTest} {
graph mygraph
catch {mygraph walk} msg
mygraph destroy
set msg
} "no value given for parameter \"node\" to \"::struct::graph::_walk\""
test graph-21.2 {walk with too few args} {
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 graph-21.3 {walk with too many args} {
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 graph-21.4 {walk with fake node} {
graph mygraph
catch {mygraph walk node0 -command {}} msg
mygraph destroy
set msg
} "node \"node0\" does not exist in graph \"::mygraph\""
test graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-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 graph-33.1 {get gives error on bogus key} {
graph mygraph
catch {mygraph get bogus} msg
mygraph destroy
set msg
} {invalid key "bogus" for graph "::mygraph"}
test graph-33.2 {get gives error on bogus key} {
graph mygraph
mygraph set foo far
catch {mygraph get bogus} msg
mygraph destroy
set msg
} {invalid key "bogus" for graph "::mygraph"}
test graph-33.3 {get} {
graph mygraph
mygraph set boom foobar
set result [mygraph get boom]
mygraph destroy
set result
} foobar
# ---------------------------------------------------
test graph-34.1 {set, wrong # args} {
graph mygraph
catch {mygraph set data foo far} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph set key ?value?"}
test graph-34.2 {set gives error on bogus key} {
graph mygraph
catch {mygraph set snarf} msg
mygraph destroy
set msg
} {invalid key "snarf" for graph "::mygraph"}
test graph-34.3 {set retrieves and/or sets value} {
graph mygraph
mygraph set baz foobar
set result [mygraph set baz]
mygraph destroy
set result
} foobar
test graph-34.4 {set with bad key gives error} {
graph mygraph
catch {mygraph set foo} msg
mygraph destroy
set msg
} {invalid key "foo" for graph "::mygraph"}
test graph-34.5 {set with bad key gives error} {
graph mygraph
mygraph set data ""
catch {mygraph set foo} msg
mygraph destroy
set msg
} {invalid key "foo" for graph "::mygraph"}
# ---------------------------------------------------
test graph-35.1 {unset, wrong # args} {
graph mygraph
catch {mygraph unset flaboozle foobar} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::_unset} {name key}]
test graph-35.2 {unset does not give error on bogus key} {
graph mygraph
set result [catch {mygraph unset bogus}]
mygraph destroy
set result
} 0
test graph-35.3 {unset does not give error on bogus key} {
graph mygraph
mygraph set foo ""
set result [catch {mygraph unset bogus}]
mygraph destroy
set result
} 0
test graph-35.4 {unset removes attribute from node} {
graph mygraph
set result [list]
lappend result [mygraph keyexists foobar]
mygraph set foobar foobar
lappend result [mygraph keyexists foobar]
mygraph unset foobar
lappend result [mygraph keyexists foobar]
mygraph destroy
set result
} {0 1 0}
# ---------------------------------------------------
test graph-36.1 {getall, wrong # args} {
graph mygraph
catch {mygraph getall data foo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::_getall} {name ?pattern?}]
test graph-36.2 {getall without attributes returns empty string} {
graph mygraph
set results [mygraph getall]
mygraph destroy
set results
} {}
test graph-36.3 {getall returns dictionary} {
graph mygraph
mygraph set data foobar
mygraph set other thing
set results [dictsort [mygraph getall]]
mygraph destroy
set results
} {data foobar other thing}
test graph-36.4 {getall matches key pattern} {
graph mygraph
mygraph set data foobar
mygraph set other thing
set results [dictsort [mygraph getall d*]]
mygraph destroy
set results
} {data foobar}
# ---------------------------------------------------
test graph-37.1 {keys, wrong # args} {
graph mygraph
catch {mygraph keys flaboozle foobar} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::_keys} {name ?pattern?}]
test graph-37.2 {keys returns empty list without attributes} {
graph mygraph
set results [mygraph keys]
mygraph destroy
set results
} {}
test graph-37.3 {keys returns list of keys} {
graph mygraph
mygraph set data foobar
mygraph set other thing
set results [mygraph keys]
mygraph destroy
lsort $results
} {data other}
test graph-37.4 {keys matches pattern} {
graph mygraph
mygraph set data foobar
mygraph set other thing
set results [mygraph keys d*]
mygraph destroy
set results
} data
# ---------------------------------------------------
test graph-38.1 {keyexists, wrong # args} {
graph mygraph
catch {mygraph keyexists} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::_keyexists} {name key} 1]
test graph-38.2 {keyexists, wrong # args} {
graph mygraph
catch {mygraph keyexists foo far} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::_keyexists} {name key}]
test graph-38.3 {keyexists returns false on non-existant key} {
graph mygraph
set result [mygraph keyexists bogus]
mygraph destroy
set result
} 0
test graph-38.4 {keyexists returns false on non-existant key} {
graph mygraph
mygraph set ok ""
set result [mygraph keyexists bogus]
mygraph destroy
set result
} 0
test graph-38.5 {keyexists returns true for existing key} {
graph mygraph
mygraph set ok ""
set result [mygraph keyexists ok]
mygraph destroy
set result
} 1
# ---------------------------------------------------
test graph-39.1 {append with too many args gives error} {
graph mygraph
catch {mygraph append foo bar baz boo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::_append} {name key value}]
test graph-39.2 {append gives if not enough arguments} {
graph mygraph
catch {mygraph append} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::_append} {name key value} 1]
test graph-39.3 {append creates missing attribute} {
graph mygraph
set result [list]
lappend result [mygraph keyexists data]
lappend result [mygraph append data bar]
lappend result [mygraph keyexists data]
lappend result [mygraph get data]
mygraph destroy
set result
} {0 bar 1 bar}
test graph-39.4 {append appends to attribute value} {
graph mygraph
set result [list]
lappend result [mygraph set data foo]
lappend result [mygraph append data bar]
lappend result [mygraph get data]
mygraph destroy
set result
} {foo foobar foobar}
# ---------------------------------------------------
test graph-40.1 {lappend with too many args gives error} {
graph mygraph
catch {mygraph lappend foo bar baz boo} msg
mygraph destroy
set msg
} [tcltest::tooManyArgs {::struct::graph::_lappend} {name key value}]
test graph-40.2 {lappend gives error if not enough arguments} {
graph mygraph
catch {mygraph lappend} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::_lappend} {name key value} 1]
test graph-40.3 {lappend creates missing attribute} {
graph mygraph
set result [list]
lappend result [mygraph keyexists data]
lappend result [mygraph lappend data bar]
lappend result [mygraph keyexists data]
lappend result [mygraph get data]
mygraph destroy
set result
} {0 bar 1 bar}
test graph-40.4 {lappend appends to attribute value} {
graph mygraph
set result [list]
lappend result [mygraph set data foo]
lappend result [mygraph lappend data bar]
lappend result [mygraph get data]
mygraph destroy
set result
} {foo {foo bar} {foo bar}}
# ---------------------------------------------------
test graph-41.1 {node rename, wrong # args} {
graph mygraph
catch {mygraph node rename foo far fox} result
mygraph destroy
set result
} [tcltest::tooManyArgs {::struct::graph::__node_rename} {name node newname}]
test graph-41.2 {node rename of bogus node fails} {
graph mygraph
catch {mygraph node rename 0 foo} result
mygraph destroy
set result
} {node "0" does not exist in graph "::mygraph"}
test graph-41.3 {node rename, setting to existing node fails} {
graph mygraph
mygraph node insert root
mygraph node insert 0
catch {mygraph node rename root 0} result
mygraph destroy
set result
} {unable to rename node to "0", node of that name already present in the graph "::mygraph"}
test graph-41.4 {node rename, in arcs} {
graph mygraph
mygraph node insert 0
mygraph node insert 1
mygraph node insert 2
mygraph node insert 3
mygraph arc insert 1 0 a
mygraph arc insert 2 0 b
mygraph arc insert 3 0 c
set result [list]
lappend result [mygraph node degree -in 0]
lappend result [mygraph node degree -out 0]
lappend result [mygraph node exists 0]
lappend result [mygraph node exists snarf]
lappend result [mygraph nodes -in 0]
lappend result [mygraph nodes -out 0]
mygraph node rename 0 snarf
lappend result [mygraph node degree -in snarf]
lappend result [mygraph node degree -out snarf]
lappend result [mygraph node exists 0]
lappend result [mygraph node exists snarf]
lappend result [mygraph nodes -in snarf]
lappend result [mygraph nodes -out snarf]
mygraph destroy
set result
} {3 0 1 0 {1 2 3} {} 3 0 0 1 {1 2 3} {}}
test graph-41.5 {node rename, out arcs} {
graph mygraph
mygraph node insert 0
mygraph node insert 1
mygraph node insert 2
mygraph node insert 3
mygraph arc insert 0 1 a
mygraph arc insert 0 2 b
mygraph arc insert 0 3 c
set result [list]
lappend result [mygraph node degree -in 0]
lappend result [mygraph node degree -out 0]
lappend result [mygraph node exists 0]
lappend result [mygraph node exists snarf]
lappend result [mygraph nodes -in 0]
lappend result [mygraph nodes -out 0]
mygraph node rename 0 snarf
lappend result [mygraph node degree -in snarf]
lappend result [mygraph node degree -out snarf]
lappend result [mygraph node exists 0]
lappend result [mygraph node exists snarf]
lappend result [mygraph nodes -in snarf]
lappend result [mygraph nodes -out snarf]
mygraph destroy
set result
} {0 3 1 0 {} {1 2 3} 0 3 0 1 {} {1 2 3}}
test graph-41.6 {node rename, attributes} {
graph mygraph
mygraph node insert 0
mygraph node set 0 data foo
set result [list]
lappend result [mygraph node getall 0]
lappend result [catch {mygraph node getall 5}]
mygraph node rename 0 5
lappend result [mygraph node getall 5]
lappend result [catch {mygraph node getall 0}]
mygraph destroy
set result
} {{data foo} 1 {data foo} 1}
# ---------------------------------------------------
test graph-42.1 {arc rename, wrong # args} {
graph mygraph
catch {mygraph arc rename foo far fox} result
mygraph destroy
set result
} [tcltest::tooManyArgs {::struct::graph::__arc_rename} {name arc newname}]
test graph-42.2 {arc rename of bogus arc fails} {
graph mygraph
catch {mygraph arc rename 0 foo} result
mygraph destroy
set result
} {arc "0" does not exist in graph "::mygraph"}
test graph-42.3 {arc rename, setting to existing arc fails} {
graph mygraph
mygraph node insert 0
mygraph node insert 1
mygraph arc insert 0 1 root
mygraph arc insert 0 1 foo
catch {mygraph arc rename root foo} result
mygraph destroy
set result
} {unable to rename arc to "foo", arc of that name already present in the graph "::mygraph"}
test graph-42.4 {arc rename, nodes} {
graph mygraph
mygraph node insert a
mygraph node insert b
mygraph arc insert a b 0
set result [list]
lappend result [mygraph arc source 0]
lappend result [mygraph arc target 0]
lappend result [mygraph arc exists 0]
lappend result [mygraph arc exists snarf]
lappend result [mygraph arcs -in b]
lappend result [mygraph arcs -out a]
mygraph arc rename 0 snarf
lappend result [mygraph arc source snarf]
lappend result [mygraph arc target snarf]
lappend result [mygraph arc exists 0]
lappend result [mygraph arc exists snarf]
lappend result [mygraph arcs -in b]
lappend result [mygraph arcs -out a]
mygraph destroy
set result
} {a b 1 0 0 0 a b 0 1 snarf snarf}
test graph-42.6 {arc rename, attributes} {
graph mygraph
mygraph node insert a
mygraph node insert b
mygraph arc insert a b 0
mygraph arc set 0 data foo
set result [list]
lappend result [mygraph arc getall 0]
lappend result [catch {mygraph arc getall 5}]
mygraph arc rename 0 5
lappend result [mygraph arc getall 5]
lappend result [catch {mygraph arc getall 0}]
mygraph destroy
set result
} {{data foo} 1 {data foo} 1}
# ---------------------------------------------------
############################################################
# V. Objects to values and back ...
# - serialize deserialize = -->
############################################################
############################################################
test graph-43.1 {serialization, bogus node} {
graph mygraph
catch {mygraph serialize foo} result
mygraph destroy
set result
} {node "foo" does not exist in graph "::mygraph"}
test graph-43.2 {serialization, empty graph} {
graph mygraph
set serial [mygraph serialize]
set result [validate_serial mygraph $serial]
mygraph destroy
set result
# serial = {{}}
} ok
test graph-43.3 {serialization, all} {
graph mygraph
mygraph node insert %0
mygraph node insert %1
mygraph node insert %2
mygraph node insert %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d
mygraph arc insert %2 %3 e
mygraph arc insert %3 %1 f
mygraph set data foo
mygraph node set %0 foo bar
mygraph arc set b bar snarf
set serial [mygraph serialize]
set result [validate_serial mygraph $serial]
mygraph destroy
set result
# serial =
# %3 {} { /0
# {f 6 {}}
# }
# %0 {foo bar} { /3
# {a 6 {}}
# {b 9 {bar snarf}}
# {c 0 {}}
# }
# %1 {} { /6
# {d 9 {}}
# }
# %2 {} { /9
# {e 0 {}}
# }
# {data foo}
} ok
test graph-43.4 {serialization, subgraph} {
graph mygraph
mygraph node insert %0
mygraph node insert %1
mygraph node insert %2
mygraph node insert %3
mygraph arc insert %0 %1 a
mygraph arc insert %0 %2 b
mygraph arc insert %0 %3 c
mygraph arc insert %1 %2 d
mygraph arc insert %2 %3 e
mygraph arc insert %3 %1 f
mygraph set data foo
mygraph node set %0 foo bar
mygraph arc set b bar snarf
set serial [mygraph serialize %0 %1 %3]
set result [validate_serial mygraph $serial {%0 %1 %3}]
mygraph destroy
set result
# serial =
# %0 {foo bar} {{a 3 {}} {c 6 {}}} /0
# %1 {} {} /3
# %3 {} {{f 3 {}}} /6
# {data foo}
} ok
# ---------------------------------------------------
test graph-44.1 {deserialization, wrong #args} {
graph mygraph
catch {mygraph deserialize foo bar} result
mygraph destroy
set result
} [tcltest::tooManyArgs {::struct::graph::_deserialize} {name serial}]
test graph-44.2 {deserialization} {
graph mygraph
set serial {. %3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: list length not 1 mod 3.}}
test graph-44.3 {deserialization} {
graph mygraph
set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data . foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: malformed graph attribute dictionary.}}
test graph-44.4 {deserialization} {
graph mygraph
set serial {%3 {.} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: malformed node attribute dictionary.}}
test graph-44.5 {deserialization} {
graph mygraph
set serial {%3 {} {{f 6 {.}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: malformed arc attribute dictionary.}}
test graph-44.6 {deserialization} {
graph mygraph
set serial {%3 {} {{a 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: duplicate definition of arc "a".}}
test graph-44.7 {deserialization} {
graph mygraph
set serial {%3 {} {{f . {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: bad arc destination reference ".".}}
test graph-44.8 {deserialization} {
graph mygraph
set serial {%3 {} {{f 2 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: bad arc destination reference "2".}}
test graph-44.9 {deserialization} {
graph mygraph
set serial {%3 {} {{f -1 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: bad arc destination reference "-1".}}
test graph-44.10 {deserialization} {
graph mygraph
set serial {%3 {} {{f 14 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: bad arc destination reference "14".}}
test graph-44.11 {deserialization} {
graph mygraph
set serial {%1 {foo bar} {{a 3 {}} {c 6 {}}} %1 {} {} %3 {} {{f 3 {}}} {data foo}}
set fail [catch {mygraph deserialize $serial} result]
mygraph destroy
list $fail $result
} {1 {error in serialization: duplicate node names.}}
test graph-44.12 {deserialization} {
graph mygraph
# Our check of the success of the deserialization
# is to validate the generated graph against the
# serialized data.
set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set result [list]
lappend result [validate_serial mygraph $serial]
mygraph deserialize $serial
lappend result [validate_serial mygraph $serial]
mygraph destroy
set result
} {attr/graph/data-mismatch ok}
test graph-44.13 {deserialization} {
graph mygraph
# Our check of the success of the deserialization
# is to validate the generated graph against the
# serialized data.
# Applying to serialization one after the
# other. Checking that the second operation
# completely squashes the data from the first.
set seriala {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
set serialb {%0 {foo bar} {{a 3 {}} {c 6 {}}} %1 {} {} %3 {} {{f 3 {}}} {data foo}}
set result [list]
lappend result [validate_serial mygraph $seriala]
lappend result [validate_serial mygraph $serialb]
mygraph deserialize $seriala
lappend result [validate_serial mygraph $seriala]
lappend result [validate_serial mygraph $serialb]
mygraph deserialize $serialb
lappend result [validate_serial mygraph $seriala]
lappend result [validate_serial mygraph $serialb]
mygraph destroy
set result
} [list \
attr/graph/data-mismatch attr/graph/data-mismatch \
ok nodes/mismatch/#nodes \
arc/b/unknown ok]
test graph-44.14 {deserialization, empty graph} {
graph mygraph
set serial {{}}
mygraph deserialize $serial
set result [validate_serial mygraph $serial]
mygraph destroy
set result
} ok
# ---------------------------------------------------
test graph-45.1 {graph assignment} {
graph mygraph
catch {mygraph = foo bar} result
mygraph destroy
set result
} [tcltest::tooManyArgs {::struct::graph::_=} {name source}]
test graph-45.2 {graph assignment} {
set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
graph mygraph
graph bgraph
mygraph deserialize $serial
set result [validate_serial bgraph $serial]
bgraph = mygraph
lappend result [validate_serial bgraph $serial]
mygraph destroy
bgraph destroy
set result
} {attr/graph/data-mismatch ok}
# ---------------------------------------------------
test graph-46.1 {reverse graph assignment} {
graph mygraph
catch {mygraph --> foo bar} result
mygraph destroy
set result
} [tcltest::tooManyArgs {::struct::graph::_-->} {name dest}]
test graph-46.2 {reverse graph assignment} {
set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
graph mygraph
graph bgraph
mygraph deserialize $serial
set result [validate_serial bgraph $serial]
mygraph --> bgraph
lappend result [validate_serial bgraph $serial]
mygraph destroy
bgraph destroy
set result
} {attr/graph/data-mismatch ok}
# ---------------------------------------------------
test graph-47.1 {copy construction, wrong # args} {
catch {graph mygraph = a b} result
set result
} {wrong # args: should be "graph ?name ?=|:=|as|deserialize source??"}
test graph-47.2 {copy construction, unknown operator} {
catch {graph mygraph foo a} result
set result
} {wrong # args: should be "graph ?name ?=|:=|as|deserialize source??"}
test graph-47.3 {copy construction, value} {
set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
graph mygraph deserialize $serial
set result [validate_serial mygraph $serial]
mygraph destroy
set result
} ok
test graph-47.4 {copy construction, graph} {
set serial {%3 {} {{f 6 {}}} %0 {foo bar} {{a 6 {}} {b 9 {bar snarf}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {data foo}}
graph mygraph deserialize $serial
graph bgraph = mygraph
set result [validate_serial bgraph $serial]
mygraph destroy
bgraph destroy
set result
} ok
# ---------------------------------------------------
proc gengraph {g} {
graph $g
$g node insert %0 ; $g node set %0 volume 30
$g node insert %1
$g node insert %2
$g node insert %3
$g node insert %4
$g node insert %5 ; $g node set %5 volume 50
$g arc insert %0 %1 0 ; $g arc set 0 volume 30
$g arc insert %0 %2 1
$g arc insert %0 %3 2
$g arc insert %3 %4 3
$g arc insert %4 %5 4
$g arc insert %5 %3 5 ; $g arc set 5 volume 50
}
test graph-48.0 {attribute search} {
gengraph mygraph
catch {mygraph arc attr} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::__arc_attr} {name key args} 1]
test graph-48.1 {attribute search} {
gengraph mygraph
catch {mygraph arc attr a b} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph arc attr key ?-arcs list|-glob pattern|-regexp pattern?"}
test graph-48.2 {attribute search} {
gengraph mygraph
catch {mygraph arc attr a b c d} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph arc attr key ?-arcs list|-glob pattern|-regexp pattern?"}
test graph-48.3 {attribute search} {
gengraph mygraph
catch {mygraph arc attr a b c} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph arc attr key ?-arcs list|-glob pattern|-regexp pattern?"}
test graph-48.4 {attribute search} {
gengraph mygraph
set result [mygraph arc attr vol]
mygraph destroy
set result
} {}
test graph-48.5 {attribute search} {
gengraph mygraph
set result [dictsort [mygraph arc attr volume]]
mygraph destroy
set result
} {0 30 5 50}
test graph-48.6 {attribute search} {
gengraph mygraph
set result [mygraph arc attr volume -arcs {0 3}]
mygraph destroy
set result
} {0 30}
test graph-48.7 {attribute search} {
gengraph mygraph
set result [mygraph arc attr volume -glob {[0-3]}]
mygraph destroy
set result
} {0 30}
test graph-48.8 {attribute search} {
gengraph mygraph
set result [mygraph arc attr volume -regexp {[0-3]}]
mygraph destroy
set result
} {0 30}
test graph-48.9 {attribute search} {
gengraph mygraph
set result [mygraph arc attr volume -arcs {}]
mygraph destroy
set result
} {}
test graph-48.10 {attribute search} {
gengraph mygraph
mygraph arc unset 0 volume
mygraph arc unset 5 volume
set result [mygraph arc attr volume]
mygraph destroy
set result
} {}
# ---------------------------------------------------
test graph-49.0 {attribute search} {
gengraph mygraph
catch {mygraph node attr} msg
mygraph destroy
set msg
} [tcltest::wrongNumArgs {::struct::graph::__node_attr} {name key args} 1]
test graph-49.1 {attribute search} {
gengraph mygraph
catch {mygraph node attr a b} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph node attr key ?-nodes list|-glob pattern|-regexp pattern?"}
test graph-49.2 {attribute search} {
gengraph mygraph
catch {mygraph node attr a b c d} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph node attr key ?-nodes list|-glob pattern|-regexp pattern?"}
test graph-49.3 {attribute search} {
gengraph mygraph
catch {mygraph node attr a b c} msg
mygraph destroy
set msg
} {wrong # args: should be "::mygraph node attr key ?-nodes list|-glob pattern|-regexp pattern?"}
test graph-49.4 {attribute search} {
gengraph mygraph
set result [mygraph node attr vol]
mygraph destroy
set result
} {}
test graph-49.5 {attribute search} {
gengraph mygraph
set result [dictsort [mygraph node attr volume]]
mygraph destroy
set result
} {%0 30 %5 50}
test graph-49.6 {attribute search} {
gengraph mygraph
set result [mygraph node attr volume -nodes {%0 %3}]
mygraph destroy
set result
} {%0 30}
test graph-49.7 {attribute search} {
gengraph mygraph
set result [mygraph node attr volume -glob {%[0-3]}]
mygraph destroy
set result
} {%0 30}
test graph-49.8 {attribute search} {
gengraph mygraph
set result [mygraph node attr volume -regexp {[0-3]}]
mygraph destroy
set result
} {%0 30}
test graph-49.9 {attribute search} {
gengraph mygraph
set result [mygraph node attr volume -nodes {}]
mygraph destroy
set result
} {}
test graph-49.10 {attribute search} {
gengraph mygraph
mygraph node unset %0 volume
mygraph node unset %5 volume
set result [mygraph node attr volume]
mygraph destroy
set result
} {}
# ---------------------------------------------------
::tcltest::cleanupTests
|