1include <../std.scad>
   2include <../fnliterals.scad>
   3
   4
   5module test_map() {
   6    l1 = [1,2,3,4,5,6,7,8];
   7    l2 = [7,3,9,1,6,1,3,2];
   8    x3 = function (x) x*3;
   9    d3 = function (x) x/3;
  10    xx = function (x) x*x;
  11    assert_approx(map(x3,l1), l1*3);
  12    assert_approx(map(x3,l2), l2*3);
  13    assert_approx(map(d3,l1), l1/3);
  14    assert_approx(map(d3,l2), l2/3);
  15    assert_approx(map(xx,l1), [for (x=l1) x*x]);
  16    assert_approx(map(xx,l2), [for (x=l2) x*x]);
  17}
  18test_map();
  19
  20
  21module test_filter() {
  22    l = [7,3,9,1,6,1,3,2];
  23    lt3 = function (x) x<3;
  24    lte3 = function (x) x<=3;
  25    gt3 = function (x) x>3;
  26    gte3 = function (x) x>=3;
  27    assert_equal(filter(lt3,l), [1,1,2]);
  28    assert_equal(filter(lte3,l), [3,1,1,3,2]);
  29    assert_equal(filter(gt3,l), [7,9,6]);
  30    assert_equal(filter(gte3,l), [7,3,9,6,3]);
  31}
  32test_filter();
  33
  34
  35module test_reduce() {
  36    l = [7,3,9,1,6,1,3,2];
  37    add = function (a,b) a+b;
  38    mul = function (a,b) a*b;
  39    assert_equal(reduce(add,l), 32);
  40    assert_equal(reduce(mul,l), 0);
  41    assert_equal(reduce(mul,l,init=1), 6804);
  42}
  43test_reduce();
  44
  45
  46module test_accumulate() {
  47    l = [2,3,9,1,6,1,3,2];
  48    add = function (a,b) a+b;
  49    mul = function (a,b) a*b;
  50    assert_equal(accumulate(add,l), [2,5,14,15,21,22,25,27]);
  51    assert_equal(accumulate(mul,l), [0,0,0,0,0,0,0,0]);
  52    assert_equal(accumulate(mul,l,init=1), [2,6,54,54,324,324,972,1944]);
  53}
  54test_accumulate();
  55
  56
  57module test_while() {
  58    fibs = while(
  59        init = [1,1],
  60        cond = function (i,x) select(x,-1)<25,
  61        func = function (i,x) concat(x, [sum(select(x,-2,-1))])
  62    );
  63    assert_equal(fibs, [1,1,2,3,5,8,13,21,34]);
  64}
  65test_while();
  66
  67
  68module test_for_n() {
  69    fib = function(n) for_n(
  70        n, [],
  71        function(i,x) x? [x[1], x[0]+x[1]] : [0,1]
  72    )[1];
  73    assert_equal(fib(1),1);
  74    assert_equal(fib(2),1);
  75    assert_equal(fib(3),2);
  76    assert_equal(fib(4),3);
  77    assert_equal(fib(5),5);
  78    assert_equal(fib(6),8);
  79    assert_equal(fib(7),13);
  80    assert_equal(fib(8),21);
  81}
  82test_for_n();
  83
  84
  85module test_find_first() {
  86    l = [7,3,8,1,6,1,3,2,9];
  87    lt  = function (val,x) val <  x;
  88    lte = function (val,x) val <= x;
  89    gt  = function (val,x) val >  x;
  90    gte = function (val,x) val >= x;
  91    assert_equal(find_first(f_eq(1),l), 3);
  92    assert_equal(find_first(f_eq(1),l,start=4), 5);
  93    assert_equal(find_first(f_eq(6),l), 4);
  94    assert_equal(find_first(f_gt(8),l), 8);
  95    assert_equal(find_first(f_gte(8),l), 2);
  96    assert_equal(find_first(f_lt(3),l), 3);
  97    assert_equal(find_first(f_lt(7),l), 1);
  98    assert_equal(find_first(f_lte(8),l), 0);
  99    assert_equal(find_first(f_gte(8),l,start=1), 2);
 100    assert_equal(find_first(f_gte(8),l,start=3), 8);
 101}
 102test_find_first();
 103
 104
 105module test_binsearch() {
 106    l = [3,6,7,9,10,11,13,17,18,19,22,47,53,68,72,79,81,84,85,88,97];
 107    assert_equal(binsearch(1,l), undef);
 108    assert_equal(binsearch(43,l), undef);
 109    assert_equal(binsearch(93,l), undef);
 110    assert_equal(binsearch(99,l), undef);
 111    for (i=idx(l)) {
 112        assert_equal(binsearch(l[i],l), i);
 113    }
 114}
 115test_binsearch();
 116
 117
 118module test_simple_hash() {
 119    assert_equal(simple_hash(true), 1000398);
 120    assert_equal(simple_hash(false), 1028531);
 121    assert_equal(simple_hash(53), 8385);
 122    assert_equal(simple_hash("Foobar"), 1065337);
 123    assert_equal(simple_hash([]), 0);
 124    assert_equal(simple_hash([[10,20],[-5,3]]), 42685374681);
 125}
 126test_simple_hash();
 127
 128
 129module test_f_1arg() {
 130    assert_equal(str(f_1arg(function (x) x)), "function(a) ((a == undef) ? function(x) target_func(x) : function() target_func(a))");
 131    assert_equal(str(f_1arg(function (x) x)(3)), "function() target_func(a)");
 132    assert_equal(f_1arg(function (x) x)()(4), 4);
 133    assert_equal(f_1arg(function (x) x)(3)(), 3);
 134}
 135test_f_1arg();
 136
 137
 138module test_f_2arg() {
 139    assert_equal(str(f_2arg(function (a,b) a+b)), "function(a, b) (((a == undef) && (b == undef)) ? function(x, y) target_func(x, y) : ((a == undef) ? function(x) target_func(x, b) : ((b == undef) ? function(x) target_func(a, x) : function() target_func(a, b))))");
 140    assert_equal(str(f_2arg(function (a,b) a+b)(3)), "function(x) target_func(a, x)");
 141    assert_equal(str(f_2arg(function (a,b) a+b)(a=3)), "function(x) target_func(a, x)");
 142    assert_equal(str(f_2arg(function (a,b) a+b)(b=3)), "function(x) target_func(x, b)");
 143    assert_equal(str(f_2arg(function (a,b) a+b)(3,4)), "function() target_func(a, b)");
 144    assert_equal(f_2arg(function (a,b) a+b)()(4,2), 6);
 145    assert_equal(f_2arg(function (a,b) a+b)(3)(7), 10);
 146    assert_equal(f_2arg(function (a,b) a+b)(a=2)(7), 9);
 147    assert_equal(f_2arg(function (a,b) a/b)(a=8)(2), 4);
 148}
 149test_f_2arg();
 150
 151
 152module test_f_3arg() {
 153    assert_equal(str(f_3arg(function (a,b,c) a+b+c)), "function(a, b, c) ((((a == undef) && (b == undef)) && (c == undef)) ? function(x, y, z) target_func(x, y, z) : (((a == undef) && (b == undef)) ? function(x, y) target_func(x, y, c) : (((a == undef) && (c == undef)) ? function(x, y) target_func(x, b, y) : (((b == undef) && (c == undef)) ? function(x, y) target_func(a, x, y) : ((a == undef) ? function(x) target_func(x, b, c) : ((b == undef) ? function(x) target_func(a, x, c) : ((c == undef) ? function(x) target_func(a, b, x) : function() target_func(a, b, c))))))))");
 154    assert_equal(str(f_3arg(function (a,b,c) a+b+c)(3)), "function(x, y) target_func(a, x, y)");
 155    assert_equal(str(f_3arg(function (a,b,c) a+b+c)(3,4)), "function(x) target_func(a, b, x)");
 156    assert_equal(str(f_3arg(function (a,b,c) a+b+c)(3,4,1)), "function() target_func(a, b, c)");
 157    assert_equal(f_3arg(function (a,b,c) a+b+c)()(4,2,1), 7);
 158    assert_equal(f_3arg(function (a,b,c) a+b+c)(3)(7,3), 13);
 159    assert_equal(f_3arg(function (a,b,c) a+b+c)(a=2)(7,1), 10);
 160    assert_equal(f_3arg(function (a,b,c) a/b/c)(a=24)(3,2), 4);
 161    assert_equal(f_3arg(function (a,b,c) a+b+c)(3,7)(3), 13);
 162    assert_equal(f_3arg(function (a,b,c) a+b+c)(3,7,3)(), 13);
 163}
 164test_f_3arg();
 165
 166
 167module test_ival() {
 168    assert_equal(str(ival(function (a) a)), "function(a, b) target_func(a)");
 169    assert_equal(ival(function (a) a)(3,5), 3);
 170}
 171test_ival();
 172
 173
 174module test_xval() {
 175    assert_equal(str(xval(function (a) a)), "function(a, b) target_func(b)");
 176    assert_equal(xval(function (a) a)(3,5), 5);
 177}
 178test_xval();
 179
 180
 181module _test_fn1arg(dafunc,tests) {
 182    assert_equal(str(dafunc()),    "function(x) target_func(x)");
 183    assert_equal(str(dafunc(3)),   "function() target_func(a)");
 184    for (test = tests) {
 185        a = test[0];
 186        r = test[1];
 187        assert_equal(dafunc(a)(), r);
 188        assert_equal(dafunc()(a), r);
 189    }
 190}
 191
 192
 193module _test_fn2arg(dafunc,tests) {
 194    assert_equal(str(dafunc()),    "function(x, y) target_func(x, y)");
 195    assert_equal(str(dafunc(3)),   "function(x) target_func(a, x)");
 196    assert_equal(str(dafunc(a=3)), "function(x) target_func(a, x)");
 197    assert_equal(str(dafunc(b=3)), "function(x) target_func(x, b)");
 198    assert_equal(str(dafunc(3,4)), "function() target_func(a, b)");
 199    for (test = tests) {
 200        a = test[0];
 201        b = test[1];
 202        r = test[2];
 203        assert_equal(dafunc(a=a,b=b)(), r);
 204        assert_equal(dafunc(a,b)(), r);
 205        assert_equal(dafunc(a)(b), r);
 206        assert_equal(dafunc(a=a)(b), r);
 207        assert_equal(dafunc(b=b)(a), r);
 208        assert_equal(dafunc()(a,b), r);
 209    }
 210}
 211
 212
 213module _test_fn2arg_simple(dafunc,tests) {
 214    assert_equal(str(dafunc()),    "function(x, y) target_func(x, y)");
 215    assert_equal(str(dafunc(3)), "function(x) target_func(x, a)");
 216    assert_equal(str(dafunc(3,4)), "function() target_func(a, b)");
 217    for (test = tests) {
 218        a = test[0];
 219        b = test[1];
 220        r = test[2];
 221        assert_equal(dafunc(a=a,b=b)(), r);
 222        assert_equal(dafunc(a,b)(), r);
 223        assert_equal(dafunc(b)(a), r);
 224        assert_equal(dafunc()(a,b), r);
 225    }
 226}
 227
 228
 229module _test_fn3arg(dafunc,tests) {
 230    assert_equal(str(dafunc()),    "function(x, y, z) target_func(x, y, z)");
 231    assert_equal(str(dafunc(3)),   "function(x, y) target_func(a, x, y)");
 232    assert_equal(str(dafunc(a=3)), "function(x, y) target_func(a, x, y)");
 233    assert_equal(str(dafunc(b=3)), "function(x, y) target_func(x, b, y)");
 234    assert_equal(str(dafunc(c=3)), "function(x, y) target_func(x, y, c)");
 235    assert_equal(str(dafunc(3,4)), "function(x) target_func(a, b, x)");
 236    assert_equal(str(dafunc(a=3,b=4)), "function(x) target_func(a, b, x)");
 237    assert_equal(str(dafunc(a=3,c=4)), "function(x) target_func(a, x, c)");
 238    assert_equal(str(dafunc(b=3,c=4)), "function(x) target_func(x, b, c)");
 239    assert_equal(str(dafunc(3,4,5)), "function() target_func(a, b, c)");
 240    for (test = tests) {
 241        a = test[0];
 242        b = test[1];
 243        c = test[2];
 244        r = test[3];
 245        assert_equal(dafunc(a=a,b=b,c=c)(), r);
 246        assert_equal(dafunc(a,b,c)(), r);
 247        assert_equal(dafunc(a)(b,c), r);
 248        assert_equal(dafunc(b=b,c=c)(a), r);
 249        assert_equal(dafunc(a=a,c=c)(b), r);
 250        assert_equal(dafunc(a=a,b=b)(c), r);
 251        assert_equal(dafunc(a=a)(b,c), r);
 252        assert_equal(dafunc(b=b)(a,c), r);
 253        assert_equal(dafunc(c=c)(a,b), r);
 254        assert_equal(dafunc()(a,b,c), r);
 255    }
 256}
 257
 258
 259module test_f_cmp() {
 260    _test_fn2arg_simple(
 261        function (a,b) f_cmp(a,b),
 262        [[4,3,1],[3,3,0],[3,4,-1]]
 263    );
 264}
 265test_f_cmp();
 266
 267
 268module test_f_gt() {
 269    _test_fn2arg_simple(
 270        function (a,b) f_gt(a,b),
 271        [[4,3,true],[3,3,false],[3,4,false]]
 272    );
 273}
 274test_f_gt();
 275
 276
 277module test_f_gte() {
 278    _test_fn2arg_simple(
 279        function (a,b) f_gte(a,b),
 280        [[4,3,true],[3,3,true],[3,4,false]]
 281    );
 282}
 283test_f_gte();
 284
 285
 286module test_f_lt() {
 287    _test_fn2arg_simple(
 288        function (a,b) f_lt(a,b),
 289        [[4,3,false],[3,3,false],[3,4,true]]
 290    );
 291}
 292test_f_lt();
 293
 294
 295module test_f_lte() {
 296    _test_fn2arg_simple(
 297        function (a,b) f_lte(a,b),
 298        [[4,3,false],[3,3,true],[3,4,true]]
 299    );
 300}
 301test_f_lte();
 302
 303
 304module test_f_eq() {
 305    _test_fn2arg_simple(
 306        function (a,b) f_eq(a,b),
 307        [[4,3,false],[3,3,true],[3,4,false]]
 308    );
 309}
 310test_f_eq();
 311
 312
 313module test_f_neq() {
 314    _test_fn2arg_simple(
 315        function (a,b) f_neq(a,b),
 316        [[4,3,true],[3,3,false],[3,4,true]]
 317    );
 318}
 319test_f_neq();
 320
 321
 322module test_f_approx() {
 323    _test_fn2arg_simple(
 324        function (a,b) f_approx(a,b),
 325        [[4,3,false],[3,3,true],[3,4,false],[1/3,0.33333333333333333333333333,true]]
 326    );
 327}
 328test_f_approx();
 329
 330
 331module test_f_napprox() {
 332    _test_fn2arg_simple(
 333        function (a,b) f_napprox(a,b),
 334        [[4,3,true],[3,3,false],[3,4,true],[1/3,0.33333333333333333333333333,false]]
 335    );
 336}
 337test_f_napprox();
 338
 339
 340module test_f_or() {
 341    _test_fn2arg(
 342        function (a,b) f_or(a,b),
 343        [
 344            [false, false, false],
 345            [true , false, true ],
 346            [false, true , true ],
 347            [true , true , true ]
 348        ]
 349    );
 350}
 351test_f_or();
 352
 353
 354module test_f_and() {
 355    _test_fn2arg(
 356        function (a,b) f_and(a,b),
 357        [
 358            [false, false, false],
 359            [true , false, false],
 360            [false, true , false],
 361            [true , true , true ]
 362        ]
 363    );
 364}
 365test_f_and();
 366
 367
 368module test_f_nor() {
 369    _test_fn2arg(
 370        function (a,b) f_nor(a,b),
 371        [
 372            [false, false, true ],
 373            [true , false, false],
 374            [false, true , false],
 375            [true , true , false]
 376        ]
 377    );
 378}
 379test_f_nor();
 380
 381
 382module test_f_nand() {
 383    _test_fn2arg(
 384        function (a,b) f_nand(a,b),
 385        [
 386            [false, false, true ],
 387            [true , false, true ],
 388            [false, true , true ],
 389            [true , true , false]
 390        ]
 391    );
 392}
 393test_f_nand();
 394
 395
 396module test_f_xor() {
 397    _test_fn2arg(
 398        function (a,b) f_xor(a,b),
 399        [
 400            [false, false, false],
 401            [true , false, true ],
 402            [false, true , true ],
 403            [true , true , false]
 404        ]
 405    );
 406}
 407test_f_xor();
 408
 409
 410module test_f_not() {
 411    _test_fn1arg(
 412        function (a) f_not(a),
 413        [
 414            [true,  false],
 415            [false, true ],
 416        ]
 417    );
 418}
 419test_f_not();
 420
 421
 422module test_f_even() {
 423    _test_fn1arg(
 424        function (a) f_even(a),
 425        [
 426            [-3, false],
 427            [-2, true ],
 428            [-1, false],
 429            [ 0, true ],
 430            [ 1, false],
 431            [ 2, true ],
 432            [ 3, false],
 433        ]
 434    );
 435}
 436test_f_even();
 437
 438
 439module test_f_odd() {
 440    _test_fn1arg(
 441        function (a) f_odd(a),
 442        [
 443            [-3, true ],
 444            [-2, false],
 445            [-1, true ],
 446            [ 0, false],
 447            [ 1, true ],
 448            [ 2, false],
 449            [ 3, true ],
 450        ]
 451    );
 452}
 453test_f_odd();
 454
 455
 456module test_f_add() {
 457    _test_fn2arg(
 458        function (a,b) f_add(a,b),
 459        [[4,3,7],[3,3,6],[3,2,5],[-3,-5,-8],[-3,7,4],[3,-7,-4]]
 460    );
 461}
 462test_f_add();
 463
 464
 465module test_f_sub() {
 466    _test_fn2arg(
 467        function (a,b) f_sub(a,b),
 468        [[4,3,1],[3,3,0],[3,4,-1],[-3,-5,2],[-3,6,-9],[3,-6,9]]
 469    );
 470}
 471test_f_sub();
 472
 473
 474module test_f_mul() {
 475    _test_fn2arg(
 476        function (a,b) f_mul(a,b),
 477        [[4,3,12],[3,3,9],[3,2,6],[-3,-5,15],[-3,7,-21],[3,-7,-21]]
 478    );
 479}
 480test_f_mul();
 481
 482
 483module test_f_div() {
 484    _test_fn2arg(
 485        function (a,b) f_div(a,b),
 486        [[21,3,7],[21,7,3],[16,4,4],[-16,4,-4],[-16,-4,4]]
 487    );
 488}
 489test_f_div();
 490
 491
 492module test_f_mod() {
 493    _test_fn2arg(
 494        function (a,b) f_mod(a,b),
 495        [[21,3,0],[22,7,1],[23,3,2],[24,3,0]]
 496    );
 497}
 498test_f_mod();
 499
 500
 501module test_f_pow() {
 502    _test_fn2arg(
 503        function (a,b) f_pow(a,b),
 504        [[2,3,8],[3,3,27],[4,2,16],[2,-3,1/8]]
 505    );
 506}
 507test_f_pow();
 508
 509
 510module test_f_sin() {
 511    _test_fn1arg(
 512        function (a) f_sin(a),
 513        [[-270,1],[-180,0],[-90,-1],[0,0],[90,1],[180,0],[270,-1],[360,0]]
 514    );
 515}
 516test_f_sin();
 517
 518
 519module test_f_cos() {
 520    _test_fn1arg(
 521        function (a) f_cos(a),
 522        [[-270,0],[-180,-1],[-90,0],[0,1],[90,0],[180,-1],[270,0],[360,1]]
 523    );
 524}
 525test_f_cos();
 526
 527
 528module test_f_tan() {
 529    _test_fn1arg(
 530        function (a) f_tan(a),
 531        [[-135,1],[-45,-1],[0,0],[45,1],[135,-1]]
 532    );
 533}
 534test_f_tan();
 535
 536
 537module test_f_asin() {
 538    _test_fn1arg(
 539        function (a) f_asin(a),
 540        [[-1,-90],[0,0],[1,90]]
 541    );
 542}
 543test_f_asin();
 544
 545
 546module test_f_acos() {
 547    _test_fn1arg(
 548        function (a) f_acos(a),
 549        [[-1,180],[-0.5,120],[0,90],[0.5,60],[1,0]]
 550    );
 551}
 552test_f_acos();
 553
 554
 555module test_f_atan() {
 556    _test_fn1arg(
 557        function (a) f_atan(a),
 558        [[-1,-45],[0,0],[1,45]]
 559    );
 560}
 561test_f_atan();
 562
 563
 564module test_f_atan2() {
 565    _test_fn2arg(
 566        function (a,b) f_atan2(a,b),
 567        [[-1,0,-90],[-1,1,-45],[0,1,0],[1,0,90],[1,1,45]]
 568    );
 569}
 570test_f_atan();
 571
 572
 573module test_f_exp() {
 574    _test_fn1arg(
 575        function (a) f_exp(a),
 576        [[-1,exp(-1)],[0,1],[1,exp(1)]]
 577    );
 578}
 579test_f_exp();
 580
 581
 582module test_f_ln() {
 583    _test_fn1arg(
 584        function (a) f_ln(a),
 585        [[1,0],[1,ln(1)],[10,ln(10)]]
 586    );
 587}
 588test_f_ln();
 589
 590
 591module test_f_log() {
 592    _test_fn1arg(
 593        function (a) f_log(a),
 594        [[1,0],[100,2],[10000,4]]
 595    );
 596}
 597test_f_log();
 598
 599
 600module test_f_sqr() {
 601    _test_fn1arg(
 602        function (a) f_sqr(a),
 603        [[-5,25],[5,25],[9,81]]
 604    );
 605}
 606test_f_sqr();
 607
 608
 609module test_f_sqrt() {
 610    _test_fn1arg(
 611        function (a) f_sqrt(a),
 612        [[25,5],[16,4],[81,9]]
 613    );
 614}
 615test_f_sqrt();
 616
 617
 618module test_f_sign() {
 619    _test_fn1arg(
 620        function (a) f_sign(a),
 621        [[-99,-1],[-1,-1],[0,0],[1,1],[99,1]]
 622    );
 623}
 624test_f_sign();
 625
 626
 627module test_f_abs() {
 628    _test_fn1arg(
 629        function (a) f_abs(a),
 630        [[-99,99],[-1,1],[0,0],[1,1],[99,99]]
 631    );
 632}
 633test_f_abs();
 634
 635
 636module test_f_neg() {
 637    _test_fn1arg(
 638        function (a) f_neg(a),
 639        [[-99,99],[-1,1],[0,0],[1,-1],[99,-99]]
 640    );
 641}
 642test_f_neg();
 643
 644
 645module test_f_ceil() {
 646    _test_fn1arg(
 647        function (a) f_ceil(a),
 648        [[-9.9,-9],[-9.1,-9],[-1,-1],[0,0],[1,1],[1.1,2],[1.9,2],[9.1,10],[9.9,10]]
 649    );
 650}
 651test_f_ceil();
 652
 653
 654module test_f_floor() {
 655    _test_fn1arg(
 656        function (a) f_floor(a),
 657        [[-9.9,-10],[-9.1,-10],[-1,-1],[0,0],[1,1],[1.1,1],[1.9,1],[9.1,9],[9.9,9]]
 658    );
 659}
 660test_f_floor();
 661
 662
 663module test_f_round() {
 664    _test_fn1arg(
 665        function (a) f_round(a),
 666        [[-9.9,-10],[-9.5,-10],[-9.1,-9],[-1,-1],[0,0],[1,1],[1.1,1],[1.9,2],[9.1,9],[9.5,10],[9.9,10]]
 667    );
 668}
 669test_f_round();
 670
 671
 672module test_f_cross() {
 673    _test_fn2arg(
 674        function (a,b) f_cross(a,b),
 675        [[UP,LEFT,FWD], [BACK+RIGHT,FWD,DOWN]]
 676    );
 677}
 678test_f_cross();
 679
 680
 681module test_f_norm() {
 682    _test_fn1arg(
 683        function (a) f_norm(a),
 684        [[UP,1], [BACK+RIGHT,sqrt(2)], [[3,4],5]]
 685    );
 686}
 687test_f_norm();
 688
 689
 690module test_f_chr() {
 691    _test_fn1arg(
 692        function (a) f_chr(a),
 693        [[65,"A"],[97,"a"],[70,"F"],[102,"f"],[48,"0"],[57,"9"]]
 694    );
 695}
 696test_f_chr();
 697
 698
 699module test_f_ord() {
 700    _test_fn1arg(
 701        function (a) f_ord(a),
 702        [["A",65],["a",97],["F",70],["f",102],["0",48],["9",57]]
 703    );
 704}
 705test_f_ord();
 706
 707
 708module test_f_len() {
 709    _test_fn1arg(
 710        function (a) f_len(a),
 711        [["A",1],["abc",3],["foobar",6],["freeb",5],["",0],["9",1]]
 712    );
 713}
 714test_f_len();
 715
 716
 717module test_f_str() {
 718    _test_fn1arg(
 719        function (a) f_str(a),
 720        [[123,"123"],[true,"true"],[false,"false"],[undef,"undef"],[3.14159,"3.14159"],[[3,4,5,true],"[3, 4, 5, true]"]]
 721    );
 722}
 723test_f_str();
 724
 725
 726module test_f_str2() {
 727    _test_fn2arg(
 728        function (a,b) f_str2(a,b),
 729        [[12,34,"1234"], [[3,4,5,true],"foo","[3, 4, 5, true]foo"], ["foo","bar","foobar"]]
 730    );
 731}
 732test_f_str2();
 733
 734
 735module test_f_str3() {
 736    _test_fn3arg(
 737        function (a,b,c) f_str3(a,b,c),
 738        [[12,34,56,"123456"], [[3,4,5,true],"foo","bar","[3, 4, 5, true]foobar"], ["foo",88,"baz","foo88baz"]]
 739    );
 740}
 741test_f_str3();
 742
 743
 744module test_f_min() {
 745    _test_fn1arg(
 746        function (a) f_min(a),
 747        [[[8,3,7,4],3], [[-4,-5,-6,-7],-7], [[4,8,2,-3,3,8,0,-5,9,6],-5]]
 748    );
 749}
 750test_f_min();
 751
 752
 753module test_f_max() {
 754    _test_fn1arg(
 755        function (a) f_max(a),
 756        [[[8,3,7,4],8], [[-4,-5,-6,-7],-4], [[4,8,2,-3,3,8,0,-5,9,6],9]]
 757    );
 758}
 759test_f_max();
 760
 761
 762module test_f_min2() {
 763    _test_fn2arg(
 764        function (a,b) f_min2(a,b),
 765        [[8,3,3], [-6,-7,-7], [-4,13,-4]]
 766    );
 767}
 768test_f_min2();
 769
 770
 771module test_f_max2() {
 772    _test_fn2arg(
 773        function (a,b) f_max2(a,b),
 774        [[8,3,8], [-4,-5,-4], [-3,7,7]]
 775    );
 776}
 777test_f_max2();
 778
 779
 780module test_f_min3() {
 781    _test_fn3arg(
 782        function (a,b,c) f_min3(a,b,c),
 783        [[8,3,5,3], [-6,-7,5,-7], [-4,13,5,-4]]
 784    );
 785}
 786test_f_min3();
 787
 788
 789module test_f_max3() {
 790    _test_fn3arg(
 791        function (a,b,c) f_max3(a,b,c),
 792        [[8,3,5,8], [-4,-5,4,4], [-3,7,4,7]]
 793    );
 794}
 795test_f_max3();
 796
 797
 798module test_f_is_bool() {
 799    testfn = f_is_bool();
 800    for (test = [
 801        [undef,   false],
 802        [false,   true],
 803        [true,    true],
 804        [0,       false],
 805        [3,       false],
 806        ["foo",   false],
 807        [[4,5,6], false]
 808    ]) {
 809        assert(testfn(test[0]), test[1]);
 810    }
 811}
 812test_f_is_bool();
 813
 814
 815module test_f_is_def() {
 816    testfn = f_is_def();
 817    for (test = [
 818        [undef,   false],
 819        [false,   true],
 820        [true,    true],
 821        [0,       true],
 822        [3,       true],
 823        ["foo",   true],
 824        [[4,5,6], true]
 825    ]) {
 826        assert(testfn(test[0]), test[1]);
 827    }
 828}
 829test_f_is_def();
 830
 831
 832module test_f_is_undef() {
 833    testfn = f_is_undef();
 834    for (test = [
 835        [undef,   true],
 836        [false,   false],
 837        [true,    false],
 838        [0,       false],
 839        [3,       false],
 840        ["foo",   false],
 841        [[4,5,6], false]
 842    ]) {
 843        assert(testfn(test[0]), test[1]);
 844    }
 845}
 846test_f_is_undef();
 847
 848
 849module test_f_is_num() {
 850    testfn = f_is_num();
 851    for (test = [
 852        [undef,   false],
 853        [false,   false],
 854        [true,    false],
 855        [-4.5,    true],
 856        [-4,      true],
 857        [0,       true],
 858        [1.5,     true],
 859        [3,       true],
 860        [INF,     true],
 861        [-INF,    true],
 862        [NAN,     false],
 863        ["foo",   false],
 864        [[4,5,6], false]
 865    ]) {
 866        assert(testfn(test[0]), test[1]);
 867    }
 868}
 869test_f_is_num();
 870
 871
 872module test_f_is_int() {
 873    testfn = f_is_int();
 874    for (test = [
 875        [undef,   false],
 876        [false,   false],
 877        [true,    false],
 878        [-4,      true],
 879        [-4.5,    false],
 880        [0,       true],
 881        [1.5,     false],
 882        [3,       true],
 883        [INF,     false],
 884        [-INF,    false],
 885        [NAN,     false],
 886        ["foo",   false],
 887        [[4,5,6], false]
 888    ]) {
 889        assert(testfn(test[0]), test[1]);
 890    }
 891}
 892test_f_is_int();
 893
 894
 895module test_f_is_nan() {
 896    testfn = f_is_nan();
 897    for (test = [
 898        [undef,   false],
 899        [false,   false],
 900        [true,    false],
 901        [-4,      false],
 902        [-4.5,    false],
 903        [0,       false],
 904        [1.5,     false],
 905        [3,       false],
 906        [INF,     false],
 907        [-INF,    false],
 908        [NAN,     true],
 909        ["foo",   false],
 910        [[4,5,6], false]
 911    ]) {
 912        assert(testfn(test[0]), test[1]);
 913    }
 914}
 915test_f_is_nan();
 916
 917
 918module test_f_is_finite() {
 919    testfn = f_is_finite();
 920    for (test = [
 921        [undef,   false],
 922        [false,   false],
 923        [true,    false],
 924        [-4,      true],
 925        [0,       true],
 926        [1.5,     true],
 927        [3,       true],
 928        [INF,     false],
 929        [-INF,    false],
 930        [NAN,     false],
 931        ["foo",   false],
 932        [[4,5,6], false]
 933    ]) {
 934        assert(testfn(test[0]), test[1]);
 935    }
 936}
 937test_f_is_finite();
 938
 939
 940module test_f_is_string() {
 941    testfn = f_is_string();
 942    for (test = [
 943        [undef,   false],
 944        [false,   false],
 945        [true,    false],
 946        [-4,      false],
 947        [0,       false],
 948        [1.5,     false],
 949        [3,       false],
 950        [INF,     false],
 951        [-INF,    false],
 952        [NAN,     false],
 953        ["",      true],
 954        ["foo",   true],
 955        [[4,5,6], false],
 956        [[4:1:6], false]
 957    ]) {
 958        assert(testfn(test[0]), test[1]);
 959    }
 960}
 961test_f_is_string();
 962
 963
 964module test_f_is_list() {
 965    testfn = f_is_list();
 966    for (test = [
 967        [undef,   false],
 968        [false,   false],
 969        [true,    false],
 970        [-4,      false],
 971        [0,       false],
 972        [1.5,     false],
 973        [3,       false],
 974        [INF,     false],
 975        [-INF,    false],
 976        [NAN,     false],
 977        ["",      false],
 978        ["foo",   false],
 979        [[4,5,6], true],
 980        [[4:1:6], false]
 981    ]) {
 982        assert(testfn(test[0]), test[1]);
 983    }
 984}
 985test_f_is_list();
 986
 987
 988module test_f_is_path() {
 989    testfn = f_is_path();
 990    for (test = [
 991        [undef,   false],
 992        [false,   false],
 993        [true,    false],
 994        [-4,      false],
 995        [0,       false],
 996        [1.5,     false],
 997        [3,       false],
 998        [INF,     false],
 999        [-INF,    false],
1000        [NAN,     false],
1001        ["",      false],
1002        ["foo",   false],
1003        [[4,5,6], false],
1004        [[4:1:6], false],
1005        [square(100), true],
1006        [circle(100), true]
1007    ]) {
1008        assert(testfn(test[0]), test[1]);
1009    }
1010}
1011test_f_is_path();
1012
1013
1014
1015// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap