;; file: test-setup.rkt ;; author: Robert Keller ;; purpose: illustrating unit tests #lang racket (require htdp/testing) ; incant to get check-expect, check-within, generate-report ; The format for check-expect is (check-expect ) (check-expect (+ 2 2) 4) ;; ok (check-expect (+ 2 3) 6) ;; should fail intentionally ; (check-expect (+ 1 .5) 1.5) ;; Not allowed because .5 is "inexact" due to floating pt. ; The format for check-within is (check-within ) (check-within (+ 1 .5) 1.5 0) ;; ok (check-within (+ 1/3 0.5) 0.833 0) ;; should fail because of no tolerance (check-within (+ 1/3 0.5) 0.833 1e-4) ;; should fail because of too little tolerance (check-within (+ 1/3 0.5) 0.833 1e-3) ;; ok (generate-report) ;Output (I added line breaks between cases.): ; ;Ran 6 checks. ;3 of the 6 checks failed. ; ; Actual value 5 differs from 6, the expected value. ; In test-setup.rkt at line 6 column 0 ; ; Actual value 0.8333333333333333 is not within 0 of expected value 0.833. ; In test-setup.rkt at line 11 column 0 ; ; Actual value 0.8333333333333333 is not within 0.0001 of expected value 0.833. ; In test-setup.rkt at line 12 column 0