benchmark-log-test.ss
#lang scheme/base
  
(require (planet schematics/schemeunit:3)
         "benchmark-log.ss")
  
(provide benchmark-log-tests)

(define test-log "test.log")

(define (delete-test-log)
  (when (file-exists? test-log)
    (delete-file test-log)))
  
(define benchmark-log-tests
  (test-suite
   "All tests for benchmark-log"

   (test-case
    "read-benchmark-log creates files that don't exist"
    (after
     (check-false (file-exists? test-log))
     (check-pred null? (read-benchmark-log test-log))
     (check-true (file-exists? test-log))
     (delete-test-log)))
     
   (test-case
    "Added data is read back"
    (after
     (check-false (file-exists? test-log))
     (add-run test-log "test" (vector 1 1 1))
     (check-equal?
      (read-benchmark-log test-log)
      `(#("test" "" ,(current-seconds) #(1 1 1) 1.0 0.0)))
     (delete-test-log)))

   (test-case
    "find-most-recent-run finds correct data"
    (after
     (add-run test-log "test" (vector 1 1 1))
     (add-run test-log "foo" (vector 1 2))
     (add-run test-log "test" (vector 3 3 3))
     (add-run test-log "bar" (vector 2 1))
     (check-equal?
      (find-most-recent-run test-log "test")
      `#("test" "" ,(current-seconds) #(3 3 3) 3.0 0.0))
     (delete-test-log)))

   (test-case
    "find-most-recent-run returns #f when no match"
    (after
     (add-run test-log "test" (vector 1 1 1))
     (add-run test-log "foo" (vector 1 2))
     (add-run test-log "test" (vector 3 3 3))
     (add-run test-log "bar" (vector 2 1))
     (check-false (find-most-recent-run test-log "baz"))
     (delete-test-log)))
     
   ))