(use byte-blob test posix srfi-4) (define a (byte-blob-cons 1 (byte-blob-cons 2 (byte-blob-empty)))) (define b (byte-blob-cons 3 (byte-blob-cons 4 (byte-blob-empty)))) (define c (list->byte-blob (list 7 8 9))) (define d (byte-blob-replicate 10 6)) (test-group "byte-blob test" (test (sprintf "f32vector <-> byte-blob") (f32vector 1.02 3.04 5.06) (byte-blob->f32vector (f32vector->byte-blob (f32vector 1.02 3.04 5.06)))) (test (sprintf "byte-blob-replicate") '(6 6 6 6 6 6 6 6 6 6) (byte-blob->list d)) (test (sprintf "byte-blob-cons" ) '(1 2) (byte-blob->list a)) (test (sprintf "byte-blob-car" ) 1 (byte-blob-car a)) (test (sprintf "byte-blob-cdr" ) '(2) (byte-blob->list (byte-blob-cdr a))) (test (sprintf "byte-blob-ref" ) 1 (byte-blob-ref (byte-blob-cons 5 a) 1)) (test (sprintf "byte-blob-append" ) '(1 2 3 4 7 8 9) (byte-blob->list (byte-blob-append a b c))) (test (sprintf "byte-blob-take" ) '(1 2 ) (byte-blob->list (byte-blob-take (byte-blob-append a b c) 2))) (test (sprintf "byte-blob-drop" ) '(3 4 7 8 9) (byte-blob->list (byte-blob-drop (byte-blob-append a b c) 2))) (test (sprintf "byte-blob-span" ) '(3 4 7) (byte-blob->list (byte-blob-span (byte-blob-append a b c) 2 5))) (test (sprintf "byte-blob-map" ) '(10 2 4 6 8) (byte-blob->list (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-append a b))))) (test (sprintf "byte-blob-reverse" ) '(10 8 6 4 2) (byte-blob->list (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))))) (test (sprintf "byte-blob-intersperse" ) '(10 9 8 9 6 9 4 9 2) (byte-blob->list (byte-blob-intersperse (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))) 9))) (test (sprintf "byte-blob-find" ) '((10) (((9 8) (9 8 9 6 9 4 9 2)) ((9 6) (9 6 9 4 9 2)) ((9 4) (9 4 9 2)) ((9 2) (9 2)))) (let ((r (byte-blob-find (list->byte-blob (list 9)) (byte-blob-intersperse (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))) 9)))) (list (byte-blob->list (car r)) (map (lambda (x) (map byte-blob->list x)) (cadr r))))) (test (sprintf "byte-blob-find" ) '((10 9 8) (((9 6 9 4 9 2) (9 6 9 4 9 2)))) (let ((r (byte-blob-find (list->byte-blob (list 9 6)) (byte-blob-intersperse (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))) 9)))) (list (byte-blob->list (car r)) (map (lambda (x) (map byte-blob->list x)) (cadr r))))) (test (sprintf "byte-blob-fold-left" ) 66 (byte-blob-fold-left + 0 (byte-blob-intersperse (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))) 9))) (test (sprintf "byte-blob-fold-right" ) -6 (byte-blob-fold-left - 0 (byte-blob-intersperse (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))) 9))) (let* ((out-port+path (let-values (((fd temp-path) (file-mkstemp "/tmp/byte-blob-test.XXXXXX"))) (let ((temp-port (open-output-file* fd))) (cons temp-port temp-path)))) (out-port (car out-port+path)) (temp-path (cdr out-port+path))) (test-assert (sprintf "byte-blob-write" ) (byte-blob-write out-port (byte-blob-intersperse (byte-blob-map (lambda (x) (* 2 x)) (byte-blob-cons 5 (byte-blob-reverse (byte-blob-append a b)))) 9))) (close-output-port out-port) (let ((in-port (open-input-file temp-path))) (test (sprintf "byte-blob-read" ) '(10 9 8 9 6 9 4 9 2) (byte-blob->list (byte-blob-read in-port 9 ))) (close-input-port in-port)) ) )