summaryrefslogtreecommitdiffstats
path: root/ex/2/47.rkt
blob: ee6e7b18cf60db4d01539d79945303bca8b6a485 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
;;;; License: CC0-1.0

#lang racket

(provide make-frame
         make-frame-alt
         origin-frame
         edge1-frame
         edge2-frame)

(require "46.rkt")


;;; frame functions

(define  (make-frame origin edge1 edge2)
  (list origin edge1 edge2))

(define (origin-frame frame)
  (car frame))

(define (edge1-frame frame)
  (car (cdr frame)))

(define (edge2-frame frame)
  (car (cdr (cdr frame))))


;;; alternative frame functions

(define (make-frame-alt origin edge1 edge2)
  (cons origin (cons edge1 edge2)))

(define (origin-frame-alt frame)
  (car frame))

(define (edge1-frame-alt frame)
  (car (cdr frame)))

(define (edge2-frame-alt frame)
  (cdr (cdr frame)))

;;; tests

(module+ tests
  (require rackunit)

  (define f1 (make-frame (make-vect 1 2) (make-vect 3 4) (make-vect 5 6)))
  (define f2 (make-frame-alt (make-vect 1 2) (make-vect 3 4) (make-vect 5 6)))

  ;; test selectors for make-frame
  (check-equal? (origin-frame f1) '(1 . 2))
  (check-equal? (edge1-frame f1)  '(3 . 4))
  (check-equal? (edge2-frame f1)  '(5 . 6))

  ;; test selectors for make-frame-alt
  (check-equal? (origin-frame-alt f2) '(1 . 2))
  (check-equal? (edge1-frame-alt f2)  '(3 . 4))
  (check-equal? (edge2-frame-alt f2)  '(5 . 6))
  "all tests ran")