#lang racket (provide display-measures-tests) (require rackunit rackunit/gui "../display-measures.rkt") (define (match regexp s) (not (null? (regexp-match regexp s)))) (define display-measures-tests (test-suite "Display Measures for Transfer Speeds" (test-case "bytes/sec->binary-rate-string* no exception for 0 input" (check-not-exn (lambda () (bytes/sec->binary-rate-string* 0 0)))) (test-case "bytes/sec->binary-rate-string* bounds" (for ([bounds (in-list '((0 1023 "B/s") (1024 1048575 "KB/s") (1048576 1073741823 "MB/s") (1073741824 1099511627775 "GB/s") (1099511627776 1125899906842623 "TB/s") (1125899906842624 1152921504606846975 "PB/s") (1152921504606846976 1180591620717411303423 "EB/s") (1180591620717411303424 1208925819614629174706175 "ZB/s")))]) (check-true (match (third bounds) (bytes/sec->binary-rate-string* (first bounds) 1))) (check-true (match (third bounds) (bytes/sec->binary-rate-string* (second bounds) 1))))) (test-case "bytes/sec->binary-rate-string* yota" (check-true (match "YB/s" (bytes/sec->binary-rate-string* 1208925819614629174706176 1)))) (test-case "bytes/sec->binary-rate-string no exception for 0 input" (check-not-exn (lambda () (bytes/sec->binary-rate-string 0 0)))) (test-case "bytes/sec->binary-rate-string bounds" (for ([bounds (in-list '((0 1023 "B/s") (1024 1048575 "KiB/s") (1048576 1073741823 "MiB/s") (1073741824 1099511627775 "GiB/s") (1099511627776 1125899906842623 "TiB/s") (1125899906842624 1152921504606846975 "PiB/s") (1152921504606846976 1180591620717411303423 "EiB/s") (1180591620717411303424 1208925819614629174706175 "ZiB/s")))]) (check-true (match (third bounds) (bytes/sec->binary-rate-string* (first bounds) 1))) (check-true (match (third bounds) (bytes/sec->binary-rate-string* (second bounds) 1))))) (test-case "bytes/sec->binary-rate-string* yota" (check-true (match "YiB/s" (bytes/sec->binary-rate-string* 1208925819614629174706176 1)))) (test-case "bits/sec->data-rate-string no exception for 0 input" (check-not-exn (lambda () (bits/sec->data-rate-string 0 0)))) (test-case "bits/sec->data-rate-string bounds" (for ([bounds (in-list '((0 999 "bit/s") (1000 1000000 "kbit/s") (1000000 1000000000 "Mbit/s") (1000000000 1000000000000 "Gbit/s")))]) (check-true (match (third bounds) (bits/sec->data-rate-string (first bounds) 1))) (check-true (match (third bounds) (bits/sec->data-rate-string (sub1 (second bounds)) 1))))) (test-case "bits/sec->data-rate-string yota" (check-true (match "Tbit/s" (bits/sec->data-rate-string 1000000000000 1)))) )) (define (test-all) (test/gui display-measures-tests #:wait? #t))