tests.rkt
#lang racket

(require rackunit
         "main.rkt")

;; check that uncompress(compress(b)) = b
(let ([test-bytes #"otoh ethon tohesunt osn.t soc  so thson.th "])
  (check-equal? (uncompress-bytes (compress-bytes test-bytes)
                                  (bytes-length test-bytes))
                test-bytes))

;; compress two separate byte-strings to a temp file
(define temp-file (make-temporary-file))
(define out (open-output-gz-file temp-file #:replace #t))
(define first-part #"12aothe3")
(define second-part #"342321")
(check-equal? (write-bytes first-part out)
              (bytes-length first-part))
(check-equal? (write-bytes second-part out)
              (bytes-length second-part))
(close-output-port out)

;; read the byte-string from the file
(define in (open-input-gz-file temp-file))
(define expected-out (bytes-append first-part second-part))
(check-equal? (read-bytes (bytes-length expected-out) in) expected-out)
(close-input-port in)

;; do it again using read-gz-file
(check-equal? (read-gz-file temp-file)
              expected-out)

(delete-file temp-file)