;;;; 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 (chicken fixnum)) ;srfi-1 (define (make-list n #!optional (f #f)) (vector->list (make-vector n f))) ;; (import (s9fes char-canvas) (s9fes char-canvas shape oval) (s9fes char-canvas shape cross)) (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 (let ((pltr (cross-x-plotter 10 10 '(#\# #\*)))) (lambda (cv) (pltr cv) (canvas->string cv) ) ) ) (define octant-plotter (circle-octant-plotter '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7))) (test-group "basics & line" (let ((cv (make-canvas 10 5 10 10))) (test-assert (canvas? cv)) (test-assert (not (canvas? 2))) (test 10 (canvas-columns cv)) (test 5 (canvas-rows cv)) (test 10 (canvas-width cv)) (test 10 (canvas-height cv)) (test "draw X example" CD-TEST-RESULT-1 (draw-X cv)) (canvas-clear cv) (test "clears" CD-TEST-RESULT-2 (canvas->string cv)) ) ) (test-group "virtual coords" (let ((cv (make-canvas 10 5 10 10))) (draw-X cv) (let-values (((x y) (canvas-physical cv 2 3))) (test "scales" '(2 1) `(,x ,y)) (test "scales" '(2 2) (receive (canvas-virtual cv x y))) (canvas-draw-string cv x y "Hello, World") (test "scales" CD-TEST-RESULT-3 (canvas->string cv)) ) ) ) (test-group "circle () - default vc" (let ((cv (make-canvas 10 10))) (generate-circle-octant cv 2 (circle-octant-visitor 5 5 octant-plotter)) (generate-circle-octant cv 4 (circle-octant-visitor 5 5 octant-plotter)) (test "circles" CD-TEST-RESULT-4 (canvas->string cv)) ) ) (test-group "circle (_)" (let ((cv (make-canvas 10 10 200 500))) (generate-virtual-circle-octant cv 100 (virtual-circle-octant-visitor 100 250 octant-plotter)) (generate-virtual-circle-octant cv 200 (virtual-circle-octant-visitor 100 250 octant-plotter)) (test "circles" CD-TEST-RESULT-4 (canvas->string cv)) ) ) ) ;; (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)