#lang r7rs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Tests: Position ADT ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-library (pacman-project tests test-position) (import (scheme base) (pp1 tests) (pacman-project adt-position)) (export test) (begin ;; Test creation and getters (define (test-creation) (define pos (make-position 5 10)) (check-eq? (pos 'row) 5 "Row should be 5") (check-eq? (pos 'col) 10 "Col should be 10")) ;; Test mutators (define (test-mutators) (define pos (make-position 0 0)) ((pos 'row!) 3) ((pos 'col!) 7) (check-eq? (pos 'row) 3 "Row should be 3 after row!") (check-eq? (pos 'col) 7 "Col should be 7 after col!")) ;; Test equal? (define (test-equal) (define p1 (make-position 5 10)) (define p2 (make-position 5 10)) (define p3 (make-position 5 11)) (check ((p1 'equal?) p2) "Equal positions should match") (check (not ((p1 'equal?) p3)) "Different positions should not match")) ;; Test move (define (test-move) (define pos (make-position 5 10)) (define new-pos ((pos 'move) -1 0)) (check-eq? (new-pos 'row) 4 "Row should be 4 after move up") (check-eq? (new-pos 'col) 10 "Col unchanged after move up") ;; Original position must not change (check-eq? (pos 'row) 5 "Original row must not change")) ;; Test that two objects are not eq? (define (test-identity) (define p1 (make-position 1 1)) (define p2 (make-position 1 1)) (check (not (eq? p1 p2)) "Two position objects must not be eq?")) (define (test) (run-test test-creation "Position: creation and getters") (run-test test-mutators "Position: mutators") (run-test test-equal "Position: equal?") (run-test test-move "Position: move") (run-test test-identity "Position: identity"))))