Files
Pacman-Project/pacman-project/tests/test-pacman.rkt
joren caac996acd Refactor(Structure): Move ADTs into adt/ folder, rename spel.rkt to main.rkt
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>
2026-03-23 11:11:08 +01:00

52 lines
1.8 KiB
Racket

#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"))))