;; ;; FILE: homework06-tests.rkt ;; AUTHOR: Eugene Wallingford ;; DATE: 2025/03/04 ;; COMMENT: This file loads "homework06.rkt" and runs tests on its ;; publicly-defined functions. I copied the tests from ;; the 2021/03/10 version of homework06-tests.rkt in the ;; 2023 Homework 6 solutions file. ;; ;; MODIFIED: ;; CHANGE: ;; #lang racket (require rackunit) (require "homework06.rkt") ;; -------------------------------------------------------------------------- ;; Problem 1 (structural recursion) ;; -------------------------------------------------------------------------- (check-equal? (list-index 'd '()) -1) (check-equal? (list-index 'a '(a c b e d f d)) 0) (check-equal? (list-index 'd '(a b c d e f d)) 3) (check-equal? (list-index 'g '(a b c d e f d)) -1) ;; -------------------------------------------------------------------------- ;; Problem 2 (structural recursion) ;; -------------------------------------------------------------------------- (check-equal? (tree-sum 8) 8) (check-equal? (tree-sum '(8 9 10)) 27) (check-equal? (tree-sum '(1 (2 3 4) 5)) 15) (check-equal? (tree-sum '(1 2 (3 4 5))) 15) (check-equal? (tree-sum '(8 (13 11 (5 24 6)) (15 (12 10 14) 20))) 138) ;; -------------------------------------------------------------------------- ;; Problem 3 (structural recursion) ;; -------------------------------------------------------------------------- (check-true (tree? '1)) (check-true (tree? '(8 (13 11 (5 24 6)) (15 (12 10 14) 20)))) (check-false (tree? 'x)) (check-false (tree? '(1 (2 3 4) (2 3 4 5)))) (check-false (tree? '(8 (13 x (5 24 6)) (15 (12 10 14) 20)))) ;; -------------------------------------------------------------------------- ;; Problem 4 (little language) ;; -------------------------------------------------------------------------- (check-false (unused-var? 'x 'x)) (check-false (unused-var? 'x 'y)) (check-false (unused-var? 'x '(x y))) (check-true (unused-var? 'x '(lambda (x) y))) (check-false (unused-var? 'x '(lambda (x) x))) (check-false (unused-var? 'x '(lambda (y) (lambda (x) x)))) (check-true (unused-var? 'y '(lambda (y) (lambda (x) x)))) (check-true (unused-var? 'x '(lambda (x) (lambda (x) x)))) (check-true (unused-var? 'y '(lambda (z) (lambda (y) (lambda (x) x))))) (check-false (unused-var? 'x '(a (lambda (z) (lambda (y) (lambda (x) x)))))) (check-true (unused-var? 'z '(z (lambda (z) (lambda (y) (lambda (x) x)))))) ;; --------------------------------------------------------------------------