test/test-draw.rkt
#lang racket

(require "../rsound.rkt"
         "../draw.rkt"
         ffi/vector
         rackunit)




(check-equal? (abs-max-from (lambda (x) (- 5 (* x x))) 4) 5)
(check-equal? (abs-max-from (lambda (x) (- 5 (* x x))) 5) 11)


(check-equal? (interpolate (lambda (x) x) 0.7) 0.7)
(check-equal? (interpolate (lambda (x) (+ 2/3 (- (* x x)))) 10) (- 2/3 100))

(check-equal? (call-with-values (lambda () (rasterize-column (lambda (x) (+ 2/3 (- (* x x)))) -3 10)) list)
              (list (- 2/3 100) 2/3))

(check-equal? (call-with-values (lambda () (rasterize-column (lambda (x) (+ 2/3 (- (* x x)))) -3.5 1)) list)
              (list (- 2/3 12.5) (exact->inexact 2/3)))


;; these don't really lend themselves to testing; I suppose if I separated
;; the rendering from the drawing...

(define rsound-4samp (rsound (s16vector 0 0 50 50 -50 -50 0 0) 4 44100))

#;(rsound-draw rsound-4samp #:title "4samp")

(define s16max #x7fff)

(define rsound-800samp (rsound (apply s16vector (build-list 1600 (lambda (i) (inexact->exact (round (* s16max (sin (* 2 pi 3/800 i)))))))) 800 44100))
#;(rsound-draw rsound-800samp #:width 800)

#;(rsound-draw rsound-800samp #:width 400)

#;(rsound-draw rsound-800samp #:width 20)

#;(define rsound-longer (read-rsound/clip "/tmp/gmafh.wav" (* 44100 60) (* 44100 70)))

#;(play-rsound rsound-longer)

#;(rsound-draw rsound-longer #:width 800)


;; drawing non-sounds

#;(let ([lvec (vector 3 4123 2 4 3 2 2 2 4 2 3 4 1 2 2 23  4 3 3)]
      [rvec (vector 3 23 298 4 2 23 1 2 3 4 9 8 2 24 2 79 1 23 9)])
  (vectors-draw "zoo"
                (lambda (i) (vector-ref lvec i))
                (lambda (i) (vector-ref rvec i))
                19
                800
                200))