;;;; sparse-vectors-extras-test.scm (import test) ;;; (test-begin "Sparse Vectors Extras") (import sparse-vectors (sparse-vectors hof) (sparse-vectors extras)) (import (only (sparse-vectors debug) sparse-vector-info)) (import (chicken sort) (srfi 1)) ;; ;for alist comparison (define (sval< a b) (< (car a) (car b))) (define (sval> a b) (> (car a) (car b))) (define (asc-sv sv) (sort sv sval<)) (define (dsc-sv sv) (sort sv sval>)) ;almost (define (vector->hilbert-node hilbert vec) (let-values (((ct ht sz) (sparse-vector-info hilbert))) (append (vector->list vec) (make-list (- sz (vector-length vec)) #f)) ) ) ;; (define Vec1 #(1 2 3)) (define Vec2 #(1 #f 2 #f 3)) (define Lis1 (vector->list Vec1)) (define Lis2 (vector->list Vec2)) (test-group "Lists" (test-group "list->sparse-vector" (let ((h1 (list->sparse-vector Lis1))) (test 3 (sparse-vector-count h1)) (test '((0 . 1) (1 . 2) (2 . 3)) (asc-sv (sparse-vector->alist h1))) (test (vector->hilbert-node h1 Vec1) (sparse-vector->list h1)) ) ) (test-group "sparse-vector->list" (let ((h1 (list->sparse-vector Lis1))) (test (vector->hilbert-node h1 Vec1) (sparse-vector->list h1)) ) ) ) (test-group "Vectors" (test-group "sparse-vector->vector w/ start" (let ((h1 (make-sparse-vector #f 8))) (test-assert (fill-sparse-vector! h1 Vec1 1)) (test 3 (sparse-vector-count h1)) (test '((1 . 1) (2 . 2) (3 . 3)) (asc-sv (sparse-vector->alist h1))) (test Vec1 (sparse-vector->vector h1 1 4)) ) ) (test-group "vector->sparse-vector" (let ((h1 (vector->sparse-vector Vec1))) (test-assert h1) (test 3 (sparse-vector-count h1)) (test '((0 . 1) (1 . 2) (2 . 3)) (asc-sv (sparse-vector->alist h1))) ) ) (test-group "default value handing" (let ((h1 (vector->sparse-vector Vec2))) (test-assert h1) (test 3 (sparse-vector-count h1)) (test '((0 . 1) (2 . 2) (4 . 3)) (asc-sv (sparse-vector->alist h1))) ) ) ) (test-group "Reserve" (let ((h1 (make-sparse-vector #f 8)) (std (expt 10 7)) ) (test-assert (sparse-vector-reserve! h1 std)) (test '(39217 3 256) (receive (sparse-vector-info h1))) (test-assert (sparse-vector-reserve! h1 (* 2 std) std)) (test '(78434 4 256) (receive (sparse-vector-info h1))) ) ) ;;; (test-end "Sparse Vectors Extras") (test-exit)