Skip to content

Commit d95d4a5

Browse files
committed
unit tests + small fixes
1 parent 4b8f3ae commit d95d4a5

File tree

5 files changed

+88
-5
lines changed

5 files changed

+88
-5
lines changed

plot-gui-lib/plot/private/gui/snip2d.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@
389389
(define/public (get-plot-bounds) (unless plot-metrics-ok? (update-metrics)) (bounds))
390390
(define/public (plot->dc coords) (unless plot-metrics-ok? (update-metrics)) (->dc coords))
391391
(define/public (dc->plot coords) (unless plot-metrics-ok? (update-metrics)) (->plot coords))
392-
(define/public (plane-vector coords) (unless plot-metrics-ok? (update-metrics)) (plane))
392+
(define/public (plane-vector) (unless plot-metrics-ok? (update-metrics)) (plane))
393393
(define/public (get-plot-metrics-functions) (unless plot-metrics-ok? (update-metrics)) (list bounds ->dc ->plot plane))
394394
))
395395

plot-gui-lib/plot/private/gui/snip3d.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
(define/public (get-plot-bounds) (unless plot-metrics-ok? (update-metrics)) (bounds))
158158
(define/public (plot->dc coords) (unless plot-metrics-ok? (update-metrics)) (->dc coords))
159159
(define/public (dc->plot coords) (unless plot-metrics-ok? (update-metrics)) (->plot coords))
160-
(define/public (plane-vector coords) (unless plot-metrics-ok? (update-metrics)) (plane))
160+
(define/public (plane-vector) (unless plot-metrics-ok? (update-metrics)) (plane))
161161
(define/public (get-plot-metrics-functions) (unless plot-metrics-ok? (update-metrics)) (list bounds ->dc ->plot plane))
162162
))
163163

plot-lib/plot/private/common/plotmetrics.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
get-plot-metrics-functions))
1919

