(module date-test mzscheme (require (planet "test.ss" ("schematics" "schemeunit.plt" 2 0)) (file "date.ss") ) (provide date-tests ) (define test-timestamp (current-seconds)) (define date-tests (test-suite "All tests for date" (test-case "leap-year? : 2001 is not a leap year" (check equal? (leap-year? 2001) #f)) (test-case "leap-year? : 2004 is a leap year" (check equal? (leap-year? 2004) #t)) (test-case "leap-year? : 2000 is a leap year" (check equal? (leap-year? 2000) #t)) (test-case "leap-year? : 1900 is not a leap year" (check equal? (leap-year? 1900) #f)) (test-case "timestamp->ago-string works with an order of magnitude of seconds" (check-equal? (timestamp->ago-string test-timestamp test-timestamp) "0 seconds ago") (check-equal? (timestamp->ago-string (- test-timestamp 1) test-timestamp) "1 second ago") (check-equal? (timestamp->ago-string (- test-timestamp 59) test-timestamp) "59 seconds ago")) (test-case "timestamp->ago-string works with an order of magnitude of minutes" (check-equal? (timestamp->ago-string (- test-timestamp 60) test-timestamp) "1 minute ago") (check-equal? (timestamp->ago-string (- test-timestamp 3599) test-timestamp) "59 minutes ago")) (test-case "timestamp->ago-string works with an order of magnitude of hours" (check-equal? (timestamp->ago-string (- test-timestamp 3600) test-timestamp) "1 hour ago") (check-equal? (timestamp->ago-string (- test-timestamp 86399) test-timestamp) "23 hours ago")) (test-case "timestamp->ago-string works with an order of magnitude of days" (check-equal? (timestamp->ago-string (- test-timestamp 86400) test-timestamp) "yesterday") (check-equal? (timestamp->ago-string (- test-timestamp 172800) test-timestamp) "2 days ago")) )) )