picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

bigtest (2585B)


      1 #!bin/picolisp lib.l
      2 # 25apr11abu
      3 # misc/bigtest <seed>
      4 
      5 (load "@lib/misc.l")
      6 
      7 (seed (car (argv)))
      8 
      9 #  Random patterns:
     10 #  cnt
     11 #     xxx0000000000000000000000000xxxx0000000000000000000000000xxx
     12 #        (| 7 (>> -28 15) (>> -57 7))
     13 #
     14 #     xxx1111111111111111111111111xxxx1111111111111111111111111xxx
     15 #        1FFFFFF0FFFFFF8
     16 #
     17 #
     18 #  dig
     19 #     xxx000000000000000000000000000xxxx000000000000000000000000000xxx
     20 #        (| 7 (>> -30 15) (>> -61 7))
     21 #
     22 #     xxx111111111111111111111111111xxxx111111111111111111111111111xxx
     23 #        1FFFFFFC3FFFFFF8
     24 
     25 (de rnd ()
     26    (let (Big (| (rand 0 7) (>> -28 (rand 0 15)) (>> -57 (rand 0 7)))  N -60)
     27       (when (rand T)
     28          (setq Big (| Big `(hex "1FFFFFF0FFFFFF8"))) )
     29       (do (rand 0 2)
     30          (let Dig (| (rand 0 7) (>> -30 (rand 0 15)) (>> -61 (rand 0 7)))
     31             (when (rand T)
     32                (setq Dig (| Dig `(hex "1FFFFFFC3FFFFFF8"))) )
     33             (setq Big (| Big (>> N Dig)))
     34             (dec 'N 64) ) )
     35       (if (rand T) Big (- Big)) ) )
     36 
     37 
     38 (de test1 (S N1)
     39    (let (N (read)  X (eval (list S N1)))
     40       (unless (= N X)
     41          (prinl "^J" N ": (" S " " N1 ") -> " X)
     42          (bye) ) ) )
     43 
     44 (de test2 (S N1 N2)
     45    (let (N (read)  X (eval (list S N1 N2)))
     46       (unless (= N X)
     47          (prinl "^J" N ": (" S " " N1 " " N2 ") -> " X)
     48          (bye) ) ) )
     49 
     50 (de cmp2 (S N1 N2)
     51    (let (N (n0 (read))  X (eval (list S N1 N2)))
     52       (unless (== N X)
     53          (prinl "^J" N ": (" S " " N1 " " N2 ") -> " X)
     54          (bye) ) ) )
     55 
     56 
     57 (sys "BC_LINE_LENGTH" "200")
     58 
     59 (pipe
     60    (out '("/usr/bin/bc")
     61       (do 10000000
     62          (setq N1 (rnd))
     63          (while (=0 (setq N2 (rnd))))
     64          (prinl N1)
     65          (prinl N2)
     66          (prinl N1 " + " N2)
     67          (prinl N1 " + 1")
     68          (prinl N1 " + 1")
     69          (prinl N1 " - " N2)
     70          (prinl N1 " - 1")
     71          (prinl N1 " - 1")
     72          (prinl N1 " * " N2)
     73          (prinl N1 " * 2")
     74          (prinl N1 " % " N2)
     75          (prinl N1 " / " N2)
     76          (prinl N1 " / 2")
     77          (prinl N1 " >= " N2)
     78          (prinl N1 " > " N2)
     79          (prinl "sqrt(" (abs N1) ")") ) )
     80    (do 100
     81       (do 100000
     82          (setq
     83             N1 (read)
     84             N2 (read) )
     85          (test2 '+ N1 N2)
     86          (test2 '+ N1 1)
     87          (test1 'inc N1)
     88          (test2 '- N1 N2)
     89          (test2 '- N1 1)
     90          (test1 'dec N1)
     91          (test2 '* N1 N2)
     92          (test2 '* N1 2)
     93          (test2 '% N1 N2)
     94          (test2 '/ N1 N2)
     95          (test2 '/ N1 2)
     96          (cmp2 '>= N1 N2)
     97          (cmp2 '> N1 N2)
     98          (test1 'sqrt (abs N1)) )
     99       (prin ".")
    100       (flush) )
    101    (prinl) )
    102 
    103 (bye)