#lang r7rs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Tests: Maze ADT ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-library (pacman-project tests test-maze) (import (scheme base) (pp1 tests) (pacman-project constants) (pacman-project adt maze)) (export test) (begin ;; Test dimensions (define (test-dimensions) (define m (make-maze)) (check-eq? (m 'rows) 31 "Maze should have 31 rows") (check-eq? (m 'cols) 28 "Maze should have 28 cols")) ;; Test wall detection (row 0 is all walls) (define (test-wall) (define m (make-maze)) (check ((m 'wall?) 0 0) "Cell (0,0) should be a wall") (check ((m 'wall?) 0 14) "Cell (0,14) should be a wall")) ;; Test coin detection (define (test-coin) (define m (make-maze)) (check ((m 'coin?) 1 1) "Cell (1,1) should be a coin") (check (not ((m 'coin?) 0 0)) "Cell (0,0) should not be a coin")) ;; Test door detection (define (test-door) (define m (make-maze)) (check ((m 'door?) 4 3) "Cell (4,3) should be a door") (check (not ((m 'door?) 1 1)) "Cell (1,1) should not be a door")) ;; Test cell-set! and remove-door! (define (test-mutation) (define m (make-maze)) ((m 'remove-door!) 4 3) (check ((m 'empty?) 4 3) "Cell (4,3) should be empty after remove-door!") (check (not ((m 'door?) 4 3)) "Cell (4,3) should no longer be a door")) ;; Test that wall blocks movement (define (test-wall-blocks) (define m (make-maze)) (check ((m 'wall?) 1 0) "Cell (1,0) is a wall, Pac-Man cannot pass")) (define (test) (run-test test-dimensions "Maze: dimensions") (run-test test-wall "Maze: wall detection") (run-test test-coin "Maze: coin detection") (run-test test-door "Maze: door detection") (run-test test-mutation "Maze: cell mutation") (run-test test-wall-blocks "Maze: wall blocks movement"))))