(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)
(check (evector? (vector 1 2 3)) => #f)
(check (evector? (evector 1 2 3)) => #t)
(check (evector? (evector)) => #t)
(check (evector-fill (make-evector 10 'foo)) => 'foo)
(check (let ([v (make-evector 10 'foo)])
(set-evector-fill! v 'bar)
(evector-fill v))
=> 'bar)
(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)))
(check (every?-ec (: i 100)
(= (evector-length (make-evector i)) i))
=> #t)
(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)
(let ([v (vector-ec (: i 100) i)])
(check (let ([ev (evector)])
(do-ec (:vector x v)
(evector-push! ev x))
(evector->vector ev))
=> v))
(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))))
(check (let ([v (evector 0 1 2 3)])
(every?-ec (: i 4)
(= (evector-ref v i) i)))
=> #t)
(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)
(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)
(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))
(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)
(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)
(check-report)