#lang racket (module+ test (require rackunit)) (define (add a b) (+ a b)) (module+ test (check-equal? (add 1 2) 3)) (define (my-even? n) (cond [(negative? n) (my-even? (- n))] [(zero? n) #t] [(= n 1) #f] [else (my-even? (- n 2))])) (module+ test (check-equal? (my-even? -1) #f) (check-equal? (my-even? 13) #f) (check-equal? (my-even? 18) #t)) (define (copy-str n str) (cond [(zero? n) ""] [else (string-append str (copy-str (sub1 n) str))])) (module+ test (check-equal? (copy-str 3 "abc") "abcabcabc") (check-equal? (copy-str 4 "ab") "abababab")) (define (copy-str-tr n str [acc ""]) (cond [(zero? n) acc] [else (copy-str-tr (sub1 n) str (string-append str acc))])) (module+ test (check-equal? (copy-str-tr 3 "abc") "abcabcabc") (check-equal? (copy-str-tr 4 "ab") "abababab")) (define (char+1 c) (integer->char (add1 (char->integer c)))) (define (char-1 c) (integer->char (sub1 (char->integer c)))) (define (consecutive-chars fst lst) (cond [(char=? fst lst) (string fst)] [(char? fst lst) (string-append (string fst) (consecutive-chars (char-1 fst) lst))])) (module+ test (check-equal? (consecutive-chars #\A #\D) "ABCD") (check-equal? (consecutive-chars #\z #\u) "zyxwvu"))