2020
(define plot-metrics-object/c
21-
(object/c [get-plot-bounds (->m (-> (vectorof (vector/c real? real?))))]
21+
(object/c [get-plot-bounds (->m (vectorof (vector/c real? real?)))]
2222
[plot->dc (->m (vectorof real?) (vectorof real?))]
2323
[dc->plot (->m (vectorof real?) (vectorof real?))]
2424
[plane-vector (->m (vectorof real?))]

plot-lib/plot/private/plot3d/plot-area.rkt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,12 +1635,14 @@
16351635

16361636
(define/public (get-plot-metrics-functions)
16371637
(list (let ([bounds bounds-rect]
1638-
[vect : (Option (Immutable-Vector (Immutable-Vector Real Real) (Immutable-Vector Real Real))) #f])
1638+
[vect : (Option (Immutable-Vector (Immutable-Vector Real Real) (Immutable-Vector Real Real) (Immutable-Vector Real Real))) #f])
16391639
(λ () (or vect
16401640
(let ([new (vector-immutable (vector-immutable (assert (ivl-min (vector-ref bounds 0)) real?)
16411641
(assert (ivl-max (vector-ref bounds 0)) real?))
16421642
(vector-immutable (assert (ivl-min (vector-ref bounds 1)) real?)
1643-
(assert (ivl-max (vector-ref bounds 1)) real?)))])
1643+
(assert (ivl-max (vector-ref bounds 1)) real?))
1644+
(vector-immutable (assert (ivl-min (vector-ref bounds 2)) real?)
1645+
(assert (ivl-max (vector-ref bounds 2)) real?)))])
16441646
(set! vect new)
16451647
new))))
16461648
plot->dc

plot-test/plot/tests/PRs/90.rkt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#lang racket
2+
(require rackunit
3+
racket/draw pict (only-in racket/gui/base sleep/yield)
4+
plot (submod plot/private/common/plotmetrics untyped))
5+
6+
; tests for PR#90, https://github.com/racket/plot/pull/90
7+
; "Plotmetrics: access/calculate data about the plot area"
8+
9+
10+
(define pr90-test-suite
11+
(make-test-suite
12+
"PR#90: plotmetrics"
13+
(append
14+
(let* ([bm (make-object bitmap% 400 400)]
15+
[dc (make-object bitmap-dc% bm)]
16+
[pm (plot/dc (polar (λ (x) x)) dc 0 0 400 400)])
17+
(list (test-suite "PR90: plot-metrics get-plot-bounds"
18+
(check-within (send pm get-plot-bounds)
19+
#(#(-3.2883704095701205 6.283185307179586)
20+
#(-4.8144539337330965 1.81970262809755))
21+
1e-15))
22+
(test-suite "PR90: plot-metrics plot->dc & dc->plot"
23+
(check-within (send pm dc->plot (send pm plot->dc #(0 0)))
24+
#(0 0) 1e-15))
25+
(test-suite "PR90: plot-metrics plane-vector"
26+
(check-equal? (send pm plane-vector)
27+
#(0 0 1)))))
28+
29+
(let ([pmbm (plot3d-bitmap (polar3d (λ (ϕ θ) ϕ)))])
30+
(list (test-suite "PR90: bitmap" (check-true (is-a? pmbm bitmap%)))
31+
(test-suite "PR90: 3d/bitmap get-plot-bounds"
32+
(check-within (send pmbm get-plot-bounds)
33+
#(#(-3.287703432872698 6.282003882664296)
34+
#(-4.812750657123522 1.819088586099858)
35+
#(-6.283185307179587 6.283185307179587))
36+
1e-15))
37+
(test-suite "PR90: 3d/bitmap plot->dc & dc->plot"
38+
(check-within (send pmbm plot->dc (send pmbm dc->plot #(200 200)))
39+
#(200 200) 1e-15))
40+
(test-suite "PR90: 3d/bitmap plane-vector"
41+
(check-equal? (send pmbm plot->dc (send pmbm plane-vector))
42+
(send pmbm plot->dc #(0 0 0))))))
43+
44+
(let ([pp (plot-pict (function (λ (x) x) 1 2))])
45+
(list (test-suite "PR90: plot-pict" (check-true (and (plot-pict? pp) (pict? pp))))
46+
(test-suite "PR90: plot-pict get-plot-bounds"
47+
(check-equal? (plot-pict-bounds pp)
48+
#(#(1 2) #(1 2))))
49+
(test-suite "PR90: plot-pict plot->dc & dc->plot"
50+
(check-within ((plot-pict-dc->plot pp) ((plot-pict-plot->dc pp) #(0 0)))
51+
#(0 0) 1e-15))
52+
(test-suite "PR90: plot-pict plane-vector"
53+
(check-equal? (plot-pict-plane-vector pp)
54+
#(0 0 1)))))
55+
56+
(let* ([ps (plot3d-snip (surface3d (λ (x y) (+ x y)) 0 1 1 2))]
57+
[plotcoords #(1 1 1)]
58+
[coords (send ps plot->dc plotcoords)])
59+
(list (test-suite "PR90: 3d/snip" (check-true (is-a? ps plot-metrics<%>)))
60+
(test-suite "PR90: 3d/snip get-plot-bounds"
61+
(check-equal? (send ps get-plot-bounds)
62+
#(#(0 1) #(1 2) #(1 3))))
63+
(test-suite "PR90: 3d/snip plot->dc & dc->plot"
64+
(check-within (send ps plot->dc (send ps dc->plot #(200 200)))
65+
#(200 200) 1e-15))
66+
(test-suite "PR90: 3d/snip plane-vector"
67+
(check-equal? (send ps plot->dc (send ps plane-vector))
68+
(send ps plot->dc #(0 0 0))))
69+
(test-suite "PR90: 3d/snip before resize"
70+
(check-equal? (send ps plot->dc plotcoords) coords))
71+
(test-suite "PR90: 3d/snip after resize"
72+
(send ps resize 800 800)
73+
(sleep/yield .1)
74+
(check-within (send ps plot->dc (send ps dc->plot #(200 200)))
75+
#(200 200) 5e-14)
76+
(check-not-equal? (send ps plot->dc plotcoords) coords)))))
77+
))
78+
79+
(module+ test
80+
(require rackunit/text-ui)
81+
(run-tests pr90-test-suite))

0 commit comments

Comments
 (0)