clean up redex bitmap tests (under mac os x)

This commit is contained in:
Robby Findler 2012-03-05 08:52:17 -06:00
parent 4a304643d3
commit 3997eaefde
38 changed files with 82 additions and 69 deletions

View File

@ -5,6 +5,7 @@
racket/gui/base racket/gui/base
(for-syntax racket/base) (for-syntax racket/base)
racket/class racket/class
racket/promise
"../pict.rkt" "../pict.rkt"
"../reduction-semantics.rkt") "../reduction-semantics.rkt")
@ -35,24 +36,23 @@
(build-path bmps-dir (build-path bmps-dir
raw-bitmap-filename)] raw-bitmap-filename)]
[old-bitmap (if (file-exists? bitmap-filename) [old-bitmap (if (file-exists? bitmap-filename)
(make-object bitmap% bitmap-filename) (read-bitmap bitmap-filename)
(let* ([bm (make-object bitmap% 100 20)] (let* ([bm (make-screen-bitmap 100 20)]
[bdc (make-object bitmap-dc% bm)]) [bdc (make-object bitmap-dc% bm)])
(send bdc clear) (send bdc clear)
(send bdc draw-text "does not exist" 0 0) (send bdc draw-text "does not exist" 0 0)
(send bdc set-bitmap #f) (send bdc set-bitmap #f)
bm))] bm))]
[new-bitmap (make-object bitmap% [new-bitmap (make-screen-bitmap
(ceiling (inexact->exact (pict-width pict))) (ceiling (inexact->exact (pict-width pict)))
(ceiling (inexact->exact (pict-height pict))))] (ceiling (inexact->exact (pict-height pict))))]
[bdc (make-object bitmap-dc% new-bitmap)]) [bdc (make-object bitmap-dc% new-bitmap)])
(send bdc clear) (send bdc clear)
(draw-pict pict bdc 0 0) (draw-pict pict bdc 0 0)
(send bdc set-bitmap #f) (send bdc set-bitmap #f)
(let ([diff-bitmap (compute-diffs old-bitmap new-bitmap)]) (unless (bitmaps-same? old-bitmap new-bitmap)
(when diff-bitmap (let ([failed-panel (make-failed-panel line-number bitmap-filename old-bitmap new-bitmap)])
(let ([failed-panel (make-failed-panel line-number bitmap-filename old-bitmap new-bitmap diff-bitmap)]) (set! failed (append failed (list failed-panel)))))))
(set! failed (append failed (list failed-panel))))))))
(define (set-fonts/call thunk) (define (set-fonts/call thunk)
(case (system-type) (case (system-type)
@ -80,49 +80,57 @@
(unless (member face (get-face-list)) (unless (member face (get-face-list))
(error 'verify-face "unknown face: ~s" face)) (error 'verify-face "unknown face: ~s" face))
face) face)
(define (bitmaps-same? old-bitmap new-bitmap)
(let ([w (send old-bitmap get-width)]
[h (send old-bitmap get-height)])
(and (= w (send new-bitmap get-width))
(= h (send new-bitmap get-height))
(let ([bytes1 (make-bytes (* w h 4))]
[bytes2 (make-bytes (* w h 4))])
(send old-bitmap get-argb-pixels 0 0 w h bytes1)
(send new-bitmap get-argb-pixels 0 0 w h bytes2)
(equal? bytes1 bytes2)))))
(define (compute-diffs old-bitmap new-bitmap) (define (compute-diffs old-bitmap new-bitmap)
(let* ([w (max (send old-bitmap get-width) (let* ([w (max (send old-bitmap get-width)
(send new-bitmap get-width))] (send new-bitmap get-width))]
[h (max (send old-bitmap get-height) [h (max (send old-bitmap get-height)
(send new-bitmap get-height))] (send new-bitmap get-height))]
[diff-bitmap (make-object bitmap% w h)] [diff-bitmap (make-bitmap w h)] ;; this bitmap holds the diff only, that we compute via set-pixel, not drawing
[new (make-object bitmap-dc% new-bitmap)] [new (make-object bitmap-dc% new-bitmap)]
[old (make-object bitmap-dc% old-bitmap)] [old (make-object bitmap-dc% old-bitmap)]
[diff (make-object bitmap-dc% diff-bitmap)] [diff (make-object bitmap-dc% diff-bitmap)]
[new-c (make-object color%)] [new-c (make-object color%)]
[old-c (make-object color%)] [old-c (make-object color%)])
[any-different? #f]) (let loop ([x 0])
(let loop ([x 0]) (unless (= x w)
(unless (= x w) (let loop ([y 0])
(let loop ([y 0]) (unless (= y h)
(unless (= y h) (cond
(cond [(and (< x (send new-bitmap get-width))
[(and (< x (send new-bitmap get-width)) (< y (send new-bitmap get-height))
(< y (send new-bitmap get-height)) (< x (send old-bitmap get-width))
(< x (send old-bitmap get-width)) (< y (send old-bitmap get-height)))
(< y (send old-bitmap get-height))) (send new get-pixel x y new-c)
(send new get-pixel x y new-c) (send old get-pixel x y old-c)
(send old get-pixel x y old-c) (cond
(cond [(and (= (send new-c red) (send old-c red))
[(and (= (send new-c red) (send old-c red)) (= (send new-c green) (send old-c green))
(= (send new-c green) (send old-c green)) (= (send new-c blue) (send old-c blue)))
(= (send new-c blue) (send old-c blue))) (send diff set-pixel x y new-c)]
(send diff set-pixel x y new-c)] [else
[else (send new-c set 255 0 0)
(set! any-different? #t) (send diff set-pixel x y new-c)])]
(send new-c set 255 0 0) [else
(send diff set-pixel x y new-c)])] (send new-c set 255 0 0)
[else (send diff set-pixel x y new-c)])
(set! any-different? #t) (loop (+ y 1))))
(send new-c set 255 0 0) (loop (+ x 1))))
(send diff set-pixel x y new-c)]) (send diff set-bitmap #f)
(loop (+ y 1)))) (send old set-bitmap #f)
(loop (+ x 1)))) (send new set-bitmap #f)
(send diff set-bitmap #f) diff-bitmap))
(send old set-bitmap #f)
(send new set-bitmap #f)
(and any-different? diff-bitmap)))
(define test-result-single-panel #f) (define test-result-single-panel #f)
(define (get-test-result-single-panel) (define (get-test-result-single-panel)
@ -135,7 +143,7 @@
(define lined (new vertical-panel% [parent f] [style '(border)])) (define lined (new vertical-panel% [parent f] [style '(border)]))
(define sp (new panel:single% [parent lined])) (define sp (new panel:single% [parent lined]))
(define current-index 0) (define current-index 0)
(define hp (new horizontal-panel% [parent f])) (define hp (new horizontal-panel% [parent f] [alignment '(center center)]))
(define prev (define prev
(new button% (new button%
[label "Prev"] [label "Prev"]
@ -157,7 +165,8 @@
(send f show #t) (send f show #t)
sp)])) sp)]))
(define (make-failed-panel line-number filename old-bitmap new-bitmap diff-bitmap) (define (make-failed-panel line-number filename old-bitmap new-bitmap)
(define diff-bitmap (delay (compute-diffs old-bitmap new-bitmap)))
(define f (new vertical-panel% [parent (get-test-result-single-panel)])) (define f (new vertical-panel% [parent (get-test-result-single-panel)]))
(define msg (new message% [label (format "line ~a" line-number)] [parent f])) (define msg (new message% [label (format "line ~a" line-number)] [parent f]))
(define hp (new horizontal-panel% [parent f])) (define hp (new horizontal-panel% [parent f]))
@ -170,7 +179,7 @@
(λ (_1 _2) (λ (_1 _2)
(cond (cond
[(send chk get-value) [(send chk get-value)
(send right-hand set-label diff-bitmap)] (send right-hand set-label (force diff-bitmap))]
[else [else
(send right-hand set-label new-bitmap)]))])) (send right-hand set-label new-bitmap)]))]))
(define btn (new button% (define btn (new button%
@ -182,11 +191,11 @@
(define left-label (new message% [parent vp1] [label "Old"])) (define left-label (new message% [parent vp1] [label "Old"]))
(define left-hand (new message% (define left-hand (new message%
[parent vp1] [parent vp1]
[label diff-bitmap])) [label old-bitmap]))
(define right-label (new message% [parent vp2] [label "New"])) (define right-label (new message% [parent vp2] [label "New"]))
(define right-hand (new message% (define right-hand (new message%
[parent vp2] [parent vp2]
[label diff-bitmap])) [label new-bitmap]))
(send left-hand set-label old-bitmap) (send left-hand set-label old-bitmap)
(send right-hand set-label new-bitmap) (send right-hand set-label new-bitmap)
f) f)

View File

@ -1,6 +1,7 @@
#lang scheme #lang racket
(require "bitmap-test-util.rkt" (require "bitmap-test-util.rkt"
"../main.rkt") "../main.rkt"
slideshow/pict)
;; tests: ;; tests:
;; - language, ;; - language,
@ -293,14 +294,6 @@
[(sum (s n_1) n_2 (s n_3)) [(sum (s n_1) n_2 (s n_3))
(sum n_1 n_2 n_3)]) (sum n_1 n_2 n_3)])
(test (render-judgment-form sum) "judgment-form-not-rewritten.png")
(test (with-compound-rewriter
'sum
(λ (lws) (list "" (list-ref lws 2) " + " (list-ref lws 3) " = " (list-ref lws 4)))
(render-judgment-form sum))
"judgment-form-rewritten.png")
(define-judgment-form nats (define-judgment-form nats
#:mode (mfw I O) #:mode (mfw I O)
[(mfw n_1 n_2) [(mfw n_1 n_2)
@ -309,16 +302,12 @@
(define-metafunction nats (define-metafunction nats
[(f n) n]) [(f n) n])
(test (render-judgment-form mfw) "judgment-form-metafunction-where.png")
(define-judgment-form nats (define-judgment-form nats
#:mode (nps I O) #:mode (nps I O)
[(nps (name a (s n_1)) n_2) [(nps (name a (s n_1)) n_2)
(nps z (name n_1 (s (s n_1)))) (nps z (name n_1 (s (s n_1))))
(where (name b n_2) z)]) (where (name b n_2) z)])
(test (render-judgment-form nps) "judgment-form-name-patterns.png")
(define-judgment-form nats (define-judgment-form nats
#:mode (lt2 I) #:mode (lt2 I)
[(lt2 z)] [(lt2 z)]
@ -330,7 +319,22 @@
(lt2 n) ... (lt2 n) ...
(sum z z z)]) (sum z z z)])
(test (render-judgment-form uses-ellipses) "judgment-form-ellipsis.png")) (test (vc-append
10
(render-judgment-form sum)
(with-compound-rewriter
'sum
(λ (lws) (list "" (list-ref lws 2) " + " (list-ref lws 3) " = " (list-ref lws 4)))
(render-judgment-form sum))
(render-judgment-form mfw)
(render-judgment-form nps)
(render-judgment-form uses-ellipses))
"judgment-form-examples.png"))
(let () (let ()
(define-language STLC (define-language STLC

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 510 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 964 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 749 B

After

Width:  |  Height:  |  Size: 810 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 510 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 946 B

After

Width:  |  Height:  |  Size: 937 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB