#lang r7rs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Tests: Pac-Man ADT ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-library (pacman-project tests test-pacman) (import (scheme base) (pp1 tests) (pacman-project adt position) (pacman-project adt pacman)) (export test) (begin ;; Test creation and start position (define (test-creation) (define pac (make-pacman 5 2)) (define pos (pac 'position)) (check-eq? (pos 'row) 5 "Start row should be 5") (check-eq? (pos 'col) 2 "Start col should be 2")) ;; Test direction (define (test-direction) (define pac (make-pacman 5 2)) (check-eq? (pac 'direction) 'right "Start direction should be right") ((pac 'direction!) 'left) (check-eq? (pac 'direction) 'left "Direction should be left after direction!")) ;; Test move! (define (test-move) (define pac (make-pacman 5 2)) ((pac 'move!) 0 1) (define pos (pac 'position)) (check-eq? (pos 'col) 3 "Col should be 3 after 1 step right") (check-eq? (pos 'row) 5 "Row unchanged after horizontal move")) ;; Test multiple moves (define (test-multiple-moves) (define pac (make-pacman 5 5)) ((pac 'move!) -1 0) ((pac 'move!) 0 1) (define pos (pac 'position)) (check-eq? (pos 'row) 4 "Row should be 4 after up") (check-eq? (pos 'col) 6 "Col should be 6 after right")) (define (test) (run-test test-creation "Pac-Man: creation and start position") (run-test test-direction "Pac-Man: direction") (run-test test-move "Pac-Man: move!") (run-test test-multiple-moves "Pac-Man: multiple moves"))))