test-evector.scm
(require "srfi-check.scm"
         "evector.scm"
         (lib "42.ss" "srfi"))

(define default-fill-value (evector-ref (make-evector 1) 0))
(define DFV default-fill-value)

; evector
; evector?
(check (evector? (vector 1 2 3)) => #f)
(check (evector? (evector 1 2 3)) => #t)
(check (evector? (evector)) => #t)

; evector-fill
(check (evector-fill (make-evector 10 'foo)) => 'foo)
(check (let ([v (make-evector 10 'foo)])
         (set-evector-fill! v 'bar)
         (evector-fill v))
       => 'bar)

; evector-fill!
(check (every?-ec (: l 100)
                  (let ([v (make-evector l)])
                    (evector-fill! v 'foo)
                    (equal? (evector->vector v)
                            (vector-ec (: i l) 'foo))))
       => #t)
(check (every?-ec (: l 100)
                  (every?-ec (: i l)
                             (:let v (make-evector l 'foo))
                             (begin
                               (evector-fill! v 'bar i))
                             (equal? (evector->vector v)
                                     (vector-ec (: j l) (if (< j i) 'foo 'bar)))))
       => #t)
(check (let ([v (make-evector 20 'foo)])
         (evector-fill! v 'bar 10 15)
         (evector->vector v))
       =>(vector-ec (: i 20) (if (<= 10 i 14) 'bar 'foo)))

; evector-length
(check (every?-ec (: i 100)
                  (= (evector-length (make-evector i)) i))
       => #t)

; evector->list, list->evector
(check (evector->list (evector)) => (list))
(check (evector->list (evector 1 2 3)) => (list 1 2 3))
(check (every?-ec (let ([l (list-ec (: i 100) i)])
                    (equal? l (evector->list (list->evector l)))))
       => #t)

; evector-push!
(let ([v (vector-ec (: i 100) i)])
  (check (let ([ev (evector)])
           (do-ec (:vector x v)
                  (evector-push! ev x))
           (evector->vector ev))
         => v))

; evector-pop!
(let ([v (vector-ec (: i 100) i)])
  (check (let ([ev (vector->evector v)])
           (list-ec (:vector x v)
                    (evector-pop! ev)))
         => (reverse (list-ec (: x v) x))))


; evector-ref
(check (let ([v (evector 0 1 2 3)])
         (every?-ec (: i 4)
                    (= (evector-ref v i) i)))
       => #t)

; evector-set!
(check (let ([v (evector 0 1 2 3)])
         (every?-ec (: i 100)
                    (begin
                      (evector-set! v i 'foo))
                    (eq? (evector-ref v i) 'foo)))
       => #t)

; evector->vector, vector->evector
(check (evector->vector (evector)) => (vector))
(check (evector->vector (evector 1 2 3)) => (vector 1 2 3))
(check (every?-ec (let ([l (vector-ec (: i 100) i)])
                    (equal? l (evector->vector (vector->evector l)))))
       => #t)


; make-evector
(check (evector->list (make-evector 3)) => (list DFV DFV DFV))
(check (evector->list (make-evector 3 'a)) => (list 'a 'a 'a))
(check (evector-fill (make-evector 10 'foo)) => 'foo)
(check (evector->list (make-evector 0 'a #t)) => (list))
(check (evector->list (make-evector 0 'a #f)) => (list))

; set-evector-fill
(check (let ([v (make-evector 10 'foo)])
         (set-evector-fill! v 'bar)
         (evector-fill v))
       => 'bar)
(check (let ([v (make-evector 2 'a)])
         (set-evector-fill! v 'b)
         (set-evector-length! v 1000)
         (evector-ref v 999))
       => 'b)

; set-evector-length!
(check (every?-ec (: i 11 100)
                  (let ([v (make-evector i)])
                    (set-evector-length! v i)
                    (and (= (evector-length v) i)
                         (eqv? DFV (evector-ref v (- i 1))))))
       => #t)


;;; REPORT

(check-report)