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 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723
|
#!/usr/bin/env newlisp
(set 'start-of-qa (time-of-day))
;;
;; General test suite testing functioning of all built in primitives.
;;
;; use from inside the newlisp-x.x.x/ directory
;;
;; ./newlisp qa-dot
;;
;; or for countries and configurations with decimal comma
;;
;; ./newlisp qa-comma (for countries and configurations with decimal , )
;;
(set (sym "test-:" 'QA) (lambda () true))
(context 'Lex) ; predeclare/create context for bayes-train
(context MAIN)
(set-locale "C")
(when utf8
(set-locale "en_US")
(set 'unicodelist '(913 914 915 916 937 945 946 947 948 969 32
1040 1041 1042 1043 1044 1072 1073 1074 1075 1076 13 10))
(set 'utf8str (join (map char unicodelist)))
(unless (catch (regex-comp (join (map char '(12411 12370 12411 12370)))) 'result)
(println "Problem compiling utf-8 regular expressions."))
)
(define (utf8qa)
(if (not (= (length (char 937)) 2)) (QA:failed "UTF-8 char: failed"))
(if (not (and
(= (map char (explode (chop utf8str))) (chop unicodelist))
(= (map char (explode (chop utf8str 3))) (chop unicodelist 3))
(= (map char (explode (chop utf8str 5))) (chop unicodelist 5)))) (QA:failed "UTF-8 chop: failed"))
(if (not (= (map char (explode utf8str)) unicodelist)) (QA:failed "UTF-8 explode: failed"))
(if (not (= (map char (explode (upper-case utf8str)))
'(913 914 915 916 937 913 914 915 916 937 32 1040 1041 1042 1043 1044 1040 1041 1042 1043 1044 13 10)))
(println "upper-case of UTF8 characters not available - not critical -"))
(if (not (= (map char (explode (lower-case utf8str)))
'(945 946 947 948 969 945 946 947 948 969 32 1072 1073 1074 1075 1076 1072 1073 1074 1075 1076 13 10)))
(println "lower-case of UTF8 characters not available - not critical -"))
(if (not (= (map char (explode (first utf8str))) '(913))) (QA:failed "UTF-8 first: failed"))
(if (not (= (map char (explode (last utf8str))) '(10))) (QA:failed "UTF-8 last: failed"))
(if (not (= (map char (explode (rest utf8str)))
'(914 915 916 937 945 946 947 948 969 32 1040 1041 1042 1043 1044 1072 1073 1074 1075 1076 13 10)))
(QA:failed "UTF-8 rest: failed"))
(if (not (= (map char (explode (first (rest utf8str)))) '(914))) (QA:failed "UTF-8 first, rest: failed"))
(if (not
(and (= (map char (explode (select utf8str 1 2 3))) '(914 915 916))
(= (map char (explode (select utf8str -1 -2 -3))) '(10 13 1076))
(= (map char (explode (select utf8str 2 4 6))) '(915 937 946))))
(QA:failed "UTF-8 select: failed"))
(if (not (= (map char (explode (select utf8str '(1 2 3)))) '(914 915 916))) (QA:failed "UTF-8 select: failed"))
(if (not (and
(= (map char (explode (nth 1 utf8str))) '(914))
(= (map char (explode (nth -5 utf8str))) '(1074))))
(QA:failed "UTF-8 nth: failed"))
; rewrite woth 'pop' and 'push', which currently do not work correctly with utf8
;(if (not (= (map char (explode (set-nth 2 utf8str (char 937))))
; '(913 914 937 916 937 945 946 947 948 969 32 1040 1041 1042 1043 1044 1072 1073 1074 1075 1076 13 10)))
; (QA:failed "UTF-8 set-nth: failed"))
true
)
(global 'global-myvar)
(set 'global-myvar 123)
; testing the default functor
(define (double:double x) (+ x x))
(define (test-default-functor)
(and
(= (map double '(1 2 3 4 5)) '(2 4 6 8 10))
(= (map 'double '(1 2 3 4 5)) '(2 4 6 8 10))
(set 'dflt:dflt '(a b c d e f g))
(= (map dflt '(1 2 6)) '(b c g))
(set 'i 0 'j -1 'k 6)
(= (dflt i) 'a)
(= (dflt k) 'g)
(= (dflt j) 'g)
(set 'ctx dflt)
(= (default ctx) dflt:dflt)
(= (default dflt) dflt:dflt)
(sort (default ctx) >)
(= (default dflt) '(g f e d c b a))
))
(context 'KMT)
(context 'QA)
(define (cleanup)
(delete-file "junk")
(delete-file "junk2"))
(set 'failed-messages '())
(define (check-case x)
(case x
(1 "one")
(2 "two")
(3 "three")))
(define (check-cond x)
(cond
((= x 1) 1)
((= x 2) 2)
((= x 3) 3)))
(define (checkqa )
(dolist (p (symbols 'MAIN))
(if (primitive? (eval p))
(begin
(set 'sm (sym (append "test-" (string p))))
(if (not (lambda? (eval sm)))
(print sm "\n"))))))
(define-macro (do-args p)
(= (args) '(2 "3 4" 5 (x y)))
(= (args 3 -1) 'y))
(define (failed msg)
; (println msg)
(push msg failed-messages))
(define (file-copy from-file to-file)
(set 'in-file (open from-file "read"))
(set 'out-file (open to-file "write"))
(while (set 'chr (read-char in-file))
(if (not (= chr 95))
(write-char out-file chr)))
(close in-file)
(close out-file))
(define (line-count file)
(set 'fno (open file "read"))
(set 'cnt 0)
(while (read-line fno)
(inc cnt))
(close fno )
cnt)
(define (myappend x y)
(cond
((= '() x) y)
(true (cons (first x) (myappend (rest x) y)))))
(define (qa)
(dolist (sm (symbols 'MAIN))
(if (not
(if (and (primitive? (eval sm)) (< sm 'zzz))
(begin
(unless MAIN:testing-cell-leaks (print " -> " (term sm) " \r"))
(set 'func (eval (sym (append "test-" (string sm)))) )
(and (catch (apply func) 'result) result))
true))
(failed (string " >>>> " sm " failed " result) )))
(unless MAIN:testing-cell-leaks (print " \n")))
(define (test-$) (find "a|b" "xtzabc" 0) (= ($ 0) $0))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; test-functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (test-!)
(integer? (! "")))
(define (test-!= )
(and (not (!= -9223372036854775808 (& -9223372036854775808 -1))) (!= "abc" "ABC")
(!= "a" "")
(!= 1.000000001 1)
(!= "" "a")))
(define (test-$)
(set '$0 123)
(= ($ 0) 123))
(define (test-% )
(and
(= (% 10 3) 1)
(not (catch (%) 'result))))
(define (test-& )
(= -9223372036854775808 (& -9223372036854775808 -1)))
(define (test-* )
(and
(= (* (* 123456789 123456789)) 15241578750190521)
(= (*) 1)
))
(define (test-+ )
(and
(= (+ 999999999999999999 1) 1000000000000000000)
(= (+ 9223372036854775807 -9223372036854775808) -1)
(= (+ -9223372036854775808 -1) 9223372036854775807) ; wraps around
(= (+) 0)
))
(define (test-- )
(= (- 100000000 1) 99999999))
(define (test-/ )
(= (/ 15241578750190521 123456789) 123456789)
(= (/ -10 5) -2))
(define (test-< )
(and
(< -9223372036854775808 9223372036854775807)
(< "abcdefg" "abcdefgh")
(< 1 1.000000001)
(< 1 "a")
(< "a" 'a)
(< '(a b) '(b c) '(c d))
(not (< '(a b) '(b d) '(b c)))
(< '(((a b))) '(((b c))))
(< '(a (b c)) '(a (b d)) '(a (b (d))))
(< -1)
(< -1.23)
(not (< '(1 2 3)))
(not (< "1"))
(not (< '()))
))
(define (test-<< )
(= (<< 1 63) -9223372036854775808))
(define (test-<= )
(and (<= -9223372036854775808 -9223372036854775808) (<= 1 1.00000001)))
(define (test-= )
(and
(= 1.23456789 1.23456789)
(= 123456789 123456789)
(= 0xFFFFFFFFFFFFFFFF -1)
(= 0b1111111111111111111111111111111111111111111111111111111111111111 -1)
(= '(1 2 3 (4 5) (a b ("CDEFG" "HIJK") 'u 'v 'w))
'(1 2 3 (4 5) (a b ("CDEFG" "HIJK") 'u 'v 'w)))
(= "" "")
(= '())
(= 0)
(= "")
(not (= 1))
(not (= "abc"))
(not (= '(1 2 3)))
))
(define (test-> )
(and (> 9223372036854775807 -9223372036854775808) (> "abcdefgh" "abcdefg") (> 1.000000001
1)
(> "a" 1)
(> "z" "aaaaa")
(> "aaa" "a")
(> 'a "a")
(> '(a) 'a)
(> 1)
(> 1.23)
(> "abc")
(> '(1 2 3))
(not (> ""))
(not (> '()))
))
(define (test->= )
(and (>= 1 0) (>= 1.00000001 1)))
(define (test->> )
(= (>> 1073741824 30) 1))
(define (test-NaN? )
(and (NaN? (sqrt -1))
(set 'NaN (sqrt -1))
(not (= NaN NaN))
(= 1 (+ 1 NaN))
(= 0 (* 2 NaN))
(NaN? (add 1 (sqrt -1)))
(NaN? (abs (sqrt -1)))))
(define (test-^ )
(= (^ 1431655765 -1431655766) -1))
(define (test-abs )
(and (= (abs -1) 1) (= (abs -9.9) 9.9)))
(define (test-acos )
(= 0 (acos (cos (acos (cos 0))))))
(define (test-acosh)
(= (cosh (acosh 1)) 1))
(define (test-add , l)
(and
(= (add) 0)
(dotimes (x 100)
(push x l))
(= 4950 (apply add l))
))
(define (test-address s)
(and
(set 's "foo")
(= (address s) (last (dump s)))
(set 'D:D "foo")
(= (address D) (last (dump D:D)))
))
(define (test-amb)
(set 'x (amb 1 2))
(or (= x 1) (= x 2)))
(define (test-and )
(and (and true true true) (not (and true true nil))))
(define (test-append )
(and
(= '(1 2 3 4) (append '(1 2) '(3 4)))
(= '(1 2 3 4 5) (append '(1 2) '(3) '(4 5)))
(= '(1 2 3 4) (append '(1 2) '(3 4) '()))
(= '(1 2 3 4 5) (append '(1 2) '(3 4) '() '(5)))
(= '(1 2 3 4 5) (append '() '(1 2) '(3 4) '() '(5)))
(= '() (append '()) (append '() '()) (append))
(= "abcdefg" (append "" "a" "bcd" "" "ef" "g" ""))
(= "" (append ""))
(set 'A (array 3 2 (sequence 1 6)))
(set 'B (array 2 2 (sequence 7 10)))
(= (array 5 2 (sequence 1 10)) (append A B))
(lambda? (append '(lambda)))
; default functor
(set 'D:D '(a b c))
(= '(a b c a b c a b c) (append D D D))
))
(define (test-append-file)
(append-file "junk" "ABC")
(append-file "file://junk" "DEF")
(= (read-file "junk") "ABCDEF")
)
(define (test-apply )
(and (= (apply + '(1 2)) 3)
(= (apply append '("a" "b" "c")) "abc")
(= (apply (fn (x y) (+ x y)) '(3 4)) 7)
(= (apply list '(a b c d e f) 2) '(((((a b) c) d) e) f))
(= (inc (apply set '(x 123))) 124 x)
(= (apply + (array 100 (sequence 1 100)))
(apply + (sequence 1 100))
(apply + (0 100 (array 100 (sequence 1 100)))))
))
(define (test-args )
(do-args 1 2 "3 4" 5 (x y)))
(define (test-array)
(and
(= (array-list (array 3 2 (sequence 1 6))) '((1 2) (3 4) (5 6)))
(set 'A (array 3 2 (sequence 1 6)))
(= (array-list (nth 0 A)) '(1 2))
(= (nth '(0 0) A) 1)
(= (nth '(2 1) A) 6)
(= (nth '(-1 -1) A) 6)
(not (catch (nth '(10 10) A) 'result))
(not (catch (nth '(-10 -10) A) 'result))
(= (nth 0 A) (array 2 '(1 2)))
(= (array-list (nth 0 A)) '(1 2))
(< (nth 0 A) (nth 1 A))
(> (nth 2 A) (nth 1 A))
(setf (A 1 0) 1)
(= (nth '(1 0) A) 1)
(setf (A 1 1) 1)
(= (array-list A) '((1 2) (1 1) (5 6)))
(< (nth 1 A) (nth 0 A))
))
(define (test-array-list)
(and
(set 'a (array 3 4 (sequence 1 12)))
(array? a)
(list? (array-list a))
; default functor
(set 'D:D (array 3 4 (sequence 1 12)))
(array? D:D)
(list? (array-list D))
(= (array-list D) '((1 2 3 4) (5 6 7 8) (9 10 11 12)))
))
(define (test-array?) (test-array-list))
(define (test-asin )
(= (round (asin (sin (asin (sin 1)))) -9) 1))
(define (test-asinh)
(= (round (sinh (asinh 1)) -12) 1))
(define (test-assoc)
(and
(set 'L '((a 1) (b (c (d 2) (e 3) (e 4))) ("a" 5) ((a) 6)))
(= (assoc 'a L) '(a 1))
(= (assoc 'b L) '(b (c (d 2) (e 3) (e 4))))
(= (assoc "a" L) '("a" 5))
(= (assoc '((a)) L) '((a) 6))
(= (assoc '(b c) L) '(c (d 2) (e 3) (e 4)))
(= (assoc '(b c d) L) '(d 2))
(= (assoc '(b c e) L) '(e 3))
; default functor
(set 'D:D '((a 1) (b (c (d 2) (e 3) (e 4))) ("a" 5) ((a) 6)))
(= (assoc 'a D) '(a 1))
))
(define (test-atan )
(< (sub 1 (atan (tan (atan (tan 1))))) 1e-15))
; old test broke after Mac OS X update to 10.5.2
; (= 1 (atan (tan (atan (tan 1)))))
(define (test-atanh)
(< (sub (tanh (atanh 0.5)) 0.5) 0.0000000001))
(define (test-atan2 )
(= (div (acos 0) (atan 1 1)) 2))
(define (test-atom? )
(and (atom? 1) (atom? 1.23) (atom? "hello") (atom? 'x) (atom? nil) (atom? true)))
(define (test-base64-enc)
(and
(= "" (base64-dec (base64-enc "")))
(= "1" (base64-dec (base64-enc "1")))
(= "12" (base64-dec (base64-enc "12")))
(= "123" (base64-dec (base64-enc "123")))
(= "1234" (base64-dec (base64-enc "1234")))
))
(define (test-base64-dec)
(test-base64-enc))
;; context Lex was previously created
(define (test-bayes-train)
(and
(= (bayes-train '(F F F B B) '(F B B B B) 'Lex) '(5 5))
(> 0.001 (apply add (map sub (bayes-query '(F) Lex) '(0.75 0.25))))
(> 0.001 (apply add (map sub (bayes-query '(F) Lex true) '(0.75 0.25))))
(> 0.001 (apply add (map sub (bayes-query '(F F) Lex) '(0.8251777681 0.1748222319))))
(> 0.001 (apply add (map sub (bayes-query '(F F) Lex true) '(0.9 0.1))))
)
)
(define (test-bayes-query)
(set 'Lex:F '(0 0))
(set 'Lex:B '(0 0))
(set 'Lex:total '(0 0))
true)
(define (test-begin )
(begin
(set 'x 0)
(inc x)
(inc x)
(= x 2)))
(define (test-beta )
(< (abs (sub (beta 1 2) 0.5)) 1e-05))
(define (test-betai )
(< (abs (sub (betai 0.5 5 10) 0.910217)) 1e-05))
(define (test-bigint?)
(and
(bigint? 123456789012345678901234567890)
(bigint? 123456789012345678901234567890L)
(bigint? 0L)
(bigint? 123L)
(bigint? (bigint 12345))
(bigint? (bigint 12345.678))
(bigint? (bigint "12345"))
(bigint? (bigint "123hello"))
(nil? (bigint "hello"))
))
(define (test-bigint)
(and
(= 12345L (bigint 12345))
(= 12345 (bigint 12345.678))
(= 12345 (bigint "12345"))
))
(define (test-bind)
(bind '((a 1) (b "hello") (c (3 4))))
(and
(= a 1)
(= b "hello")
(= c '(3 4))
(= 7 (bind '((a (+ 3 4))) true))
)
)
(define (test-binomial )
(< (sub (binomial 2 1 0.5) 0.5) 1e-09))
(define (test-bits)
(and
(= (int (bits 0x7fffffffffffffff) 0 2) 0x7fffffffffffffff)
(= (int (bits 0x8000000000000000) 0 2) 0x8000000000000000)
(= 64 (length (bits 0x8000000000000000)))
(= (bits 0) "0")
(= (bits 1234) "10011010010")
(= (bits 1234 true) '(nil true nil nil true nil true true nil nil true))
))
(define (test-break )
(break true)
(= true (break))
(not (break nil)))
(define (test-case )
(and (= (check-case 1) "one") (= (check-case 2) "two") (= (check-case
9) nil)))
(define (test-callback) true)
(define (test-catch )
(and
(catch (+ 3 4) 'result)
(= result 7)
(= (catch (+ 3 4)) 7)
(= (catch (dotimes (x 100) (if (= x 7) (throw x)))) 7)
))
(define (test-ceil )
(= 2 (ceil 1.5)))
(define (test-change-dir )
(make-dir "adir")
(change-dir "adir")
(change-dir "..")
(remove-dir "adir"))
(define (test-char )
(and
(= (format "%c" (char "a" 0)) "a")
(= (char "A") 65) (= (char 65) "A")
(= (map char (sequence 65 67)) '("A" "B" "C"))
(= (char 0) "\000")
(set 'D:D "ABCDEFG")
(= (char D 0) 65)
(= (char D -1) 71)
(if utf8
(let (s (char 937))
(and
(= (char s 0 true) 206)
(= (char s 1 true) 169)
(= (char s -1 true) 169)
(= (char s -2 true) 206)
)
)
true
)
))
(define (test-chop )
(and
(= (chop "newlisp") "newlis")
(= (chop "newlisp" 4) "new")
(= (chop "abc" 5) "")
(= (chop "abc" -5) "")
(= (chop '(a b (c d) e)) '(a b (c d)))
(= (chop '(a b (c d) e) 2) '(a b))
(set 'D:D "newlisp")
(= (chop D) "newlis")
(= (chop D 4) "new")
))
(define (test-clean )
(and
(= (clean integer? '(1 1.1 2 2.2 3 3.3)) '(1.1 2.2 3.3))
(= (clean true? '(a nil b nil c nil)) '(nil nil nil))))
(define (test-close , fno)
(and
(set 'fno (open "qa-dot" "read"))
(close fno)))
(define (test-collect)
(= (let (x 0) (collect (if (<= (inc x) 5) x))) '(1 2 3 4 5))
)
(define (test-corr)
(< (apply add (map sub (corr '(1 3 5 8 9 9) '(2 2 3 4 6 8))
'(0.868724789 0.5571847507 0.6187683284 3.507907832 4 0.0247186268))) 0.000000001)
)
(define (test-crc32)
(and
(= (crc32 "abcdefghijklmnopqrstuvwxyz") 1277644989)
(= (crc32 "HELLO") 3242484790))
)
(define (test-select-collect )
(and
(set 'l '(0 1 2 3 4 5 6 7 8 9))
(= (select l '()) '())
(= (select l 0 9 9 0 1 8 8 1) '(0 9 9 0 1 8 8 1))
(= (select "2001-09-20" 5 6 8 9 0 1 2 3) "09202001")
(set 'a 0 'b 1 'c 2)
(= (select '(w x y z) a b c) '(w x y))
(= (select '(w x y z) (inc a) (inc b) (inc c)) '(x y z))
))
(define (test-command-event) true) /* test interactively */
(define (test-cond )
(and
(= (check-cond 1) 1)
(= (check-cond 2) 2)
(not (check-cond 99))
(= (cond ((+ 3 4))) 7)
(= (cond (nil 1) ('())) '())
(= (cond (nil 1) (nil)) nil)
(= (cond (nil 1) (true nil)) nil)
(= (cond ('())) '())
(= (cond (nil 1) ('() 2)) '())
))
(define (test-cons )
(= (myappend '(1 2 3) '(4 5 6)) '(1 2 3 4 5 6))
)
(define (test-constant )
(constant 'cs 123)
(= cs 123)
(protected? 'cs))
(define (test-context )
(and (context 'TEST) (context 'QA)))
(define (test-context? )
(and (context? MAIN) (context? QA)))
(define (test-continue)
(let (cnt 0)
(= 1000 (catch (begin (if (< (inc cnt) 1000) (continue) cnt)))))
)
(define (test-copy)
(and
(set 'aList '(a b c))
(= (replace 'b (copy aList)) '(a c))
(= aList '(a b c))
(find-all "12" "12345" (replace "1" (copy $0) "N"))
(= (rotate (copy "abcdefg")) "gabcdef")
))
(define (test-copy-file )
(and (copy-file "qa-dot" "junk") (delete-file "junk")))
(define (test-cos )
(= 1 (cos (acos (cos (acos 1))))))
(define (test-cosh)
(= (cosh 1) (div (add (exp 1) (exp -1)) 2)))
(define (test-count )
(and (= (count '(1 2) '(2 1 2 1)) '(2 2))
(= (count '(a b) '(a a b c a b b)) '(3 3))
(= (count '(a b c) '()) '(0 0 0))
(set 'L '(a b c d e f))
(= (count L L) '(1 1 1 1 1 1))
)
)
(define (test-cpymem)
(set 'from "12345")
(set 'to " ")
(cpymem (address from) (address to) 5)
(= from to))
(define (test-crit-chi2)
(and
(< (abs (sub (crit-chi2 (prob-chi2 4.605 2) 2) 4.605)) 0.001)
(< (abs (sub (crit-chi2 (prob-chi2 51.805 40) 40) 51.805)) 0.001)
(< (abs (sub (crit-chi2 (prob-chi2 9.210 2) 2) 9.210)) 0.001)
(< (abs (sub (crit-chi2 (prob-chi2 63.691 40) 40) 63.691)) 0.001)
))
(define (test-crit-f)
(and
(< (abs (sub (crit-f (prob-f 6.59 3 4) 3 4) 6.59)) 0.001)
(< (abs (sub (crit-f (prob-f 2.79 12 11) 12 11) 2.79)) 0.001)
(< (abs (sub (crit-f (prob-f 16.59 3 4) 3 4) 16.59)) 0.001)
(< (abs (sub (crit-f (prob-f 4.40 12 11) 12 11) 4.40)) 0.001)
))
(define (test-crit-t)
(and
(< (abs (sub (crit-t (prob-t 1.886 2) 2) 1.886)) 0.001)
(< (abs (sub (crit-t (prob-t 1.303 40) 40) 1.303)) 0.001)
(< (abs (sub (crit-t (prob-t 6.965 2) 2) 6.965)) 0.001)
(< (abs (sub (crit-t (prob-t 2.423 40) 40) 2.423)) 0.001)
))
(define (test-crit-z)
(for (z -6 6 0.3)
(let (flag true)
(if (> (abs (sub (crit-z (prob-z z)) z)) 0.0001)
(set 'flag nil))
flag)
))
(define (test-current-line , handle)
(and
(set 'handle (open "qa-dot" "r"))
(= (read-line handle) "#!/usr/bin/env newlisp")
(= (current-line) "#!/usr/bin/env newlisp")
(close handle)))
(define (test-curry)
(and
(= (set 'f (curry + 10)) (lambda ($x) (+ 10 $x)))
(= (filter (curry match '(a *)) '((a 10) (b 5) (a 3) (c 8) (a 9)))
'((a 10) (a 3) (a 9)))
(= (clean (curry match '(a *)) '((a 10) (b 5) (a 3) (c 8) (a 9)))
'((b 5) (c 8)))
(= (map (curry list 'x) (sequence 1 5))
'((x 1) (x 2) (x 3) (x 4) (x 5)))
))
(define (test-date )
(= (date) (date (date-value)) (date (apply date-value (now)))))
(define (test-date-parse)
(and
(= (date-parse "2007.1.3" "%Y.%m.%d") 1167782400)
(= (date-parse "20091014" "%Y%m%d") 1255478400)
(= (date-parse "January 10, 07" "%B %d, %y") 1168387200)
))
(define (test-date-list)
(let (value (date-value) vlist (now))
(= (apply date-value (date-list value)) value)
(= (vlist -4) ((date-list (apply date-value vlist)) -2))
(= (date-list 0) '(1970 1 1 0 0 0 1 4))
)
)
(define (test-date-value )
(= 0
(date-value 1970 1 1 0 0 0)
(date-value (+ 1970) (+ 1) (+ 1) (+ 0) (+ 0) (+ 0))
(date-value '(1970 1 1 0 0 0))) )
(define (test-debug )
(= (debug (+ 3 4)) 7))
(define (test-dec , x)
(test-inc))
(define (test-define , foo)
(and
(lambda? (define (foo (x 1) (y 2)) (list x y)))
(= (foo) '(1 2))
(= (foo 3) '(3 2))
(= (foo 3 4) '(3 4))
(define (foo (x 10) (y (div x 2))) (list x y))
(= (foo) '(10 5))
(= (foo 20) '(20 10))
(= (foo 3 4) '(3 4))
))
(define (test-def-new)
(and
(set 'fooctx:x 123)
(new fooctx)
(= fooctx:x 123)
(set 'barctx:bar 999)
(def-new 'barctx:bar)
(= bar 999)
(def-new 'barctx:bar 'foobar)
(= foobar 999)
(def-new 'barctx:bar 'foofoo:foo)
(= foofoo:foo 999)
))
(define (test-define-macro , foo)
(and
(macro? (define-macro (foo (x 1) (y 2)) (list x y)))
(= (foo) '(1 2))
(= (foo 3) '(3 2))
(= (foo 3 4) '(3 4))
(define-macro (foo (x 10) (y (div x 2))) (list x y))
(= (foo) '(10 5))
(= (foo 20) '(20 10))
(= (foo 3 4) '(3 4))
))
(define (test-default)
(MAIN:test-default-functor))
(define (test-delete )
(and
(set 'l (list (sym "xxx")))
(not (delete (sym "xxx") true))
(delete (sym "xxx")))
)
(define (test-delete-file )
(and (copy-file "qa-dot" "junk") (delete-file "junk")))
(define (test-delete-url )
(= "ERR: HTTP bad formed URL" (delete-url "")))
(define (test-destroy)
(if (find ostype '("Linux" "BSD" "OSX" "SunOS" "AIX" "Tru64Unix" "Cygwin"))
(set 'pid (fork (dotimes (t 100) (sleep 100))))
(set 'pid (process "newlisp")) )
(if (= ostype "Cygwin") (sleep 1000))
(destroy pid))
(define (test-det)
(and
(set 'A '((-1 1 1) (1 4 -5) (1 -2 0)))
(< (sub (det A) -1) 2e-10)
(set 'A '((1 2 3) (4 5 6)))
(not (catch (det A) 'result))
(starts-with result "ERR: wrong dimensions")
))
(define (test-device , fno)
(set 'fno (open "junk" "write"))
(device fno)
(if (= (device) fno)
(close (device))))
(define (test-difference )
(and
(= (difference '(2 5 6 0 3 0 2 5) '(1 2 3 3 2 1)) '(5 6 0))
(= (difference '(1 5 2 3 2 2 4 5 3 4 5 1) '(3 4) true) '(1 5 2 2 2 5 5 1))
(= (difference '(nil nil nil) '()) '(nil))
(= (difference '(nil nil nil) '() true) '(nil nil nil))
(set 'L '(a b c d e f))
(= (difference L L) '())
)
)
(define (test-directory )
(or (find "qa-dot" (directory)) (find "QA" (directory))))
(define (test-directory? )
(and
(directory? ".")
(directory? "modules/")
(directory? "modules")
))
(define (test-div )
(and (= 0.1 (div 100000000 1000000000))
(= (div 1 3) 0.3333333333333333)
(= (div 3) 0.3333333333333333)
))
(define (testdoargs)
(local (lst)
(doargs (i) (push i lst))
lst))
(define (test-doargs)
(= (testdoargs 3 2 1) '(1 2 3)))
(define (test-dolist , rList)
(and
(dolist (x '(1 2 3 4 5 6 7 8 9))
(push x rList))
(= rList '(9 8 7 6 5 4 3 2 1))
(dolist (x rList)
(pop rList))
(dolist (x '(1 2 3 4 5 6 7 8 9) (> x 5))
(push x rList))
(= rList '(5 4 3 2 1))
(= (local (l) (dolist (e '(1 2 3)) (push $idx l)) l) '(2 1 0))
(= (dolist (x '(a b c d e f g)) x) 'g)
;; default functor
(set 'D:D (sequence 1 10))
(set 'cnt 0)
(dolist (i D) (inc cnt i))
(= cnt (apply add D))
))
(define (test-dostring)
(local (r)
(dostring (i "newlisp" (= i 108)) (push i r))
(= r '(119 101 110))
(= (dostring (c "newlisp") c) 112)
)
)
(define (test-dotimes , aList)
(dotimes (x 2)
(dotimes (y 2)
(dotimes (z 2)
(push z aList))))
(and
(= '(1 0 1 0 1 0 1 0) aList)
(not (dotimes (x 0) x))
(= (dotimes (x 1) x) 0)
; dotimes returns nil when ever executed since 8.9.7
(not (= (dotimes (x -1) x) 0))
(not (= (dotimes (x -1.8) x) 0))
(= (dotimes (x 1.8) x) 0)
(set 'cnt 0)
(dotimes (x 10 (> x 5)) (inc cnt))
(= cnt 6)
))
(define (test-dotree )
(set 'aList '())
(and
(= (last (symbols MAIN)) (dotree (p MAIN) p))
(dotree (x 'MAIN)
(push x aList))
(= (length (symbols 'MAIN)) (length aList))
))
(define (test-dump )
( = "hello" (get-string (last (dump "hello")))))
(define (test-dump-symbol )
(= (length (dump nil) 4)))
(define (test-dup)
(and
(= (dup "" 0) "")
(= (dup "" 10) "")
(= (dup "A" 10) "AAAAAAAAAA")
(= (dup "AB" 5) "ABABABABAB")
(= (dup 'x 5) '(x x x x x))
(= (dup "l" -1) "")
(= (dup '(1) -1) '())
(= (dup 1 0) '())
(= (dup 1 5) '(1 1 1 1 1))))
(define (test-empty? , aList)
(set 'aList '(1 2 3 4 5 6 7 8 9 0))
(while aList
(pop aList))
(and
(empty? aList)
(empty? "")
(set 'D:D (sequence 1 10))
(while D:D (pop D))
(empty? D)
))
(define (test-encrypt )
(= (encrypt (encrypt "newlisp" "123") "123") "newlisp"))
(define (test-ends-with )
(and
(ends-with "newlisp" "lisp")
(ends-with "newlisp" "LISP" 1)
(ends-with "abc.def.ghi" "def|ghi" 1)
(ends-with "12345" "4|5" 1)
(ends-with (explode "newlisp") "p")
(set 'D:D "newlisp")
(ends-with D "lisp")
(ends-with D "LISP" 1)
))
(define (test-env)
(and
(list? (env))
(env "key" "value")
(= (env "key") "value")
(env "key" "") ; remove key
(if (or (= ostype "SunOS") (= ostype "Solaris"))
(= (env "key" ""))
(not (env "key")))
))
(define (test-erf)
(< (abs (sub 0.5204998778 (erf 0.5))) 0.000001))
;(define (test-estack) (list? (estack)))
(define (test-even?)
(and (even? 2) (not (even? 3)) (even? 0.9) (not (even? 3.9))))
(define (alarm) (println "ring..."))
(define (test-t-test)
(and
; dependent samples
(< (apply add (map sub (t-test '(1 3 5 8 9 9) '(2 2 3 4 6 8))
'(5.833333333 4.166666667 3.371448749 2.401388487 0.9862873039 10 0.3472542517)))
0.00000001)
; related samples (before and after treatment)
(< (apply add (map sub (t-test '(3 0 6 7 4 3 2 1 4) '(5 1 5 7 10 9 7 11 8) true)
'(3.333333333 7 2.236067977 3.041381265 -3.142857143 8 0.01374582439)))
0.00000001)
; force Welch's Student's t for unequal variances
(< (apply add (map sub (t-test '(1 3 5 8 9 9) '(2 2 3 4 6 8) 1.0)
'(5.833333333 4.166666667 3.371448749 2.401388487 0.9862873039 9 0.3497635197)))
0.00000001)
; force Welch's Student's t for unequal variances and sample sizes
(< (apply add (map sub (t-test '(10 4 7 1 1 6 1 8 2 4) '(4 6 9 4 6 8 9 3) 1.0)
'(4.4 6.125 3.238655414 2.356601669 -1.30656126 15 0.2110406063)))
0.00000001)
; one sample t-test
(< (apply add (map sub (t-test '(3 5 4 2 5 7 4 3) 2.5)
'(4.125 2.5 1.552647509 0.548943791 2.960230221 7 0.02109816335)))
0.00000001)
)
)
(define (test-timer)
(timer 'alarm 4))
(define (test-title-case)
(= (title-case "heLLo") "HeLLo")
(= (title-case "heLLo" true) "Hello"))
(define (test-throw-error)
(and
(not (catch (throw-error "message text") 'result))
(starts-with result "ERR: user error :")) )
(define (test-error-event )
(= 'nil (error-event)))
(define (test-estack) (list? (estack)))
(define (test-eval , x y)
(set 'x 123)
(set 'y 'x)
(set 'z 'y)
(and (= 123 (eval y)) (= 123 (eval 'x)) (= 123 (eval (eval z)))))
(define (test-eval-string ) true
(eval-string "(set 'x 123)")
(eval-string "(set 'y x)")
(= 123 (eval-string "y"))
(set 'Foo:xyz 99999)
(= 99999 (eval-string "xyz" 'Foo))
(delete (sym "xyz" Foo))
)
(define (test-exec )
(and (sub-read-exec) (sub-write-exec))
)
(define (sub-read-exec )
(write-file "exectest" {(println "hello") (exit)})
(and
(set 'result (if (find ostype '("Windows" "OS/2"))
(exec "newlisp exectest")
(exec "./newlisp exectest")))
(= "hello" (last result))
(delete-file "exectest")))
(define (sub-write-exec )
(and
(write-file "testexec" {(write-file "exectest" (read-line))})
(if (find ostype '("Windows" "OS/2"))
(exec "newlisp testexec" "HELLO") (exec "./newlisp testexec" "HELLO"))
(= "HELLO" (read-file "exectest"))
(delete-file "testexec")
(delete-file "exectest")))
(define (test-exit )
(or (primitive? exit) (lambda? exit)))
(define (test-exists)
(and
(= (exists string? '(2 3 4 6 "hello" 7)) "hello")
(not (exists string? '(3 4 2 -7 3 0)) )
(= (exists zero? '(3 4 2 -7 3 0)) 0)
(= (exists < '(3 4 2 -7 3 0)) -7)
(= (exists (fn (x) (> x 3)) '(3 4 2 -7 3 0)) 4)
(not (exists (fn (x) (= x 10)) '(3 4 2 -7 3 0)))
))
(define (test-exp )
(= 1 (exp (log (exp (log (exp (log 1))))))))
(define (test-expand)
(and
(set 'x 2)
(= (expand 'x 'x) 2)
(= (expand '(a x b) 'x) '(a 2 b))
(= (expand '(x b) 'x) '(2 b))
(= (expand '(a x) 'x) '(a 2))
(= (expand '(a (x) b) 'x) '(a (2) b))
(= (expand '(a ((x)) b) 'x) '(a ((2)) b))
(set 'a 1 'b 2 'c 3)
(= (expand '(a b c) 'b 'a 'c ) '(1 2 3))
;; prolog mode with uppercase vars
(set 'X 2)
(= (expand '(a ((X)) b)) '(a ((2)) b))
;; env list as parameter
(set 'a "a" 'B "B" 'c "c" 'd "d")
(= (expand '(a (B (c) (d a B))) '((a 1) (B 2) (c 3) (d 4)))
'(1 (2 (3) (4 1 2))))
(= a "a") (= B "B") (= c "c") (= d "d")
;; default functor
(set 'Le:Le '(a (B (c) (d a B))) )
(set 'p '((a 1) (B 2) (c 3) (d 4)))
(= (expand Le p) '(1 (2 (3) (4 1 2))))
))
(define (test-explode )
(and
(= (explode "kakak" -1) '())
(= (explode "ABC" 4) '("ABC"))
(= (explode '(a b c d e f) -1) '())
(= (explode "new") '("n" "e" "w"))
(= (explode "newlisp" 3) '("new" "lis" "p"))
(= (explode "newlisp" 3 true) '("new" "lis"))
(= (explode "newlisp" 7 true) '("newlisp"))
(= (explode "newlisp" 8 true) '())
(= (explode '(a b c d e)) '((a) (b) (c) (d) (e)))
(= (explode '(a b c d e) 2) '((a b) (c d) (e)))
(= (explode '(n e w l i s p)) '((n) (e) (w) (l) (i) (s) (p)))
(= (explode '(n e w l i s p) 3) '((n e w) (l i s) (p)))
(= (explode '(n e w l i s p) 7 true) '((n e w l i s p)))
(= (explode '(n e w l i s p) 8 true) '())
(set 'D:D '(a b c d e f g))
(= (explode D 2) '((a b) (c d) (e f) (g)))
))
(define (test-extend)
(and
(= (extend '() '(a) '(b c)) '(a b c))
(= (extend '(a) '() '(b)) '(a b))
(= (extend '(a) '(b) '(c d)) '(a b c d))
(not (set 'l '()))
(= (extend l '(a) '(b c)) '(a b c))
(= (extend l '(d e)) '(a b c d e))
(not (set 'l nil))
(= (extend l "abc" "def") "abcdef")
(not (set 'l nil))
(= (extend l '(a) '(b c)) '(a b c))
)
)
(define (test-factor)
(= (apply * (factor 0x7FFFFFFFFFFFFFFF)) 0x7FFFFFFFFFFFFFFF))
(define (test-fcall) true)
(define (test-fft )
(= '((1 2) (3 4)) (ifft (fft '((1 2) (3 4))))))
(define (test-file-info )
(list? (file-info "qa-dot")))
(define (test-file? )
(and
(file? "qa-dot")
(= (file? "qa-dot" true) "qa-dot")
(file? "modules/")
(file? "modules")
(not (file? "modules" true))
))
(define (test-filter )
(and
(= (filter integer? '(1 1.1 2 2.2 3 3.3)) '(1 2 3))
(= (filter true? '(a nil b nil c nil)) '(a b c))
; default functor
(set 'D:D '(2 4 2 7 5 3 8))
(= (filter (curry < 5) D) '(7 8))
))
(define (test-find )
(and
(= 3 (find '(3 4) '(0 1 2 (3 4) 5 6 7 8)))
(= nil (find 9 '(1 2 3)))
(= 2 (find "W" "newlisp" 1))
(= $0 "w")
(= (find "newlisp" '("Perl" "Python" "newLISP") 1) 2)
; use a comparison functor
(= (find '(1 2) '((1 4) 5 6 (1 2) (8 9))) 3)
(= (find 3 '(8 4 3 7 2 6) >) 4)
(= (find 5 '((l 3) (k 5) (a 10) (z 22)) (fn (x y) (= x (last y)))) 1)
(= (find '(a ?) '((l 3) (k 5) (a 10) (z 22)) match) 2)
(= (find '(X X) '((a b) (c d) (e e) (f g)) unify) 2)
(define (has-it-as-last x y) (= x (last y)))
(= (find 22 '((l 3) (k 5) (a 10) (z 22)) has-it-as-last) 3)
(= (find "newlisp" '("Perl" "Python" "newLISP") (fn (x y) (regex x y 1))) 2)
; default functor
(set 'D:D '(0 1 2 (3 4) 5 6 7 8))
(= 3 (find '(3 4) D))
(set 'D:D "newlisp")
(= 2 (find "W" D 1))
))
(define (test-find-all)
(and
(= (find-all {\d+} "asdf2kjh44hgfhgf890") '("2" "44" "890"))
(= (find-all {(new)(lisp)} "newLISPisNEWLISP" (append $2 $1) 1) '("LISPnew" "LISPNEW"))
(set 'D:D "asdf2kjh44hgfhgf890")
(= (find-all {\d+} D) '("2" "44" "890"))
(set 'D:D "newLISPisNEWLISP")
(= (find-all {(new)(lisp)} D (append $2 $1) 1) '("LISPnew" "LISPNEW"))
(= (find-all {(^|(?<=,))("(([^"]|"")*)"|([^",]*))}
{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"", baby",10K})
'("Ten Thousand" "10000" " 2710 " "" "\"10,000\"" "\"It's \"\"10 Grand\"\", baby\"" "10K"))
))
(define (test-first )
(= 1 (first '(1 2 3 4)))
(= "n" (first "ewLISP"))
(= (array 2 '(1 2)) (first (array 3 2 (sequence 1 6))))
;; default functor
(set 'D:D '(a b c d e f g))
(= (first D) 'a)
(set 'D:D (array 7 '(a b c d e f g)))
(= (first D) 'a)
(not (catch (first '()) 'result))
)
(define (test-flat )
(set 'lst '(a (b (c d))))
(= (map (fn (x) (ref x lst)) (flat lst)) '((0) (1 0) (1 1 0) (1 1 1))))
(define (test-float )
(float? (float "1.234")))
(define (test-flt)
(= (flt 1.23) 1067282596)
(= (flt 0.8) 1061997773)
(= (flt -0.8) 3209481421))
(define (test-float? )
(float? 1.234))
(define (test-floor )
(= 1 (floor 1.5)))
(define (test-for , x lst1 lst2)
(set 'lst1 '())
(set 'lst2 '())
(for (x 10 0 3)
(push x lst1))
(for (x 10 0 3 (< x 7))
(push x lst2))
(and
(= lst1 '(1 4 7 10))
(= lst2 '(7 10)) )
)
(define (test-for-all)
(and
(for-all number? '(2 3 4 6 7))
(not (for-all number? '(2 3 4 6 "hello" 7)) )
(for-all (fn (x) (= x 10)) '(10 10 10 10 10))
))
; use qa-pipe, qa-pipefork, qa-setsig in qa-specific-test/ to test fork
(define (test-fork) (integer? (fork (exit))))
(define (test-format )
(and
(= (format "%d" 1.23) "1")
(= (format "%5.2f" 10) "10.00")
(= (format "%c %s %d %g" 65 "hello" 123 1.23) "A hello 123 1.23")
(= (format "%5.2s" "hello") " he")
; args passed in a list
(= (format "%d" '(1.23)) "1")
(= (format "%5.2f" '(10)) "10.00")
(= (format "%c %s %d %g" '(65 "hello" 123 1.23)) "A hello 123 1.23")
(= (format "%5.2s" '("hello")) " he")
(set 'data '((1 "a001" "g") (2 "a101" "c") (3 "c220" "g")))
(set 'result (map (fn (x) (format "%3.2f %5s %2s" (nth 0 x) (nth 1 x) (nth 2 x))) data))
(set 'result (map (fn (x) (format "%3.2f %5s %2s" (x 0) (x 1) (x 2))) data))
(= result '("1.00 a001 g" "2.00 a101 c" "3.00 c220 g"))
(not (catch (format "%%" 1) 'result))
(not (catch (format "%10.2lf" 123) 'result))
(= (test-format-r '(("foo" "bar") ("foo" "baz")))
"[ [ 'foo', 'bar' ], [ 'foo', 'baz' ] ]")
; test 64-bit formatting
(if (find ostype '("Windows")) ;; Win32 and Win64
(begin
(and
(= (format "%I64d" 0x7fffffffffffffff) "9223372036854775807")
(= (format "%I64x" 0x7fffffffffffffff) "7fffffffffffffff")
(= (format "%I64u" 0x7fffffffffffffff) "9223372036854775807")
(= (format "%I64d" 0x8000000000000000) "-9223372036854775808")
(= (format "%I64x" 0x8000000000000000) "8000000000000000")
(= (format "%I64u" 0x8000000000000000) "9223372036854775808")
(= (format "%I64d" 0xFFFFFFFFFFFFFFFF) "-1")
(= (format "%I64x" 0xFFFFFFFFFFFFFFFF) "ffffffffffffffff")
(= (format "%I64u" 0xFFFFFFFFFFFFFFFF) "18446744073709551615"))
)
(begin ;; UNIX like OS
(if (= ostype "Tru64Unix") ;TRU64
(begin
(and
(= (format "%d" 0x7fffffff) "2147483647")
(= (format "%d" 0xffffffff) "-1")
(= (format "%u" 0xffffffff) "4294967295")
(= (format "%i" 0x7fffffff) "2147483647")
; truncate
(= (format "%d" 0x7fffffffffffffff) "-1")
(= (format "%u" 0x7fffffffffffffff) "4294967295")
(= (format "%x" 0x7fffffffffffffff) "ffffffff")
(= (format "%X" 0x7fffffffffffffff) "FFFFFFFF")
(= (format "%ld" 0x7fffffffffffffff) "9223372036854775807")
(= (format "%lu" 0xffffffffffffffff) "18446744073709551615")
(= (format "%li" 0x7fffffffffffffff) "9223372036854775807")
(= (format "%lx" 0x7fffffffffffffff) "7fffffffffffffff")
(= (format "%ld" 0x8000000000000000) "-9223372036854775808")
(= (format "%lx" 0x8000000000000000) "8000000000000000")
(= (format "%lu" 0x8000000000000000) "9223372036854775808")
(= (format "%ld" 0xFFFFFFFFFFFFFFFF) "-1")
(= (format "%lx" 0xFFFFFFFFFFFFFFFF) "ffffffffffffffff")
(= (format "%lu" 0xFFFFFFFFFFFFFFFF) "18446744073709551615"))
)
(begin ; all other UNIX, Linux, OS X
(and
(= (format "%d" 0x7fffffff) "2147483647")
(= (format "%d" 0xffffffff) "-1")
(= (format "%u" 0xffffffff) "4294967295")
; truncate
(= (format "%d" 0x7fffffffffffffff) "-1")
(= (format "%u" 0x7fffffffffffffff) "4294967295")
(= (format "%x" 0x7fffffffffffffff) "ffffffff")
(= (format "%X" 0x7fffffffffffffff) "FFFFFFFF")
(= (format "%lld" 0x7fffffffffffffff) "9223372036854775807")
(= (format "%llx" 0x7fffffffffffffff) "7fffffffffffffff")
(= (format "%llu" 0x7fffffffffffffff) "9223372036854775807")
(= (format "%lld" 0x8000000000000000) "-9223372036854775808")
(= (format "%llx" 0x8000000000000000) "8000000000000000")
(= (format "%llu" 0x8000000000000000) "9223372036854775808")
(= (format "%lld" 0xFFFFFFFFFFFFFFFF) "-1")
(= (format "%llx" 0xFFFFFFFFFFFFFFFF) "ffffffffffffffff")
(= (format "%llu" 0xFFFFFFFFFFFFFFFF) "18446744073709551615"))
)
)
))))
(define (test-format-r obj , s)
(cond
((string? obj) (format "'%s'" obj))
((list? obj) (format "[ %s ]" (join (map test-format-r obj) ", ")))
))
(define (test-fv )
(< (sub (fv 0.1 10 1000 0 0) -15937.4246) 1e-05))
(define (test-gammai )
(< (abs (sub (gammai 4 5) 0.734974)) 1e-05))
(define (test-gammaln )
(< (abs (sub 120 (exp (gammaln 6)))) 1e-05))
(define (test-gcd)
(and
(= (gcd 0) 0)
(= (gcd 1) 1)
(= (gcd 12 36) 12)
(= (gcd 12 36 6) 6)
(= (gcd 12 36 6 3) 3)
))
(define (test-get-char )
(and
(= 65 (get-char (address "A")) (get-char "ABC"))
(set 'D:D "ABC")
(= 65 (get-char D))
))
(define (test-get-float )
(and
(= 1.234 (get-float (pack "lf" 1.234)))
(= (get-float (address (get-long (address 17.4)))) 17.4)
(= (get-long (address (get-float (address 4625590882276894310)))) 4625590882276894310)
) )
(define (test-get-int )
(and
(= 123456789 (get-int (pack "ld" 123456789)))
(set 'adr (pack "ldld" 0xaabbccdd 0xccddeeff))
(= (format "%x" (get-int adr)) "aabbccdd")
(= (format "%x" (get-int (address adr))) "aabbccdd")
(= (format "%x" (get-int (+ (address adr) 0))) "aabbccdd")
(= (format "%x" (get-int (+ (address adr) 4))) "ccddeeff")
(set 'adr (pack "> ldld" 0xaabbccdd 0xccddeeff))
(= adr "\170\187\204\221\204\221\238\255")
(set 'adr (pack "< ldld" 0xaabbccdd 0xccddeeff))
(= adr "\221\204\187\170\255\238\221\204")
(set 'buff (pack "lulululululululu" 1 2 3 4))
(apply and (map (fn (i) (= (+ i 1) (get-int (+ (* i 4) (address buff))))) '(0 1 2 3)))
))
(define (test-get-long)
(set 'adr (pack "Ld" -1))
(= -1 (get-long adr)))
(define (test-get-string )
(= "hello" (get-string (address "hello"))))
(define (test-get-url )
(and
(starts-with (get-url "file://qa-dot") "#!/usr/bin/env newlisp")
(= "ERR: HTTP bad formed URL" (get-url ""))
))
(define (test-global)
(= global-myvar 123))
(define (test-global?)
(and
(global? 'global-myvar)
(global? 'println)
))
(define (test-history)
(= '((qa)) (history true))
(= '(qa) (history))
)
(define (test-if )
(and
(if true true)
(if nil nil true)
(if 'nil nil true)
(if '() nil true)
(= (if '()) '())
(= (if nil 1 '() 2) '())
(= (if nil '() '()) '())
(= (if true '() '()) '())
(= (if nil 1 nil 2 nil 3 true 4 3) 4)
(= (if nil 1 nil 2 nil 3 nil 4 3) 3)
; anaphoric $it
(if 123 (= $it 123))
))
(define (test-if-not )
(if-not nil
true nil))
(define (test-ifft )
(= '((1 2) (3 4)) (ifft (fft '((1 2) (3 4))))))
(define (test-import )
(primitive? import))
(define (test-inc , x)
(and
(= (inc x) 1)
(= (inc x) 2)
(set 'l '(1 2 3 4))
(= (inc (l 1)) 3)
(= (dec (nth 0 l) 2) -1)
(= (dec (last l) 0.1) 3.9)
(= (inc (+ 3 4)) 8)
(= l '(-1 3 3 3.9))
))
(define (test---) (test-++))
(define (test-++ , x)
(and
(= (++ x) 1)
(= (++ x) 2)
(= (++ x 3) 5)
(set 'l '(0 nil 2.5))
(= (-- (l 0)) -1)
(= (++ (l 1)) 1)
(= (++ (l 2) 2) 4)
(= l '(-1 1 4))
)
)
(define (test-index )
(= '(1 3) (index (lambda (x) (> x 3)) '(1 5 2 6 2 0))))
(define (test-inf?)
(inf? (div 1 0)))
(define (test-integer )
(and
(integer? (int "12345"))
(= (int " 12345") 12345)
(= (int "9223372036854775807") 9223372036854775807)
(= (int "-9223372036854775808") -9223372036854775808)
(= (int 0.0) 0)
(= (int 1e30) 9223372036854775807)
(= (int -1e30) -9223372036854775808)
(= (int 0x8000000000000000) (int "0x8000000000000000"))
(set 'D:D 12345)
(= (int D) 12345)
(= (int "gg" 99) 99)
(= (int "ff" 99 16) 255)
(= (int "-ff" 99 16) -255)
(= (int "0b101010") 42)
(= (int "101010" 0 2) 42)
))
(define (test-int) (test-integer))
(define (test-integer? )
(and
(integer? 12345)
(integer? 9223372036854775807)
(integer? -9223372036854775808)
(integer? 0x7FFFFFFFFFFFFFFF)
(integer? 0xFFFFFFFFFFFFFFFF)
))
(define (test-intersect )
(and
(= (intersect '(3 0 2 4 1) '(1 4 2 5)) '(2 4 1))
(set 'L '(a b c d e f))
(= (intersect L L) L)
)
)
(define (test-invert )
(set 'A '((-1 1 1) (1 4 -5) (1 -2 0)))
(set 'I (multiply A (invert A)))
(set 'J (multiply (array 3 3 (flat A)) (invert (array 3 3 (flat A)))))
(and (< (sub 1 (nth 0 (nth 0 I))) 1e-06)
(< (sub 1 (nth 1 (nth 1 I))) 1e-06)
(< (sub 1 (nth 2 (nth 2 I))) 1e-06)
(= I (array-list J))
(not (invert '((0 1 0) (1 0 1) (0 0 0))) )
))
(define (test-irr )
(< (abs (sub (irr '(-1000 500 400 300 200 100)) 0.20272)) 0.0001))
(define (test-join )
(and
(= "this is a sentence" (join '("this" "is" "a" "sentence") " "))
(= "this_is_a_sentence" (join '("this_" "is_" "a_" "sentence")))
(= "" (join '()))
(= (join '("A" "B" "C") "-") "A-B-C")
(= (join '("A" "B" "C") "-" true) "A-B-C-")
))
(define (test-json-error)
(and
(not (json-parse {{"key" : "value" , "hello" "world"}}))
(= (json-error) '("missing : colon" 28))
))
; see also qa-specific-tests/qa-json
(define (test-json-parse)
(and
(= (json-parse { {"key" : "value" , "hello" : "world", "array" : [1, 2, 3, 4, 5]} })
'(("key" "value") ("hello" "world") ("array" (1 2 3 4 5))))
(= (json-parse { [1,2,3,4,5,6,{ "nested" : 777}, 8, 9] } )
'(1 2 3 4 5 6 (("nested" 777)) 8 9) )
))
(define (test-kmeans-query) true)
(define (test-kmeans-train)
(let (data '(
(1.85 1.89 0.11)
(2.11 2.14 0.85)
(2.48 2.26 0.19)
(2.43 2.14 1.59)
(2.29 4.18 1.06)
(1.17 4.46 1.02)
(3.12 3.1 1.4)
(9.44 2.65 7.37)
(8.16 3.83 8.93)
(8.49 5.31 7.47)
(7.01 4.2 11.9)
(6.57 4.96 11.91)
(8.63 2.51 8.11)
(7.18 3.46 8.7)
(8.17 6.59 7.49)
(6.79 8.72 8.62)
(5.44 5.9 5.57)
(7.56 7.93 5.06)
(3.61 7.95 5.11)
(6.77 6.04 3.76) ))
(< (abs (apply add (map sub (kmeans-train data 3 'MAIN:KMT)
'(403.8613998 122.6051922 91.49019772 85.06633163 82.74597619)))) 0.000001)
(= KMT:labels '(2 2 2 2 2 2 2 3 3 3 3 3 3 3 1 1 1 1 1 1))
(= KMT:clusters '((14 15 16 17 18 19) (0 1 2 3 4 5 6) (7 8 9 10 11 12 13)))
(< (abs (apply add (map sub KMT:deviations '(2.457052209 1.240236975 2.260089397)))) 0.000001)
(< (abs (apply add (map sub (flat KMT:centroids) (flat '((6.39 7.188333333 5.935)
(2.207142857 2.881428571 0.8885714286)
(7.925714286 3.845714286 9.198571429)))))) 0.000001)
(< (abs (apply add (map sub (kmeans-query '(1 2 3) KMT:centroids)
'(8.036487279 2.58693657 9.475994267)))) 0.000001)
)
)
(define (test-lambda? )
(lambda? qa)
)
(define (test-last )
(= 'f (last '(a b c d e f)))
(= "p" (last "newlisp"))
(= (array 2 '(5 6)) (last (array 3 2 (sequence 1 6))))
;; default functor
(set 'D:D '(a b c d e f g))
(= (last D) 'g)
(set 'D:D (array 7 '(a b c d e f g)))
(= (last D) 'g)
(not (catch (last '()) 'result))
)
(define (test-last-error)
(= (last-error 1) '(1 "not enough memory"))
)
(define (test-legal?)
(and
(legal? "abc")
(not (legal? "a b c"))
(set 'greek (pack "cccccccccccccccccc" 206 160 206 181 206 187 206 181 206 185 206
172 206 180 206 181 207 137))
(legal? greek)
))
(define (test-length )
(> (length (symbols)) 100)
(- 7 (length "newlisp"))
(= 3 (length 123))
(= 3 (length 123.456))
(= 1 (length 0))
(= 1 (length 0.789))
(= 7 (length 10e5))
)
(define (test-let )
(set 'a 123)
(set 'b 456)
(set 'p 111)
(set 'q 222)
(and
(let ((a 1) (b 2))
(= (+ a b) 3))
(= a 123)
(= b 456)
(let (p 3 q 4)
(= (+ q p) 7))
(= p 111)
(= q 222)
))
(define (test-letex)
(and
(= (letex (x '* y 3 z 4) (x y z)) 12)
(= (letex (x 1 y 2 z 3) (quote (x y z))) '(1 2 3))
(= (letex (x 1 y 2 z 3) '(x y z)) '(1 2 3))
(= (letex (x 1 y 2 z 3) '('x (quote y) z)) '('1 (quote 2) 3))
(= (letex (x 1) 'x) 1)
(set 'x 123 'y 456)
(= (letex (x 'y) 'x) 'y)
(= (letex (x 'y) x) 456)
(= (letex (x '(+ 3 4)) 'x) '(+ 3 4))
(= (letex (x '(+ 3 4)) x) 7)
))
(define (test-letn)
(set 'x 0 'y 0 'z 0)
(and
(= (letn ((x 1) (y (+ x 1)) (z (+ y 1))) (list x y z)) '(1 2 3))
(= 0 x y z))
)
(define (test-list )
(and (list? (list 1 2 3 4 5)) (= '(1) (list 1)) (= '(1 nil) (list
1 'nil))))
(define (test-list? )
(and (list? '(1 2 3 4 5)) (list? '())))
(define (test-load )
(write-file "junk" "(+ 3 4)")
(load "junk"))
(define (test-local)
(set 'a 10 'b 20)
(and
(= (local (a b) (set 'a 1 'b 2) (+ a b)) 3)
(= a 10)
(= b 20)))
(define (test-set-locale)
(list? (set-locale)))
(define (test-log )
(and
(= 1 (log (exp 1)))
(= 1 (log (exp 1) (exp 1)))
)
)
(define (test-lookup )
(and
(= 3 (lookup 1 '((2 3 4) (1 2 3))))
(= 2 (lookup 1 '((2 3 4) (1 2 3)) 1))
; default functor
(set 'D:D '((a 1 2 3) (b 4 5 6) (c 7 8 9)))
(= 6 (lookup 'b D -1))
))
(define (test-lower-case )
(= "abcdefghijklmnopqrstuvwxyz" (lower-case "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
(define (test-macro)
(= (unless testmacro (macro (testmacro x) (+ x x)))
(lambda-macro (x) (expand '(+ x x))))
)
(define (test-macro? )
(macro?
(define-macro (foo-macro))))
(define (test-main-args )
(and
(list? (main-args))
(list? $main-args)
(= $main-args (main-args))
(= ($main-args 0) ((main-args) 0) (main-args 0))
(= ($main-args -1) ((main-args) -1))
(= ($main-args -1) (main-args -1))
))
(define (test-make-dir )
(and (make-dir "foodir") (remove-dir "foodir")))
(define (test-map )
(and (= '(11 22 33) (map + '(10 20 30) '(1 2 3)))
(= '(2 4 6) (map (lambda (x) (+ x x)) '(1 2 3)))
(set 'D:D '(1 2 3 4 5))
(= (map pow D) '(1 4 9 16 25))
(= (map pow (array 5 D)) '(1 4 9 16 25))
))
(define (test-mat)
(set 'A '((1 2 3) (4 5 6)))
(set 'B A)
(and
(= (mat + A B) '((2 4 6) (8 10 12)))
(= (mat - A B) '((0 0 0) (0 0 0)))
(= (mat * A B) '((1 4 9) (16 25 36)))
(= (mat / A B) '((1 1 1) (1 1 1)))
(= (mat + A 2) '((3 4 5) (6 7 8)))
(= (mat - A 2) '((-1 0 1) (2 3 4)))
(= (mat * A 2) '((2 4 6) (8 10 12)))
(= (mat / A 2) '((0.5 1 1.5) (2 2.5 3)))
(= (mat + A 5) '((6 7 8) (9 10 11)))
(= (mat - A 2) '((-1 0 1) (2 3 4)))
(= (mat * A 3) '((3 6 9) (12 15 18)))
(= (mat / A 10) '((.1 .2 .3) (.4 .5 .6)))
(set 'op +)
(= (mat op A B) '((2 4 6) (8 10 12)))
(set 'op '+)
(= (mat op A B) '((2 4 6) (8 10 12)))
; default functor
(set 'DA:DA A)
(set 'DB:DB B)
(= (mat + DA DB) '((2 4 6) (8 10 12)))
(set 'B '((-1 1 1) (1 4 -5) (1 -2 0)))
(set 'A '((1 2 3) (4 5 6)))
(not (catch (mat + A B) 'result))
(starts-with result "ERR: wrong dimensions")
( = (mat * '((1 2 3)) -1) '((-1 -2 -3)))
))
(define (test-match)
(and
(= (match '(a (b ?) d e *) '(a (b c) d e f g) true) '(a (b c) d e (f g)) )
(= (match '(a (b ?) d e *) '(a (b c) d e f g) ) '(c (f g)) )
(= (match '(a * b x) '(a b c d b x e f b x) true) '(a (b c d b x e f) b x) )
(= (match '(a * b x) '(a b c d b x e f b x) ) '((b c d b x e f)) )
(= (match '(? (?) x * ? (? e)) '(a (b) x y c (d e)) true) '(a (b) x (y) c (d e)) )
(= (match '(? (?) x * ? (? e)) '(a (b) x y c (d e))) '(a b (y) c d) )
(= (match '(a * b) '(a x b) true) '(a (x) b) )
(= (match '(a * b) '(a x b)) '((x)) )
(= (match '(a * b) '(a b) true) '(a () b) )
(= (match '(a * b) '(a b)) '(()) )
(= (match '( (? ?) * ) '( (x y) ) true) '((x y) ()) )
(= (match '( (? ?) * ) '( (x y) )) '(x y ()) )
(match '(+) '(a))
(match '(+) '(a b))
(not (match '(+) '()))
; default functors
(set 'P:P '(a (b ?) d e *) )
(set 'M:M '(a (b c) d e f g))
(true? (match P M))
))
(define (test-max )
(and (= 10 (max 3 6 10 8)) (= 1.2 (max 0.7 0.6 1.2))))
(define (test-member )
(and
(= '(3 4) (member 3 '(1 2 3 4)))
(= (member "LISP" "newLISP") "LISP")
(= (member "LI" "newLISP") "LISP")
(= (member "" "newLISP") "newLISP")
(not (member "xyz" "newLISP"))
(not (member "new" "this is NEWLISP" 0))
(= (member "new" "this is NEWLISP" 1) "NEWLISP")
; default functor
(set 'D:D '(1 2 3 4))
(= '(3 4) (member 3 D))
(set 'D:D "newLISP")
(= "LISP" (member "LI" D))
)
)
(define (test-min )
(and (= 3 (min 3 6 10 8)) (= 0.6 (min 0.7 0.6 1.2))))
(define (test-mod )
(and (< (sub (mod 10.5 3.3) 0.6) 0.0001)
(< (sub (mod 10 3) 1) 0.0001)
(< (sub (mod 10.5) 0.5) 0.0001)
))
(define (test-mul )
(and
(= (mul) 1)
(= 1e-09 (mul 0.0001 1e-05))
))
(define (test-multiply )
(let ((A '((1 2 3) (4 5 6))) (B '((1 2) (1 2) (1 2))))
(and
(= '((6 12) (15 30)) (multiply A B))
(= (array 2 2 (flat '((6 12) (15 30))))
(multiply (array 2 3 (flat A)) (array 3 2 (flat B))))
)
))
(define (test-net-accept )
(and
(set 'net-listen-test (set 'listen (net-listen 12345)))
(if (zero? (& (sys-info -1) 512)) ; IPv4
(set 'net-connect-test (set 'connect (net-connect "localhost" 12345)))
(set 'net-connect-test (set 'connect (net-connect "::1" 12345)))
)
(set 'server (net-accept listen))
(set 'net-send-test (= (net-send server "hello") 5))
(set 'net-select-test (net-select connect "r" 100000))
(set 'net-peek-test (= (net-peek connect) 5))
(set 'net-receive-test (net-receive connect buff 20))
(= buff "hello")
(set 'net-sessions-test (and
(find listen (net-sessions))
(find connect (net-sessions))
(find server (net-sessions))))
(set 'net-local-test (= (net-local server) (net-peer connect)))
(set 'net-peer-test (= (net-local connect) (net-peer server)))
(set 'net-close-test (net-close connect))
(set 'net-close-test (net-close server))
(set 'net-close-test (net-close listen))
(not (net-error))
))
(define (test-net-close ) net-close-test)
(define (test-net-connect ) net-connect-test)
(define (test-net-error )
(and
(not (net-close 12345))
(list? (net-error))))
(define (test-net-eval) true) ;; see special test prog
(define (test-net-interface) true) ;; test manually on multihoned machine
(define (test-net-ipv)
(and (= (net-ipv) 4) (= (net-ipv 6) 6) (= (net-ipv 4) 4)))
(define (test-net-listen ) net-listen-test)
(define (test-net-local ) net-local-test)
(define (test-net-lookup )
(if (zero? (& (sys-info -1) 512)) ; IPv4
(and (= "127.0.0.1" (net-lookup "localhost")) (string? (net-lookup "127.0.0.1")))
(and (= "localhost" (net-lookup "::1")) (= "::1" (net-lookup "localhost")))
)
)
(define (test-net-packet) true);
(define (test-net-peek ) net-peek-test)
(define (test-net-peer ) net-peer-test)
(define (test-net-ping) true) ; test manualyy as superuser
(define (test-net-receive ) net-receive-test)
(define (test-net-receive-from)
(and
(set 'sock (net-listen 1234 "localhost" "udp"))
(set 'net-send-to-test (net-send-to "localhost" 1234 "hello" sock))
(set 'net-select-test (net-select sock "r" 1000000) )
(= "hello" (first (net-receive-from sock 10)))
(net-close sock)))
(define (test-net-receive-udp)
(write-file "udptest.lsp"
[text]
(map set '(in out sid) (map int (slice (main-args) 2)))
(semaphore sid 1) ; signal parent to start
(set 'msg (net-receive-udp in 20 2000000))
(sleep 100)
(if (not msg) (exit))
(net-send-udp "localhost" out (upper-case (first msg)))
(exit)
[/text]
)
(and
(set 'sid (semaphore))
(if (find ostype '("Windows" "OS/2"))
(process (string "newlisp udptest.lsp " 10001 " " 10002 " " sid))
(process (string "./newlisp udptest.lsp " 10001 " " 10002 " " sid)))
;(println "---------- testing UDP Win32/64 and OS/2 -------------")
;(println "waiting ...");
(semaphore sid -1) ; wait for child process
(sleep 100)
;(println "sending ...")
(net-send-udp "localhost" 10001 "hello")
;(println "receiving ...")
(set 'msg (net-receive-udp 10002 20 3000000))
;(println "msg:" msg)
(or (delete-file "udptest.lsp") true)
;(println "deleting semaphore:" (semaphore sid 0)) ; delete semaphore
;(println "------------------------------------------")
(if msg (set 'net-send-udp-test (= "HELLO" (first msg)) ) )))
(if (find ostype '("Linux" "BSD" "OSX" "SunOS" "AIX" "Tru64Unix" "Cygwin"))
(define (test-net-receive-udp)
(fork (begin (sleep 500) (net-send-udp "localhost" 10001 "hello")))
(set 'net-send-udp-test (= "hello" (first (net-receive-udp 10001 10)))))
)
(define (test-net-select ) net-select-test)
(define (test-net-send ) net-send-test)
(define (test-net-send-to ) net-send-to-test)
(define (test-net-send-udp ) net-send-udp-test)
(define (test-net-service ) (= 21 (net-service "ftp" "tcp")))
(define (test-net-sessions ) net-sessions-test)
(define (test-new)
(new QA 'MAIN:QA2))
(define (test-nil?)
(and
;test symbol-nil = logic-nil in order compare of count
(= (count '(nil true) (map (curry < 3) '(1 2 4 5))) '(2 2))
(= nil (not (nil? nil)))
(= '(nil true) (map nil? '(a nil)))))
(define (test-null?)
(= (map null? '(1 0 2 0.0 "hello" "" (a b c) () nil true (lambda) (fn) (lambda ())))
'(nil true nil true nil true nil true true nil true true nil)))
(define (test-normal )
(and (float? (normal)) (float? (normal 10 3)) (list? (normal 10
3 100))))
(define (test-not )
(and (not (not (not '()))) (not (not (not (not (not nil))))) (not
(not (not (not true))))
(= '(true true true) (map not '(nil nil nil)))
(= '(nil nil nil) (map not '(true true true)))))
(define (test-now )
(and
(= (length (now)) 11)
(= 3600 (round (- (apply date-value (now 60)) (date-value)) 2))
)
)
(define (test-nper )
(< (sub (nper 0.1 1000 100000 0 0) -25.15885793) 1e-08))
(define (test-npv )
(< (sub (npv 0.1 '(-10000 3000 4200 6800)) 1188.443412) 1e-06))
(define (test-nth , l)
(and
(set 'l '(0 1 2))
(= 0 (nth 0 l))
(= 1 (nth 1 l))
(= 2 (nth 2 l))
(= 2 (nth -1 l))
(= (nth 0 "lisp") "l")
(= (nth 1 "lisp") "i")
(= (nth 3 "lisp") "p")
(= (nth -4 "lisp") "l")
(= (nth 0 "") "")
(set 'l '(a b (c d) (e f)))
(= 'a (l 0))
(= '(c d) (l 2))
(= 'c (l 2 0))
(= 'f (l -1 -1))
(= 'c (l '(2 0)))
(= 'f (l '(-1 -1)))
(= (l '()) l)
(set 'myarray (array 3 2 (sequence 1 6)))
(= (array 2 '(3 4)) (myarray 1))
(= 6 (myarray -1 -1))
(= (myarray '()) myarray)
(= (array 2 '(3 4)) (myarray '(1)))
(= 6 (myarray '(-1 -1)))
(= "L" ("newLISP" 3))
(constant 'constL '((1 2 3) (a b c)))
(set 'aref '(1 2))
(= (constL 1 2) 'c)
(= (nth '(1 2) constL) 'c)
(= (nth (list (- 2 1) (+ 1 1)) constL) 'c)
(= (nth aref constL) 'c)
(= (nth '() constL) constL)
; default functor
(set 'D:D '(a b (c d) (e f)))
(= 'a (D 0))
(= '(c d) (D 2))
(= 'c (D 2 0))
(= 'f (D -1 -1))
(= 'c (D '(2 0)))
(= 'f (D '(-1 -1)))
(= 'a (nth 0 D))
(= '(c d) (nth 2 D))
))
(define (test-number?)
(and
(number? 1)
(number? 1.23)
(not (number? 'x))
(not (number? "abc"))
(not (number? '(a b c)))
)
)
(define (test-open )
(and
(set 'fle (open "qa-dot" "read"))
(close fle)))
(define (test-odd?)
(and (odd? 3) (not (odd? 2)) (odd? 3.34) (not (odd? 2.999))))
(define (test-or )
(and (or (or (= 1 2) nil nil) (or nil nil nil true)) (not (or nil
(= "a" "b") nil))))
(define (test-pack )
(and
(= (pack "c c c" 65 66 67) "ABC")
(= (unpack "c c c" "ABC") '(65 66 67))
(set 's (pack "c d u" 10 12345 56789))
(= (unpack "c d u" s) '(10 12345 56789))
(set 's (pack "s10 f" "result" 1.23))
(= (first (unpack "s10 f" s)) "result\000\000\000\000")
(< (- (last (unpack "s10 f" s)) 1.23) 0.00001)
(set 's (pack "s3 lf" "result" 1.23))
(= (first (unpack "s3 f" s)) "res")
(= (pack "ccc" 65 66 67) "ABC")
(= (unpack "ccc" "ABC") '(65 66 67))
(set 's (pack "cdu" 10 12345 56789))
(= (unpack "cdu" s) '(10 12345 56789))
(set 's (pack "s10f" "result" 1.23))
(= (first (unpack "s10f" s)) "result\000\000\000\000")
(< (- (last (unpack "s10f" s)) 1.23) 0.00001)
(set 's (pack "s3lf" "result" 1.23))
(= (first (unpack "s3f" s)) "res")
(= "\001\000" (pack "<d" 1))
(= "\000\001" (pack ">d" 1))
(= "\001\000\000\000" (pack "<ld" 1))
(= "\000\000\000\001" (pack ">ld" 1))
(= '(12345678) (unpack "ld" (pack "ld" 12345678)))
(= '(12345678) (unpack "<ld" (pack "<ld" 12345678)))
(= '(12345678) (unpack ">ld" (pack ">ld" 12345678)))
(= (unpack "bbbbbbbb" (pack "<lf" 1.234)) '(88 57 180 200 118 190 243 63))
(= (unpack "bbbbbbbb" (pack ">lf" 1.234)) '(63 243 190 118 200 180 57 88))
(= (format "%20.2f" (first (unpack "lf" (pack "lf" 1234567890123456)))) " 1234567890123456.00")
))
(define (test-parse )
(and
(= 3 (length (parse "hello hi there")))
(= (parse "abcbdbe" "b") '("a" "c" "d" "e"))
(= (parse "," ",") '("" ""))
(= (parse "hello regular expression 1, 2, 3" {,\s*|\s+} 0)
'("hello" "regular" "expression" "1" "2" "3"))))
(define (test-parse-date) (test-date-parse))
(define (test-prefix)
(set 's 'Foo:bar)
(= s (sym (term s) (prefix s))))
(define (test-peek)
(set 'fle (open "qa-dot" "r"))
(= (peek fle) (first (file-info "qa-dot")))
(close fle))
(define (test-pipe)
(write-file "pipe-child.lsp"
[text]
(set 'msg (read-line (int (nth 2 (main-args)))))
(write-line (int (nth 3 (main-args))) (upper-case msg))
(exit)
[/text]
)
(and
(set 'channel (pipe))
(set 'in (first channel))
(set 'out (last channel))
(if (find ostype '("Windows" "OS/2"))
(process (string "newlisp pipe-child.lsp " in " " out))
(process (string "./newlisp pipe-child.lsp " in " " out)))
(sleep 500)
(write-line out "hello there")
(sleep 500)
(= (read-line in) "HELLO THERE")
(delete-file "pipe-child.lsp")
)
)
;(if (find ostype '("Linux" "BSD" "OSX" "Solaris" "SunOS" "Aix" "True64Unix" "Cygwin"))
(if (find ostype '("BSD" "OSX" "Solaris" "SunOS" "Aix" "True64Unix" "Cygwin"))
(define (test-pipe)
(set 'channel (pipe))
(set 'in (first channel))
(set 'out (last channel))
(fork (write-line out (upper-case (read-line in))))
(write-line out "hello there")
(sleep 1000)
(= (read-line in) "HELLO THERE")
)
)
(define (test-pmt )
(< (sub (pmt 0.1 10 100000 0 0) -16274.53949) 1e-05))
(define (test-pop , r l)
(set 'r '())
(set 'l '(1 2 3 4 5 6 7 8 9 0))
(dotimes (x 10)
(push (pop l) r))
(and (= r '(0 9 8 7 6 5 4 3 2 1))
(set 'l '(a b (c d (x) e)))
(= 'x (pop l '(2 2 0)))
(set 'lst '(1 2 3 (4 5)()))
(push 'x lst -1 -1)
(= lst '(1 2 3 (4 5) (x)))
(push 'y lst -1 0)
(= lst '(1 2 3 (4 5) (y x)))
(push 'z lst -1 1)
(= lst '(1 2 3 (4 5) (y z x)))
(push 'p lst 4)
(= lst '(1 2 3 (4 5) p (y z x)))
(push 'q lst -2)
(= lst '(1 2 3 (4 5) p q (y z x)))
(push 'a lst 3 -3)
(= lst '(1 2 3 (a 4 5) p q (y z x)))
(= (pop lst 3 -3) 'a)
(= (pop lst -2) 'q)
(= (pop lst 4) 'p)
(= (pop lst -1 1) 'z)
(= (pop lst -1 0) 'y)
(= (pop lst -1 -1) 'x)
(= lst '(1 2 3 (4 5)()))
; test pop string
(set 's "newLISP")
(= (pop s) "n")
(= s "ewLISP")
(= (pop s 2) "L")
(= s "ewISP")
(= (pop s -1) "P")
(= s "ewIS")
(= (pop s -2 2) "IS")
(= s "ew")
(= (pop s -2 10) "ew")
(= s "")
(set 's "123456789")
(= (pop s 5) "6")
(= (pop s 5 -1) "")
(= s "12345789")
(set 's "123456789")
(= (pop s 5 5) "6789")
(set 's "x")
(= (pop s) "x")
(= s "")
(= (pop s) "")
(= (pop s) "")
(= s "")
; default functor
(set 'D:D '(a b (c d (x) e)))
(= 'x (pop D '(2 2 0)))
))
(define (test-pop-assoc)
(and
(set 'L '((a (b 1) (c (d 2)))))
(= (pop-assoc 'a L) '(a (b 1) (c (d 2))))
(= L '())
(set 'L '((a (b 1) (c (d 2)))))
( = (pop-assoc '(a b) L) '(b 1))
(= L '((a (c (d 2)))))
(set 'L '((a (b 1) (c (d 2)))))
(= (pop-assoc '(a c) L) '(c (d 2)))
(= L '((a (b 1))))
(set 'L '((a (b 1) (c (d 2)))))
(= (pop-assoc (list 'a 'c 'd) L) '(d 2))
(= L '((a (b 1) (c))))
(= (pop-assoc '(a c) L) '(c))
(= L '((a (b 1))))
(= (pop-assoc '(a b) L) '(b 1))
(= L '((a)))
(= (pop-assoc 'a L) '(a))
(= L '())
; default functor
(set 'D:D '((a (b 1) (c (d 2)))))
(= (pop-assoc 'a D) '(a (b 1) (c (d 2))))
(= D:D '())
; pop-assoc last, should disable nested last-element optimizations (10.5.4)
(= (set 'data '()) '())
(push '(1 (k_1 "v_1")) data)
(set 'result (push '(k_2 "v_2") (assoc 1 data) -1))
(pop-assoc '(1 k_2) data)
(= result (push '(k_2 "v_2") (assoc 1 data) -1))
)
)
(define (test-post-url )
(= "ERR: HTTP bad formed URL" (post-url "" "abc" "def")))
(define (test-pow )
(and
(= 1024 (pow 2 10))
(= 100 (pow 10))
))
(define (test-pretty-print)
(= (pretty-print) '(80 " " "%1.16g"))
)
(define (test-primitive? )
(primitive? primitive?))
(define (test-print )
(device (open "testprint" "w"))
(print "hello")
(close (device))
(and (= "hello" (read-file "testprint"))
(delete-file "testprint")))
(define (test-println )
(device (open "testprintln" "w"))
(print "hello")
(close (device))
(and
(= "hello" (slice (read-file "testprintln") 0 5))
(delete-file "testprintln")))
(define (test-prob-f)
(and
(< (abs (sub (prob-f 6.59 3 4) 0.05)) 0.001)
(< (abs (sub (prob-f 2.79 12 11) 0.05)) 0.001)
(< (abs (sub (prob-f 16.69 3 4) 0.01)) 0.0001)
(< (abs (sub (prob-f 4.40 12 11) 0.01)) 0.0001)
))
(define (test-prob-chi2)
(and
(< (abs (sub (prob-chi2 4.605 2) 0.1)) 0.001)
(< (abs (sub (prob-chi2 51.805 40) 0.1)) 0.001)
(< (abs (sub (prob-chi2 9.210 2) 0.01)) 0.0001)
(< (abs (sub (prob-chi2 63.691 40) 0.01)) 0.0001)
))
(define (test-prob-t)
(and
(< (abs (sub (prob-t 1.886 2) 0.1)) 0.001)
(< (abs (sub (prob-t 1.303 40) 0.1)) 0.001)
(< (abs (sub (prob-t 6.965 2) 0.01)) 0.0001)
(< (abs (sub (prob-t 2.423 40) 0.01)) 0.0001)
))
(define (test-prob-z)
(and
(< (sub (prob-z -0.1) 0.4601721627) 0.00001)
(< (sub (prob-z 0.1) 0.5398278373) 0.00001)
(< (sub (prob-z -1) 0.1586552539) 0.00001)
(< (sub (prob-z 1) 0.8413447461) 0.00001)
(< (sub (prob-z -2) 0.02275013195) 0.00001)
(< (sub (prob-z 2) 0.9772498681) 0.00001)
(< (sub (prob-z -3) 0.001349898032) 0.00001)
(< (sub (prob-z 3) 0.998650102) 0.00001)
))
(define (test-process )
(write-file "process test" {(write-file "test process" "hello") (exit)})
(if (find ostype '("Windows" "OS/2"))
(process {newlisp '"process test"'}) ; Win32 and Win64
(process "./newlisp 'process test'")) ; Unix
(until (file? "test process") (sleep 500))
(sleep 200)
(and
(= "hello" (read-file "test process"))
(delete-file "process test")
(delete-file "test process")))
(define (test-prompt-event) true) /* test interactively */
(define (test-protected?)
(and
(protected? 'println)
(constant 'cval 123)
(protected? 'cval)
(protected? 'QA))
)
(define (test-push , l)
(dotimes (x 10)
(push x l x))
(and
(= l '(0 1 2 3 4 5 6 7 8 9))
(set 'l '(a b (c d () e)))
(push 'x l '(2 2 0))
(= (ref 'x l) '(2 2 0))
(set 'lst '(1 2 3 (4 5)()))
(push 'x lst -1 -1)
(= lst '(1 2 3 (4 5) (x)))
(push 'y lst -1 0)
(= lst '(1 2 3 (4 5) (y x)))
(push 'z lst -1 1)
(= lst '(1 2 3 (4 5) (y z x)))
(push 'p lst 4)
(= lst '(1 2 3 (4 5) p (y z x)))
(push 'q lst -2)
(= lst '(1 2 3 (4 5) p q (y z x)))
(push 'a lst 3 -3)
(= lst '(1 2 3 (a 4 5) p q (y z x)))
(= (pop lst 3 -3) 'a)
(= (pop lst -2) 'q)
(= (pop lst 4) 'p)
(= (pop lst -1 1) 'z)
(= (pop lst -1 0) 'y)
(= (pop lst -1 -1) 'x)
(= lst '(1 2 3 (4 5)()))
(set 'lst '((1)))
(push 2 lst -1 -1)
(= lst '((1 2)))
(test-push-pop)
(test-push-optimization-bug)
; test string push
(set 's "newLISP")
(= (push "#" s) "#newLISP")
(= (push "#" s 1) "##newLISP")
(= (push "#" s 3) "##n#ewLISP")
(= (push "#" s -1) "##n#ewLISP#")
(= (push "#" s -3) "##n#ewLIS#P#")
(= (push "xy" s) "xy##n#ewLIS#P#")
(= (push "xy" s -1) "xy##n#ewLIS#P#xy")
(= s "xy##n#ewLIS#P#xy")
(set 's "")
(= (push "" s) "")
(set 's "newLISP")
(= (push "" s -1) "newLISP")
(= (push "" s) "newLISP")
(= s "newLISP")
(push "-" s 7)
(= s "newLISP-")
(push "-" s -9)
(= s "-newLISP-")
(set 's "newLISP")
(= (push "-" s 8) "newLISP-")
(= (push "-" s -10) "-newLISP-")
; default functor
(set 'D:D '(a b (c d () e)))
(push 'x D '(2 2 0))
(= (ref 'x D) '(2 2 0))
(set 'D:D "newLISP")
(= (push "#" D:D) "#newLISP")
(= D:D "#newLISP")
))
(define (test-push-pop)
; string
(set 's "abcdefg")
(= (pop (push "h" s -1)) "a")
(= s "bcdefgh")
)
(define (test-push-optimization-bug) ; fixed in 8.7.1
(set 'l nil)
(and (push 'x l -1)
(set 'lst l)
(push 'y lst -1)
(= lst '(x y))))
(define (test-put-url )
(= "ERR: HTTP bad formed URL" (put-url "" "abc")))
(define (test-pv )
(< (sub (pv 0.1 10 1000 100000 0 0) -44696.89605) 1e-05))
(define (test-quote )
(= (quote x) 'x))
(define (test-quote? )
(quote? ''quote?))
(define (test-rand , sum)
(set 'sum 0)
(dotimes (x 1000)
(inc sum (rand 2)))
(and (< sum 600) (> sum 400) (list? (rand 10 100))))
(define (test-random )
(and (float? (random)) (= (length (random 0 1 10)) 10)))
(define (test-randomize)
(and
(!= '(a b c d e f g) (randomize '(a b c d e f g)))
(= (difference '(a b c d e f g) (randomize '(a b c d e f g))) '())
)
)
(define (test-read-expr , code)
(and
(set 'code "; a statement\n(define (double x) (+ x x))\n")
(= (read-expr code (context)) '(define (double x) (+ x x)))
(= $count 41))
)
(define (test-read-buffer )
(and
(set 'file (open "qa-dot" "read"))
(read-buffer file buff (nth 0 (file-info "qa-dot")))
(close file)
(set 'file (open "junk" "write"))
(write-buffer file buff (nth 0 (file-info "qa-dot")))
(close file)))
(define test-read test-read-buffer)
(define (test-read-char )
(and
(file-copy "qa-dot" "junk")
(delete-file "junk")))
(define (test-read-file )
(read-file "qa-dot")
(starts-with (read-file "file://qa-dot") "#!/usr/bin/env newlisp")
)
(define (test-read-key) true)
(define (test-read-line )
(line-count "qa-dot"))
(define (test-read-utf8)
(and
(write-file "utf8text.txt" MAIN:utf8str)
(setq fle (open "utf8text.txt" "read"))
(= (read-utf8 fle) (char (MAIN:utf8str 0)))
(close fle)
(delete-file "utf8text.txt")
))
(define (test-reader-event) true)
(define (test-real-path)
(and
(string? (real-path))
(string? (real-path "."))
(not (real-path "foofoo"))
(not (real-path "foofoo" true))
(if (!= ostype "Windows")
(let ( old-path (env "PATH"))
(and
(env "PATH" (append (real-path) ":" (env "PATH")))
; on Unix newLISP's which() is used to find executable path
(= (real-path "newlisp" true) (append (real-path) "/newlisp"))
(env "PATH" old-path))
)
true
)
))
; tested with qa-specific-tests/qa-message
(define (test-receive) true)
(define (test-ref)
(and
(set 'pList '(a b (c d () e)))
(push 'x pList 2 2 0)
(= (ref 'x pList) '(2 2 0))
(= (ref '(x) pList) '(2 2))
(set 'v (ref '(x) pList))
(= (pList v) '(x))
;(= (ref 'foo pList) '()) changed in 10.2.18
(= (ref 'foo pList) nil)
; comparison functor
(= (ref 'e '(a b (c d (e) f)) =) '(2 2 0))
(= (ref 'e '(a b (c d (e) f)) >) '(0))
(= (ref 'e '(a b (c d (e) f)) <) '(2))
(= (ref 'e '(a b (c d (e) f)) (fn (x y) (or (= x y) (= y 'd)))) '(2 1))
(define (is-it-or-d x y) (or (= x y) (= y 'd)))
(= (ref 'e '(a b (c d (e) f)) is-it-or-d) '(2 1))
; comparison with match and unify
(= (ref '(a ?) '((l 3) (a 12) (k 5) (a 10) (z 22)) match) '(1))
(= (ref '(X X) '( ((a b) (c d)) ((e e) (f g)) ) unify) '(1 0))
(= (ref '(X g) '( ((a b) (c d)) ((e e) (f g)) ) unify) '(1 1))
; default functor
(set 'D:D '((l 3) (a 12) (k 5) (a 10) (z 22)) )
(= (ref '(a ?) D match) '(1))
))
(define (test-ref-all)
(and
(set 'L '(a b c (d a f (a h a)) (k a (m n a) (x))))
(= (ref-all 'a L) '((0) (3 1) (3 3 0) (3 3 2) (4 1) (4 2 2)))
(= (L '(3 1)) 'a)
(= (map 'L (ref-all 'a L)) '(a a a a a a))
; with comparison functor
(= (ref-all 'a '(1 2 3 4 5 6)) '())
(set 'L '(a b c (d f (h l a)) (k a (m n) (x))))
(= (ref-all 'c L =) '((2)))
(= (ref-all 'c L >) '((0) (1) (3 2 2) (4 1)))
(= (ref-all 'a L (fn (x y) (or (= x y) (= y 'k)))) ' ((0) (3 2 2) (4 0) (4 1)))
(define (is-long? x y) (> (length y) 2))
(= (ref-all nil L is-long?) '((3) (3 2) (4)))
(define (is-it-or-d x y) (or (= x y) (= y 'd)))
(= (ref-all 'e '(a b (c d (e) f)) is-it-or-d) '((2 1) (2 2 0)))
(= (ref-all 'b '(a b (c d (e) f)) is-it-or-d) '((1) (2 1)))
(= (ref-all nil '(((()))) (fn (x y) (> (length y) 0))) '((0) (0 0)))
; test comparison with match and unify
(= (ref-all '(a ?) '((l 3) (a 12) (k 5) (a 10) (z 22)) match) '((1) (3)))
(= (ref-all '(X X) '( ((a b) (c d)) ((e e) (f g)) ((z) (z))) unify) '((1 0) (2)))
(= (ref-all '(X g) '( ((x y z) g) ((a b) (c d)) ((e e) (f g))) unify) '((0) (2 1)))
))
(define (test-regex )
(and
(= (regex "http://(.*):(.*)" "http://nuevatec.com:80")
'("http://nuevatec.com:80" 0 22 "nuevatec.com" 7 12 "80" 20 2))
(= $0 "http://nuevatec.com:80")
(= $1 "nuevatec.com")
(= $2 "80")
(= (regex "b+" "AAAABBBAAAA" 1) '("BBB" 4 3))
(= (regex "b+" "AABBBAAABBA" 1 4) '("B" 4 1))
(= (regex "b+" "AABBBAAABBA" 1 5) '("BB" 8 2))
))
(define (test-regex-comp)
(and
(set 'pattern (regex-comp "http://(.*):(.*)"))
(find pattern "http://nuevatec.com:80" 0x10000)
(= $0 "http://nuevatec.com:80")
(= $1 "nuevatec.com")
(= $2 "80")
))
(define (test-remove-dir )
(and (make-dir "junk") (remove-dir "junk")))
(define (test-rename-file )
(copy-file "qa-dot" "junk")
(rename-file "junk" "junk2"))
;; this can run only once than must be reloaded
;; because some replace's are in place with a constant
(define (test-replace )
(and
(not (catch (replace "a" "akakak") 'result))
(not (catch (replace "a") 'result))
(not (catch (replace) 'result))
(catch (replace "a" '("x" "a" "y")) 'result)
(= (replace "a" "ababab" "b") "bbbbbb")
(= $count 3)
(= (replace 'a '(a a b a b a a a b a) 'b) '(b b b b b b b b b b))
(= (replace 'a '(a a b a b a a a b a)) '(b b b))
(= (replace 'a '(a)) '())
;; with regular expressions option
(= (replace "" "abc" "x" 0) "xaxbxcx")
(= (replace "$" "abc" "x" 0) "abcx")
(= (replace "^" "abc" "x" 0) "xabc")
(= (replace "\\b" "abc" "x" 0) "xabcx")
(= (replace "(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))" "1234567" "," 0) "1,234,567")
(= (replace "a" "ababab" (upper-case $it) 0) "AbAbAb")
(= $count 3)
(set 'str2 "abaBab")
(= (replace "b|B" str2 "z" 0) "azazaz")
(= $count 3)
(replace-once "aaa")
(= (replace "%([0-9A-F][0-9A-F])" "%41123%42456%43" (char (int (append "0x" $1))) 1) "A123B456C")
; replace with comparison functor
(set 'L '(1 4 22 5 6 89 2 3 24))
(= (replace 10 L 10 <) '(1 4 10 5 6 10 2 3 10))
(set 'L '(1 4 22 5 6 89 2 3 24))
(= (replace 10 L 10 (fn (x y) (< x y))) '(1 4 10 5 6 10 2 3 10))
;
(set 'AL '((john 5 6 4) (mary 3 4 7) (bob 4 2 7 9) (jane 3)))
(= (replace '(mary *) AL (list 'mary (apply + (rest $it))) match)
'((john 5 6 4) (mary 14) (bob 4 2 7 9) (jane 3)))
(set 'AL '((john 5 6 4) (mary 3 4 7) (bob 4 2 7 9) (jane 3)))
(= (replace '(*) AL (list ($it 0) (apply + (rest $it))) match)
'((john 15) (mary 14) (bob 22) (jane 3)))
(set 'AL '((john 5 6 4) ("mary" 3 4 7) (bob 4 2 7 9) ("jane" 3)))
(= (replace nil AL (cons (sym ($it 0)) (rest $it)) (fn (x y) (string? (y 0))))
'((john 5 6 4) (mary 3 4 7) (bob 4 2 7 9) (jane 3)))
; default functor
(set 'D:D '(a a b a b a a a b a) )
(= (replace 'a D 'b) '(b b b b b b b b b b))
(set 'D:D "abc")
(= (replace "" D "x" 0) "xaxbxcx")
; regression for key cell part of list
(setq a '(b c d))
(= (replace (a 0) a (term (a 0))) '("b" c d))
))
(define (replace-once str)
(= (replace "a" str (upper-case $it) 0x8000) "Aaa") ;; custom option replace once
)
(define (test-reset )
true)
(define (test-rest , l)
(set 'l '(a b c d e f g))
(and (= (cons (first l) (rest l)) l)
(= (rest "newlisp") "ewlisp")
;; implicit nrest
(= (1 l) '(b c d e f g))
(= (10 l) '())
(= (0 l) l)
(= (-3 '(a b c d e f g)) '(e f g))
(= (-3 "abcdefg") "efg")
(= (1 '(A)) '())
(= (1 "A") "")
(= (array 2 2 (sequence 3 6)) (rest (array 3 2 (sequence 1 6))))
;; default functor
(set 'D:D '(a b c d e f g))
(= (rest D) '(b c d e f g))
(set 'D:D (array 7 '(a b c d e f g)))
(= (rest D) (array 6 '(b c d e f g)))
))
(define (test-reverse )
(and
(= (reverse '(1 2 3)) '(3 2 1))
(= (reverse "newLISP") "PSILwen")
(set 'D:D '(1 2 3))
(= (reverse D) '(3 2 1))
(set 'D:D "newLISP")
(= (reverse D) "PSILwen")
(set 'a (array 2 3 '(1 2 3 4 5 6)))
(reverse a)
(= a (array 2 3 '(4 5 6 1 2 3)))
))
(define (test-rotate )
(and
(= '(8 9 0 1 2 3 4 5 6 7) (rotate '(0 1 2 3 4 5 6 7 8 9) 2))
(= '() (rotate '()))
(= (rotate '(1) -1) '(1))
(= (rotate "") "")
(= (rotate "x" -1) "x")
(set 'str "abcdefg")
(= (rotate str) "gabcdef")
(= (rotate str 3) "defgabc")
(= (rotate str -4) "abcdefg")
(set 'D:D '(0 1 2 3 4 5 6 7 8 9))
(= '(8 9 0 1 2 3 4 5 6 7) (rotate D 2))
))
(define (test-round)
(and
(= (round 1.25) (round 1.25 0) 1)
(= (round 3.89) (round 3.89 0) 4)
(= (round 123.49 2) 100)
(= (round 123.49 1) 120)
(= (round 123.49 0) 123)
(= (round 123.49 -1) 123.5)
(= (round 123.49 -2) 123.49)
(= (round 123.49 -3) 123.49)
(!= (round 123.49 -2) 123.49000000000001)
(= (round 123.49 3) 0)
(= (round 0.05 -1) 0.1)
(= (round 0.5) 1)
(= (round 5 1) 10)
))
(define (test-save )
(and (save "all") (save "save.lsp" 'test-save) (delete-file "all")
(delete-file "save.lsp")))
(define (test-search , file)
(and
(set 'file (open "qa-dot" "read"))
(search file "define")
(close file)))
(define (test-seed )
(seed 123)
(set 'a (rand 10))
(seed 123)
(set 'b (rand 10))
(= a b)
; built-in PRNG with state recall
(seed 123 true)
(rand 100 100)
(set 'state (seed)) ; save state
(set 'r1 (rand 100 100))
(rand 100 100)
(normal 10 3 100)
(seed state true 0) ; recall state
(= r1 (rand 100 100))
)
(define (test-seek , file chr)
(set 'file (open "junk" "write"))
(dotimes (x 100)
(write-char file x))
(close file)
(set 'file (open "junk" "read"))
(seek file 65)
(set 'chr (read-char file))
(close file)
(delete-file "junk")
(= chr 65))
(define (test-select )
(set 'l '(0 1 2 3 4 5 6 7 8 9))
(and
(test-select-collect)
(= (select l '(0 9 9 0 1 8 8 1)) '(0 9 9 0 1 8 8 1))
(= (select "2001-09-20" '(5 6 8 9 0 1 2 3)) "09202001")
; default functor
(set 'D:D '(0 1 2 3 4 5 6 7 8 9))
(= (select D '(0 9 9 0 1 8 8 1)) '(0 9 9 0 1 8 8 1))
))
(new Class 'MAIN:Circle)
(define (test-self)
(define (Circle:move dx dy) (inc (self 1) dx) (inc (self 2) dy))
(set 'myc (list (Circle 1 2 3) (Circle 4 5 6)))
(:move (myc 0) 10 20)
(:move (myc 1) 10 20)
(= myc '((Circle 11 22 3) (Circle 14 25 6)))
)
;; for testing semaphores accross processes/threads see test-share
(define (test-semaphore)
(and
(set 'sid (semaphore))
(if (find ostype '("Linux" "BSD" "OSX" "Solaris" "SunOS" "AIX" "Tru64Unix" "Cygwin"))
(= (semaphore sid) 0) true) ;; no semaphore status on Win32
(semaphore sid 1)
(if (find ostype '("Linux" "BSD" "OSX" "Solaris" "SunOS" "AIX" "Tru64Unix" "Cygwin"))
(= (semaphore sid) 1) true) ;; no semaphore status on Win32
(semaphore sid 0)))
; tested with qa-specific-tests/qa-message
(define (test-send) true)
(define (test-sequence )
(= (sequence 1 10 3) '(1 4 7 10)))
(define (test-series )
(and
(= (series 2 2 5) '(2 4 8 16 32))
(= (series 2 2 0) '())
(= (series 1 2 -10) '())
(= (series 1 1 5) '(1 1 1 1 1))
(= (series "a" (fn (c) (char (inc (char c)))) 5) '("a" "b" "c" "d" "e"))
(= (series 1 (fn (x) (* 2 x)) 5) '(1 2 4 8 16))
))
(define (test-set , x y z)
(set 'x 123 'y (string "foo"))
(= x 123)
)
(define (test-setf)
(and
(setf l '(a b c d e f g))
(setf (nth 3 l) 999)
(= l '(a b c 999 e f g))
(set 's "abcdefg")
(setf (s 3) (upper-case $it))
(= s "abcDefg")
(set 's "a-b-c-d-e-f-g")
(setf (first (replace "-" s "")) (upper-case $it))
(= s "Abcdefg")
(setf (s 2) "CCC")
(= s "AbCCCdefg")
(= (setf ((copy '(a b c)) 1) 'B) 'B)
))
(define (test-setq , x y z)
(setq x 1 y 2 z 3)
(and (= x 1) (= y 2) (= z 3)))
(define (test-set-ref)
(and
(set 'L '(z a b (z) (d (c c (c)) e f c)))
(= (set-ref 'c L 'z) '(z a b (z) (d (z c (c)) e f c)))
(set 'L '((a 1) (b 2) (a 3) (b 4)))
(= (set-ref '(a *) L '(z 99) match) '((z 99) (b 2) (a 3) (b 4)))
(= (set-ref '(a *) L '(z 99) match) '((z 99) (b 2) (z 99) (b 4)))
(set 'Ct:Ct '(a b c d e f g))
(= (set-ref 'c Ct 'z) '(a b z d e f g))
; default functor
(set 'D:D '(z a b (z) (d (c c (c)) e f c)))
(= (set-ref 'c D 'z) '(z a b (z) (d (z c (c)) e f c)))
)
)
(define (test-set-ref-all)
(and
(set 'L '(z a b (c) (d (c c (c)) e f c)))
(= (set-ref-all 'c L 'z) '(z a b (z) (d (z z (z)) e f z)))
(set 'L '((a 1) (b 2) (a 3) (b 4)))
(= (set-ref-all '(a *) L '(z 99) match) '((z 99) (b 2) (z 99) (b 4)))
)
)
(define (test-share)
(and
(if (find ostype '("Windows" "OS/2"))
(windows-test-share)
(unix-test-share))
(set 'mvar (share))
(not (share mvar nil))
(= (share mvar) nil) ; nil
(share mvar true)
(= (share mvar) true) ; true
(share mvar 123)
(= (share mvar) 123) ; integer
(share mvar 123.456)
(= (share mvar) 123.456) ; float
(share mvar "hello")
(= (share mvar) "hello") ; string
(share mvar '(a b c d e f))
(= (share mvar) '(a b c d e f)) ; list
; check sizes > pagesize
(share mvar (dup "X" 10000))
(= 10000 (length (share mvar)))
; force deletion of temporary file
(not (share mvar nil))
(unless (= ostype "Windows") (share nil mvar))
))
(define (windows-test-share)
(write-file "sharetest.lsp"
[text]
(map set '(sid mm) (map int (slice (main-args) 2)))
(if (= (share mm) "hello") (share mm "HELLO"))
(semaphore sid 1) ; signale parent to read
(exit)
[/text]
)
(and
(set 'sid (semaphore))
(set 'mm (share))
(share mm "hello")
(if (find ostype '("Windows" "OS/2"))
(process (string "newlisp sharetest.lsp " sid " " mm))
(process (string "./newlisp sharetest.lsp " sid " " mm)))
(semaphore sid -1) ; wait for child process
(sleep 1000)
(semaphore sid 0) ;; delete semaphore
(= (share mm) "HELLO")
(or (delete-file "sharetest.lsp") true)))
(define (unix-test-share)
(and
(set 'mm (share))
(share mm "hello")
(wait-pid (fork (begin
(if (= (share mm) "hello")
(share mm "HELLO"))
(exit ))))
(= (share mm) "HELLO")
(share nil mm) ; unmap share
))
(define (test-sgn)
(and
(= 0 (sgn 0))
(= 1 (sgn 123))
(= -1 (sgn -3.5))))
; test manually
(define (test-signal) true)
(define (test-silent )
(primitive? silent))
(define (test-sin )
(= 1 (sin (asin (sin (asin 1))))))
(define (test-sinh)
(< (abs (sub (tanh 1) (div (sinh 1) (cosh 1)))) 0.0000000001)
)
(define (test-sleep )
(set 'start (time-of-day))
(sleep 10)
(set 'start (time-of-day))
(sleep 1000)
(set 'duration (- (time-of-day) start))
(and (> duration 500) (< duration 1500)))
(define (test-slice )
(and
(set 'str "0123456789")
(= (slice str 0 1) "0")
(= (slice str 0 3) "012")
(= (slice str 8 2) "89")
(= (slice str 8 10) "89")
(= (slice str 20 10) "")
(= (slice str 2 -2) "234567")
(= (slice str 2 -5) "234")
(= (slice str 2 -7) "2")
(= (slice str 2 -8) "")
(= (slice str 2 -9) "")
(= (slice '(a b c d e f g) 3 1) '(d))
(= (slice '(a b c d e f g) 3 0) '())
(= (slice '(a b c d e f g) 0 0) '())
(= (slice '(a b c d e f g) 10 10) '())
(= (slice '(a b c d e f g) 3 2) '(d e))
(= (slice '(a b c d e f g) 5) '(f g))
(= (slice '(a b c d e f g) -5 2) '(c d))
(= (slice '(a b c d e f g) -1 -2) '())
(= (slice '(a b c d e f g) 1 -2) '(b c d e))
(= (slice '(a b c d e f g) 4 -2) '(e))
(= (slice '(a b c d e f g) 4 -3) '())
(= (slice '(a b c d e f g) 4 -4) '())
(= (slice '(a b c d e f g) -6 -3) '(b c d))
;; implicit slice
(= (1 3 '(a b c d e f g)) '(b c d))
(= (-4 2 '(a b c d e f g)) '(d e))
(= (1 3 "abcdefg") "bcd")
(= (-4 2 "abcdefg") "de")
(= (1 -3 "abcdefg") "bcd")
(= (1 -5 "abcdefg") "b")
(= (1 -7 "abcdefg") "")
(setq x 1 y 2)
(= (x y '(a b c d e f g)) '(b c))
(= (x y "abcdefg") "bc")
(= (1 -2 '(a b c d e f g)) '(b c d e))
(= (4 -2 '(a b c d e f g)) '(e))
(= (4 -3 '(a b c d e f g)) '())
(= (4 -4 '(a b c d e f g)) '())
(= (-6 -3 '(a b c d e f g)) '(b c d))
; default functor
(set 'D:D "0123456789")
(= (slice D 0 1) "0")
(= (slice D 0 3) "012")
(set 'D:D '(a b c d e f g))
(= (slice D 3 1) '(d))
(= (1 3 D) '(b c d))
))
(define (test-sort )
(and
(= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5)))
(= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5)))
(= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5) <))
(= '(9 8 7 6 5 4 3 2 1) (sort '(9 1 8 2 7 3 6 4 5) >))
(= '(1 2 3 4 5 6 7 8 9) (sort '(9 1 8 2 7 3 6 4 5) (fn (x y) (< x y))))
(= '(9 8 7 6 5 4 3 2 1) (sort '(9 1 8 2 7 3 6 4 5) (fn (x y) (> x y))))
(= '() (sort '()))
(= (sort '(1 nil)) '(nil 1))
(= (sort '(a nil true 1 1.2)) (sort (list 'a nil true 1 1.2)) '(nil true 1 1.2 a))
;; at runtime generated sort function v10.4.6
(define (f<g= f g)
(expand (fn (a b) (f (g a) (g b))) 'f 'g))
(set 'lst '((c 4) (b 5) (a 2)))
(= (sort lst (f<g= < last)) '((a 2) (c 4) (b 5)))
)
)
(define (test-source)
(= (replace "\r|\n" (source 'test-sin) "" 0)
"(define (test-sin ) (= 1 (sin (asin (sin (asin 1))))))"))
(define (test-sqrt )
(and (= 10 (sqrt 100)) (= 1.2 (sqrt 1.44))))
(define (test-ssq)
(= 385 (ssq (sequence 1 10)) (ssq (array 10 (sequence 1 10))))
)
(define (test-starts-with )
(and
(starts-with "newlisp" "new")
(starts-with "newlisp" "NEW" 1)
(set 'D:D "newlisp")
(starts-with D "new")
(starts-with D "NEW" 1)
))
(define (test-stats)
(< (apply add (map sub (stats '(1 2 3 4 5)) '(5 3 1.2 1.58113883 2.5 0 -1.912))) 0.000000001)
)
(define (test-string )
(and (string? (string 12345)) (= (string 12345) "12345") (string?
(string 1.234))
(= (string 'test-string) "test-string")
(string? (string test-string))
(= (string "a" "b" "c") (append "a" "b" "c") "abc")
(= (string "a" 123 "b") "a123b")))
(define (test-string? )
(and (string? "1234") (not (string? 1234))))
(define (test-struct) ; more tests in qa-libffi
(struct 'complex "double" "double")
(= (unpack complex (pack complex 1.23 4.56)) '(1.23 4.56)))
(define (test-sub )
(= 0 (sub 0.99999999 0.99999999))
(= -123 (sub 123)))
(define (test-swap )
(and
; new (swap <place1> <place2>) in 10.0.3
(set 'lst '(1 2 3 4))
(= (swap (first lst) (last lst)) 1)
(= lst '(4 2 3 1))
(= (swap (lst 0) (lst -1)) 4)
(= lst '(1 2 3 4))
(set 'A (array 2 3 (sequence 1 6)))
(= (swap (A 0 0) (A -1 -1)) 1)
(= A (array 2 3 (flat '((6 2 3) (4 5 1)))))
(set 'lst '(a b c d))
(set 'x 'z)
(= (swap (lst 0) x) 'a)
(= lst '(z b c d))
(= x 'a)
)
)
(define (test-sym)
(and (= (sym "test-sym") 'test-sym)
(= (sym "test-sym" 'QA) 'test-sym)))
(define (test-symbol? )
(and
(symbol? (sym "test-symbol"))
(symbol? (sym "a b"))
))
(define (test-symbols )
(and (list? (symbols)) (> (length (symbols)) 0)))
(define (test-sys-error) true)
; (integer? (sys-error 0) ))
(define (test-sys-info )
(and (list? (sys-info)) (= (length (sys-info)) 10)))
(define (test-tan )
(> 1 (tan (atan (tan (atan 1))))))
(define (test-tanh)
(< (abs (sub (sinh 1) (div (sub (exp 1) (exp -1)) 2))) 0.0000000001)
)
(define (test-term )
(= "term" (term 'term)))
(define test-name test-term)
(define (test-throw )
(and (catch (throw (+ 3 4)) 'msg) (= msg 7)))
(define (test-time )
(float? (time))
)
(define (test-time-of-day )
(float? (time-of-day)))
(define (test-trace )
(trace nil)
(= nil (trace)))
(define (test-trace-highlight )
(trace-highlight "#" "#"))
(define (test-transpose )
(and
(= '((1) (2) (3)) (transpose '((1 2 3))))
(= '((a b) (c d) (e f)) (transpose '((a c e) (b d f))))
(= '((a d f) (b e g) (c nil nil)) (transpose '((a b c) (d e) (f g))))
(= '((a c f) (b d g)) (transpose '((a b) (c d e) (f g))))
;; transpose arrays
(set 'A (array 2 3 (sequence 1 6)))
(= (array-list (transpose A)) '((1 4) (2 5) (3 6)))
))
(define (test-trim )
(and
(= (trim " \n \t h e l l o \r ") "h e l l o")
(= (trim "----hello----" "-") "hello")
(= (trim "----hello====" "-" "=") "hello")
(= (trim "000012345" "0" "") "12345")))
(define (test-true?)
(= (map true? '(x nil 1 nil "hi" ())) '(true nil true nil true nil)))
(define (test-unicode)
(= (utf8 (unicode "newLISP")) "newLISP"))
(define (test-unify)
(and
(= (unify 'X 123) '((X 123)))
(= (unify '(Int Flt Str Sym Lst) '(123 4.56 "Hello" s '(a b c)))
'((Int 123) (Flt 4.56) (Str "Hello") (Sym s) (Lst '(a b c))))
(= (unify 'A 'A) '())
(= (unify '(A B "hello") '("hi" A Z)) '((A "hi") (B "hi") (Z "hello")))
(= (unify '(A B) '(B abc)) '((A abc) (B abc)))
(= (unify '(B A) '(abc B)) '((B abc) (A abc)))
(= (unify '(A A C D) '(B C 1 C)) '((B 1) (A 1) (C 1) (D 1)))
(= (unify '(D C A A) '(C 1 C B)) '((D 1) (C 1) (B 1) (A 1)))
(= (unify '(f A) '(f (a b c))) '((A (a b c))))
(= (unify '(A f) '((a b c) f)) '((A (a b c))))
(= (unify '(f (g A)) '(f B)) '((B (g A))))
(= (unify '(p X Y a) '(p Y X X)) '((Y a) (X a)))
(= (unify '(p X Y) '(p Y X)) '((Y X)))
(= (unify '(q (p X Y) (p Y X)) '(q Z Z)) '((Y X) (Z (p X X))))
(= (unify '(f (g A) A) '(f B xyz)) '((B (g xyz)) (A xyz)))
(= (unify '(A (g abc)) '(B A)) '((B (g abc)) (A (g abc))))
;; with additional environment list
(= (unify '(A (B) X) '(A (A) Z) '((A 1) (Z 4)))
'((A 1) (Z 4) (B 1) (X 4)))
))
(define (test-union)
(= (union '(1 3 1 4 4 3) '(2 1 5 6 4)) '(1 3 4 2 5 6)))
(define (test-unique )
(= (unique '(2 3 4 4 6 7 8 7)) '(2 3 4 6 7 8)))
(define (test-unless )
(and
(= (unless nil (set 'x 1) (set 'y 2) (set 'z 3)) 3)
(= x 1) (= y 2) (= z 3)
(= (unless 123) 123)
(= (unless true) true)
(= (unless nil) nil)
))
(define (test-unpack )
(= (pack "c c c" 65 66 67) "ABC")
(= (unpack "c c c" "ABC") '(65 66 67)))
(define (test-until , x)
(set 'x 0)
(= 10 (until (= x 10) (inc x)) x))
(define (test-do-until , x)
(set 'x 0)
(and
(= 10 (do-until (= x 10) (inc x)) x)
(= 11 (do-until (> x 0) (inc x)) x)
))
(define (test-upper-case )
(= (upper-case "abcdefghijklmnopqrstuvwxyz") "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(define (test-utf8)
(and
(= (utf8 (unicode "newLISP")) "newLISP")
(MAIN:utf8qa)))
(define (test-utf8len)
(= 23 (utf8len MAIN:utf8str)))
(define (test-uuid)
(= 36 (length (uuid))))
(define (test-wait-pid)
(set 'pid (fork (begin (sleep 200)(exit))))
(wait-pid pid))
(define (test-when)
(and
(= (when true (set 'x 1) (set 'y 2) (set 'z 3)) 3)
(= x 1) (= y 2) (= z 3)
(= (when 123) 123)
(= (when nil) nil)
(= (when true) true)
))
(define (test-while , x)
(and
(set 'x 0)
(= 1000 (while (< x 1000) (inc x)) x)
))
(define (test-do-while, x)
(and
(set 'x 0)
(= 100 (do-while (< x 100) (inc x)) x)
(= 101 (do-while (< x 100) (inc x)) x)
))
(define (test-write-buffer )
(set 'str "")
(dotimes (x 5) (write-buffer str "hello"))
(set 'Bf:Bf "")
(set 'S:S "hello")
(dotimes (x 5) (write-buffer Bf S))
(and
(= str "hellohellohellohellohello")
(= Bf:Bf str)
(test-read-buffer)
(set 'str "")
(write-buffer str S 3)
(= str "hel")
))
(define test-write test-write-buffer)
(define (test-write-char )
(file-copy "qa-dot" "junk")
(delete-file "junk"))
(define (test-write-file )
(and
(write-file "junk" "newlisp")
(write-file "file://junk2" "hello")
(= (read-file "junk") "newlisp")
(= (read-file "file://junk2") "hello")
(delete-file "file://junk2")
))
(define (test-write-line )
(and
(set 'fle (open "testwrite" "w"))
(write-line fle "hello")
(close fle)
(set 'fle (open "testwrite" "r"))
(= (read-line fle) "hello")
(close fle)
(delete-file "testwrite")
(set 'Bf:Bf "")
(set 'S:S "hello world")
(write-line Bf S)
(if (find ostype '("Windows"))
(= Bf:Bf "hello world\r\n")
(= Bf:Bf "hello world\n"))
))
(define (test-xfer-event)
(not (xfer-event)))
(define (test-xml-error )
(= (xml-error) nil))
(define (test-xml-parse )
(= (xml-parse "<hello att='value'></hello>") '(("ELEMENT" "hello"
(("att" "value"))
()))))
(define (test-xml-type-tags )
(length (xml-type-tags) 4))
(define (test-zero?)
(= (map zero? '(1 0 1.2 0.0)) '(nil true nil true)))
(define (test-| )
(= (| -1431655766 1431655765) -1))
(define (test-~ )
(and
(= (~ 0) -1)
(if
(find ostype '("Windows" "OS/2"))
(= (format "%I64x" (~ 0xa0a0a0a0a0a0a0a0)) "5f5f5f5f5f5f5f5f")
(= ostype "True64Unix")
(= (format "%lx" (~ 0xa0a0a0a0a0a0a0a0)) "5f5f5f5f5f5f5f5f")
(= (format "%llx" (~ 0xa0a0a0a0a0a0a0a0)) "5f5f5f5f5f5f5f5f"))
))
;;;;;;;;;;;;;;;; test Cilk interface, run qa-cilk for more tests ;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (test-abort)
(and
(spawn 'x (+ 1 2))
(abort)
))
; more testing can be found in qa-specific-test/qa-cilk
(define (test-spawn)
(and
(set 'pw (spawn 'w (list 'a 'b 'c 'd 'e 'f))) ; list
(set 'px (spawn 'x (+ 1 2 3 4))) ; integer
(set 'py (spawn 'y (add 1.23 4.56))) ; float
(set 'pz (spawn 'z (upper-case "hello world"))) ;string
(if (!= ostype "Windows")
(begin
(find pw (sync))
(find px (sync))
(find py (sync))
(find pz (sync)))
true)
(true? (sync 1000))
(empty? (sync))
(= w '(a b c d e f))
(= x 10)
(< (abs (sub y 5.79)) 0.0000000001)
(= z "HELLO WORLD")
))
(define (test-sync) true)
(define (test-schedule) true)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ENTRY POINT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (or (not (or (file? "newlisp") (file? "newlisp.exe"))) (not (file? "qa-dot")))
(begin
(println "both newlisp(.exe) and qa-dot should be in the current directory.")
(exit)))
(cleanup)
(unless MAIN:testing-cell-leaks
(println)
(println "Testing built-in functions ..."))
(qa)
(cleanup)
(context 'MAIN)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(unless MAIN:testing-cell-leaks
(println "Testing contexts as objects and scoping rules ...")
(println))
;; check creating local symbols
;; in case they already exist in MAIN
(set 'var 123)
(set 'CTX:var 456)
(if (or (!= CTX:var 456) (!= var 123))
(println " >>>> problem creating local symbols"))
(set 'ctx CTX)
(global 'myprint)
(set 'myprint print)
;; following would fail without dynamic symbols for non-existing
;; contexts because 'accnt' is not a context at this moment
(define (report accnt)
(list accnt:name accnt:balance))
;; late in ACCOUNT the definition of 'deposit' should
;; should not fail, locals should always be created for
;; the current context
(constant 'amount 999)
(constant 'stat 999)
;; the symbol defined should always be forced into the current
;; context, even if alread exists in MAIN, if not following
;; definition of 'deposit' would fail
(set 'deposit 999)
(set 'clear 999)
(constant 'withdraw 999)
(define balance 1000.00)
(constant 'phone "123-456-789")
(context 'ACCOUNT)
(set 'ACCOUNT:term "") ; force creation of local symbol 'term with
(define balance 0.0) ; same name as built in primitive
(set 'phone "")
(constant 'const "foo") ; a protected variable
(define (deposit amount)
(inc balance amount))
(define (withdraw amount)
(dec balance amount))
; make sure contexts are inherited
; but not variables containing contexts
(if (not (context? CTX))
(QA:failed " >>>> problem inheriting context symbols"))
; make sure context variables get not inherited
(if (= ctx CTX) (QA:failed " >>>> should not inherit context var"))
(set 'ctx 123)
; make sure redefined primitives get inherited
(if (not (primitive? myprint))
(QA:failed " >>>> problem inheriting redefined primitives"))
(set 'myprint nil)
(context 'MAIN)
;; make sure again that context defs did not overwrite MAIN symbols
(if (or (!= deposit 999) (!= clear 999) (!= withdraw 999) (!= stat 999) (!= ctx CTX)
(not (primitive? term)) (!= balance 1000.0) (!= phone "123-456-789"))
(QA:failed " >>>> context definitions are overwriting MAIN"))
(new ACCOUNT 'John true) ; this creates a new context copy of
; ACCOUNT called 'John' if exists overwrite symbols
(set 'John:name "John Doe")
(set 'John:phone "555-123-456")
(unless (protected? 'John:const)
(QA:failed ">>>> symbol protection has not been copied"))
(John:deposit 100.00)
(John:withdraw 60)
(new ACCOUNT 'Anne true)
(set 'Anne:name "Anne Somebody")
(set 'Anne:phone "555-456-123")
(Anne:deposit 120.00)
(Anne:withdraw 50)
(if (or (!= John:balance 40) (!= Anne:balance 70))
(QA:failed " >>>> problem with methods in contexts"))
(if (or (!= (report John) (list John:name John:balance))
(!= (report Anne) (list Anne:name Anne:balance)))
(QA:failed " >>>> problem using context variables"))
(if (!= (map report (map eval '(John Anne)))
'(("John Doe" 40) ("Anne Somebody" 70)) )
(QA:failed " >>>> problem mapping functions using context vars"))
;; dynamic context var as symbol to be defined
;;
(define (defit)
(define (ctx:foo x) (+ x x)))
(set 'ctx ACCOUNT)
(defit)
(if (!= (ctx:foo 10) 20)
(QA:failed " >>>> problem with dyna symbols in defined symbol"))
;; check setq, define (as set) and inc, dec on dynamic context vars
;;
(define (foo-set ct value) (set 'ct:var value))
(define (foo-setq ct value) (setq ct:var value))
(define (foo-define ct value) (define ct:var value))
(define (foo-inc ct value) (inc ct:var))
(define (foo-dec ct value) (dec ct:var))
(set 'CTX:var 0) ;; make sure var is existent
(foo-set CTX 1)
(if (!= 1 CTX:var)
(QA:failed " >>>> problem with set on context vars"))
(foo-setq CTX 3)
(if (!= 3 CTX:var)
(QA:failed " >>>> problem with setq on context vars"))
(foo-define CTX 4)
(if (!= 4 CTX:var)
(QA:failed " >>>> problem with define on context vars"))
(foo-inc CTX)
(if (!= 5 CTX:var)
(QA:failed " >>>> problem with inc on context vars"))
(foo-dec CTX)
(if (!= 4 CTX:var)
(QA:failed " >>>> problem with dec on context vars"))
;; dynamic context vars inside a context (since version 7.5.1)
(context 'TST)
(define (init ctx value)
(set 'ctx:foo value))
;; since version 8.7.8 when calling a function in a context the current runtime
;; context changes
(define (test-context-change)
(= (context) TST))
(context MAIN)
;; foo does not exist in CTX
(TST:init CTX 999)
(if (!= 999 CTX:foo)
(QA:failed " >>>> problem with dyna vars in contexts"))
;; now foo does exist
(TST:init CTX 222)
(if (!= 222 CTX:foo)
(QA:failed " >>>> problem with dyna vars in contexts"))
(define (cdf:cdf a b) (+ a b))
(if (!= (cdf 3 4) 7)
(QA:failed " >>>> problem with context default vars"))
;; check for existence of dynamic context symbol
(define (check-sym-existence ctx)
(if (symbol? 'ctx:foovar) ;; check only, will not create
(QA:failed " >>>> problem with symbol? for dyna vars")))
(check-sym-existence CTX)
;; do not overwrite existing symbols
(set 'Actx:x 123)
(set 'Actx:y 456)
(set 'Bctx:x 999)
(new Actx Bctx)
(if (not (= Bctx:x 999))
(QA:failed " >>>> problem with new in overwriting symbols"))
;; delete contexts
(if (not (and
(delete 'ACCOUNT)
(delete 'Anne)
(delete 'John)
) )
(QA:failed " >>>> problem deleting contexts"))
;; define static default functions
(define foobar:foobar)
(define (def-static s contents)
(def-new 'contents (sym (term s) s)))
(if (not
(and
(def-static 'foobar (fn (x) (+ x x)))
(= foobar:foobar (lambda (foobar:x) (+ foobar:x foobar:x)))
(= (foobar 10) 20)))
(QA:failed " >>>> problem with static default function definition"))
;; calling into context changes context
(if (not TST:test-context-change)
(QA:failed " >>>> problem changing runtime context with symbol"))
;; but calling with raw lambda doesn't
(if ((eval TST:test-context-change))
(QA:failed " >>>> problem maintaining runtime context with lambda"))
;; apply evaluates functor
(if (not (apply 'TST:test-context-change))
(QA:failed " >>>> problem changing runtime context with apply symbol"))
;; apply evaluates functor
(if (apply TST:test-context-change)
(QA:failed " >>>> problem maintaining runtime context with apply lambda"))
;; map evaluates functor
(if (!= (map 'TST:test-context-change '(a b c)) '(true true true))
(QA:failed " >>>> problem changing runtime context with map symbol"))
;; map evaluates functor
(if (!= (map TST:test-context-change '(a b c)) '(nil nil nil))
(QA:failed " >>>> problem maintaining runtime context with map lambda"))
;; hash-like access functions for namespaces
(if (not (and
(nil? (define Foo:Foo)) ; create namespace and default functor
(= (Foo "bar" 123) 123)
(= (Foo "bar") 123)
(= (Foo "bar" (+ 100 23)) 123)
(= (Foo (append "b" "ar")) 123)
(= (Foo '(("var" 123) ("bar" 456) ("baz" 789))) 'Foo)
(= (Foo) '(("bar" 456) ("baz" 789) ("var" 123)))
(= (Foo "var" (* 2 (Foo "var"))) 246)
; accept integers as keys since 10.5.6 (get converted to strings)
(= (Foo 123 "hello") "hello" (Foo 123))
(nil? (Foo 123 nil))
)) (QA:failed " >>>> problem with hash functions for namespaces") true)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(unless testing-cell-leaks (println "total time: " (- (time-of-day) start-of-qa) "\n"))
(if QA:failed-messages
(begin
(println ">>>>> TESTING: " (main-args 0) " FINISHED WITH ERRORS:")
(println)
(dolist (func (reverse QA:failed-messages))
(println func)))
(unless testing-cell-leaks
(println ">>>>> ALL FUNCTIONS FINISHED SUCCESSFUL: " (main-args 0))
(println))
)
(delete-file "sharetest.lsp")
(delete-file "udptest.lsp")
(sys-info)
(unless do-not-exit (exit))
;; eof
|