New structure groups all ADT modules under adt/ directory, removing redundant adt- prefix from filenames. Library names now read as (pacman-project adt position) etc. All imports updated accordingly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 lines
1.8 KiB
Racket
56 lines
1.8 KiB
Racket
#lang r7rs
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;; Tests: Timer ADT ;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(define-library (pacman-project tests test-timer)
|
|
(import (scheme base)
|
|
(pp1 tests)
|
|
(pacman-project adt timer))
|
|
(export test)
|
|
|
|
(begin
|
|
|
|
;; Test initial time
|
|
(define (test-initial)
|
|
(define t (make-timer))
|
|
(check-eq? (t 'remaining-time) 60 "Initial time should be 60 seconds")
|
|
(check (not ((t 'time-up?))) "Time should not be up at start"))
|
|
|
|
;; Test decrease after 1 second
|
|
(define (test-decrease)
|
|
(define t (make-timer))
|
|
((t 'decrease!) 1000)
|
|
(check-eq? (t 'remaining-time) 59 "Time should be 59 after 1 second"))
|
|
|
|
;; Test increase (coin bonus)
|
|
(define (test-increase)
|
|
(define t (make-timer))
|
|
((t 'decrease!) 1000)
|
|
((t 'increase!))
|
|
(check-eq? (t 'remaining-time) 60 "Time should be 60 after decrease + increase"))
|
|
|
|
;; Test format-time
|
|
(define (test-format)
|
|
(define t (make-timer))
|
|
(check-eq? ((t 'format-time)) "1:00" "60 seconds = 1:00")
|
|
((t 'decrease!) 1000)
|
|
(check-eq? ((t 'format-time)) "0:59" "59 seconds = 0:59"))
|
|
|
|
;; Test time-up?
|
|
(define (test-time-up)
|
|
(define t (make-timer))
|
|
;; Decrease 60 times by 1 second
|
|
(do ((i 0 (+ i 1)))
|
|
((= i 60))
|
|
((t 'decrease!) 1000))
|
|
(check ((t 'time-up?)) "Time should be up after 60 seconds"))
|
|
|
|
(define (test)
|
|
(run-test test-initial "Timer: initial time")
|
|
(run-test test-decrease "Timer: decrease")
|
|
(run-test test-increase "Timer: increase")
|
|
(run-test test-format "Timer: format-time")
|
|
(run-test test-time-up "Timer: time-up?"))))
|