;;;; s9fes-char-graphics-test.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 (import test) (test-begin "S9fES Char Graphics") ;;; (import (only (chicken port) with-output-to-string)) ;; (import (s9fes char-canvas)) (define CD-TEST-RESULT-1 (apply string-append '( "## **\n" " ## ** \n" " ** \n" " ** ## \n" "** ##\n"))) (define CD-TEST-RESULT-2 (apply string-append '( " \n" " \n" " \n" " \n" " \n"))) (define CD-TEST-RESULT-3 (apply string-append '( "## **\n" " ## ** \n" " ** \n" " Hello, W\n" "** ##\n"))) (define CD-TEST-RESULT-4 (apply string-append '( " 221 \n" " 2 1 \n" " 3 221 0 \n" " 3 3 0 0\n" " 4 4 7 7\n" " 4 4 7 7\n" " 4 566 7 \n" " 5 6 \n" " 566 \n" " \n"))) (test-group "char-canvas" (define (draw-X c) (canvas-plot-line c 0 9 9 0 #\#) (canvas-plot-line c 0 0 9 9 #\*) (canvas->string c) ) (test-group "basics & line" (let ((c (make-canvas 10 5 10 10))) (test-assert (canvas? c)) (test-assert (not (canvas? 2))) (test 10 (canvas-columns c)) (test 5 (canvas-rows c)) (test 10 (canvas-width c)) (test 10 (canvas-height c)) (test "draw X example" CD-TEST-RESULT-1 (draw-X c)) (canvas-clear c) (test "clears" CD-TEST-RESULT-2 (canvas->string c)) ) ) (test-group "virtual coords" (let ((c (make-canvas 10 5 10 10))) (draw-X c) (let-values (((x y) (canvas-physical c 2 3))) (test "scales" '(2 1) `(,x ,y)) (test "scales" '(2 2) (receive (canvas-virtual c x y))) (canvas-draw-string c x y "Hello, World") (test "scales" CD-TEST-RESULT-3 (canvas->string c)) ) ) ) (test-group "circle" ;NOTE virtual coords NOT supported (define (visit canvas x0 y0 x y) (let-values (((xr0 yr0 xr1 yr1 xr2 yr2 xr3 yr3 xr4 yr4 xr5 yr5 xr6 yr6 xr7 yr7) (circle-octant-coordinates x0 y0 x y)) ) (canvas-draw canvas xr0 yr0 #\0) (canvas-draw canvas xr1 yr1 #\1) (canvas-draw canvas xr2 yr2 #\2) (canvas-draw canvas xr3 yr3 #\3) (canvas-draw canvas xr4 yr4 #\4) (canvas-draw canvas xr5 yr5 #\5) (canvas-draw canvas xr6 yr6 #\6) (canvas-draw canvas xr7 yr7 #\7) #t ) ) (let ((c (make-canvas 10 10 10 10))) (generate-circle-octant c 2 (circle-octant-visitor 5 5 visit)) (generate-circle-octant c 4 (circle-octant-visitor 5 5 visit)) (test "circles" CD-TEST-RESULT-4 (canvas->string c)) ) ) ) ;; (import (s9fes char-plot)) (define CP-TEST-DATA-1 '(0 1 2 3 4 5 6 7 8 9)) ;NOTE editors can trim trailing so don't give them the chance #; ;FIXME Example Output (define CP-TEST-RESULT-1 (apply string-append '( "----------- foo --> -----------------\n" "| --|\n" "| --X- |\n" "| --X---X- |\n" "| --X- |\n" "| --X---X- |\n" "| --X- |\n" "|X--X- |\n" "----------- foo --> -----------------\n"))) ;FIXME Actual Output (define CP-TEST-RESULT-1 (apply string-append '( "----------- foo --> -----------------\n" "| -X |\n" "| --X- |\n" "| --X--X- |\n" "| -X- |\n" "| -X---X- |\n" "| --X- |\n" "|X--X- |\n" "----------- foo --> -----------------\n"))) (test-group "char-plot" (test CP-TEST-RESULT-1 (with-output-to-string (lambda () (char-plot CP-TEST-DATA-1 'foo 7 35 #f)))) ) ;; (import (s9fes draw-tree)) (define DT-TEST-FORM-1 '((a) (b . c) (d e))) ;NOTE editors can trim trailing so don't give them the chance (define DT-TEST-RESULT-1 (apply string-append '( "[o|o]---[o|o]---[o|/]\n" " | | | \n" "[o|/] | [o|o]---[o|/]\n" " | | | | \n" " a | d e \n" " | \n" " [o|o]--- c \n" " | \n" " b \n"))) (test-group "draw-tree" (test DT-TEST-RESULT-1 (with-output-to-string (lambda () (draw-tree DT-TEST-FORM-1)))) ) ;;; (test-end "S9fES Char Graphics") (test-exit)