;;;; srfi-174-srfi-19-test.scm -*- Scheme -*- ;;;; Kon Lovett, Aug '23 ;;;; ;;;; (from SRFI 174 sample implementation srfi-174-chibi-tests.scm) (import (scheme base)) (import test) (import (srfi-174 srfi-19)) (define ts1 (timespec 1 2)) (define ts2 (timespec 1 2)) (define ts3 (timespec 1 3)) (define ts4 (timespec 2 2)) (define ts-neg1 (timespec -1 2)) (define ts-neg2 (timespec -1 5)) (define ts-neg3 (timespec -2 0)) (test-group "srfi-174" (test-assert "timespec?" (timespec? ts1)) (test-assert "not timespec?" (not (timespec? #f))) (test "seconds" 1 (timespec-seconds ts1)) (test "nanos" 2 (timespec-nanoseconds ts1)) (test-assert "equal" (timespec=? ts1 ts2)) (test-assert "less nanos" (timespecinexact (timespec 1 #e1e8))) (let ((t (timespec 1 1)) (u (inexact->timespec #i1.000000001))) (test "from inexact" t u)) ) (import srfi-19-time) (import (only (chicken port) with-output-to-string)) (test-group "srfi-174 Extensions" (define ts1 (timespec 1 2)) (let ((t1 (timespec->time ts1))) (test-assert "timespec->time" t1) (test "timespec->time second" (timespec-seconds ts1) (time-second t1)) (test "timespec->time nanosecond" (timespec-nanoseconds ts1) (time-nanosecond t1)) ;check a copy (set-time-second! t1 -1) (test "timespec->time is a copy" (timespec-seconds ts1) (time-second (timespec->time ts1))) ) (test "timespec-print" "#" (with-output-to-string (cut timespec-print ts1))) ) (test-exit)