;;;; slib-charplot-test.scm ;;;; Kon Lovett, Mar '20 (import test) (test-begin "Charplot (SLIB)") (import slib-charplot) (import (chicken base)) (import (chicken type)) (import (srfi 63)) ;; #; ;Pass - Argument #1 to procedure `plot' has an invalid type:... (plot "FAILS" "" "") (print) (print "*** Plot w/ dimensions 4x5+2 (minimum safe @ minimum left-margin)") (print) ;Fail - infinite loop forall H, W : H < 4, W < (5 + LM) (let ((margin (plot-left-margin))) (plot-left-margin #f) (plot-dimensions (list 4 (+ 5 (plot-left-margin)))) (plot (list->array 2 '#() '((1 2) (3 4) (5 6))) "A" "B") (plot-left-margin margin) ) ;;;"Tests" (examples) from http://people.csail.mit.edu/jaffer/slib_5.html#SEC125 ;; (print) (print "*** Plot w/ dimensions 20x55") (print) ;ex 1 (plot-dimensions '(20 55)) (define (make-points n) (if (zero? n) '() (cons (list (/ n 6) (sin (/ n 6))) (make-points (sub1 n))))) (plot (make-points 40) "x" "Sin(x)") ;checkout the, undocumented, histogram? switch (print) (print "*** Histogram w/ dimensions 20x55 (NOTE undocumented by SLIB site)") (print) (plot (make-points 40) "x" "Sin(x)" #t) ;; ;mathh (define-constant PI 3.1415926535897932384626433832795028841972) ; pi (define pi PI) ; pi ;test framing (plot-dimensions #f) (print) (print "*** Plot w/ dimensions (#f)") (print) ;ex 2 (plot sin 0 (* 2 pi)) ;; ;srfi-27 (define-type random-f64-function (-> float)) ;fortran "real" (define-type random-real-function random-f64-function) (define-type number-function (-> number)) ;; Knuth's "The Art of Computer Programming", Vol. II, 2nd ed., ;; Algorithm P of Section 3.4.1.C. (: *make-random-normals (number number random-real-function --> number-function)) ; (define (*make-random-normals mu sigma randoms) (let ((next #f)) (lambda () (if next (let ((result next)) (set! next #f) (+ mu (* sigma result))) (let loop () (let* ( (v1 (- (* 2.0 (randoms)) 1.0) ) (v2 (- (* 2.0 (randoms)) 1.0) ) (s (+ (* v1 v1) (* v2 v2)) ) ) ; (if (<= 1.0 s) (loop) (let ((scale (sqrt (/ (* -2.0 (log s)) s)))) (set! next (* scale v2)) (+ mu (* sigma scale v1))))))))) ) ;SLIB wrapper (define random:normal (let ( (random-normal (let () (import (only (chicken random) pseudo-random-real)) (*make-random-normals 0.0 1.0 pseudo-random-real))) ) (lambda () (random-normal) ) ) ) ;test framing (plot-left-margin #f) (plot-dimensions '(20 55)) (print) (print "*** Histograph w/ dimensions 20x55 & left-margin (#f)") (print) ;ex 3 (histograph (do ((idx 99 (+ -1 idx)) (lst '() (cons (* .02 (random:normal)) lst))) ((negative? idx) lst)) "normal") ;; (test-end "Charplot (SLIB)") (test-exit)