(
    maxima_tempdir: sconcat (maxima_tempdir, "/", "draw-test-", ?getpid ()),
    print ("rtest_draw: output image and Gnuplot files to", maxima_tempdir),
    load ("operatingsystem"),
    /* I SUPPOSE WE SHOULD NUKE THE DIRECTORY IF IT EXISTS ALREADY */
    mkdir (maxima_tempdir),

    execute_test (expr, result) ::=
        block ([file_name_output, file_name_output_path],

               file_name_output: next_file_name (),
               /* need to paste path onto file name, since otherwise
                * the graphic output file is created in the current directory.
                */
               file_name_output_path: sconcat (maxima_tempdir, "/", file_name_output),

               /* assign these file names to global variables
                * so that they can be inspected after the fact
                */
               file_name_gnuplot: sconcat (file_name_output, ".gnuplot"),
               file_name_data_gnuplot: sconcat (file_name_output, ".data"),

               draw_tests[file_name_output]: expr,
               buildq ([file_name_output_path, file_name_gnuplot, file_name_data_gnuplot, expr, result],
                       (set_draw_defaults ('file_name = file_name_output_path,
                                           'gnuplot_file_name = file_name_gnuplot,
                                           'data_file_name = file_name_data_gnuplot),
                        expr,
                        result))),

    file_name_counter: 0,
    next_file_name () := printf (false, "draw-test-~3,'0d", file_name_counter: file_name_counter + 1),

    /* Define a function that tests if the gnuplot file created by draw contains
       a set of lines.
       */
    gnuplot_contains([x]):=block(
        [
            infile:openr(sconcat(maxima_tempdir,"/",file_name_gnuplot)),
            line,
	    retval,
            lines:[]
        ],
        while(stringp(line:readline(infile))) do
            push(line,lines),
        retval:emptyp(
            setdifference(
                setify(x),
                setify(lines)
            )
        ),
	close(infile),
	return(retval)
    ),
    /* Define a function that tests if the gnuplot file created by draw contains
       a string.
       */
    gnuplot_contains_string(x):=block(
        [
            infile:openr(sconcat(maxima_tempdir,"/",file_name_gnuplot)),
            line,retval:false
        ],
        while(stringp(line:readline(infile))) do
            if numberp(ssearch(x,line)) then retval:true,
	close(infile),
	return(retval)
    ),
    0
);
0$

/* Test if "title=" affects the gnuplot file. */
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,1,10)
),0);
0$
gnuplot_contains("set title ''");
true$

execute_test (draw2d(
    terminal='svg,
    title="Test",
    explicit(sin(x),x,1,10)
),0);
0$
gnuplot_contains("set title 'Test'");
true$

/* Test "contour=". */
execute_test (draw3d(
    terminal='svg,
    contour='none,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
execute_test (draw3d(
    terminal='svg,
    contour='base,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
gnuplot_contains("set contour base");
true$
execute_test (draw3d(
    terminal='svg,
    contour='both,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
gnuplot_contains("set contour both");
true$
execute_test (draw3d(
    terminal='svg,
    contour='surface,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
gnuplot_contains("set contour surface");
true$
execute_test (draw3d(
    terminal='svg,
    contour='map,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
gnuplot_contains("set contour base","unset surface");
true$

/* Test "axis_3d=". */
execute_test (draw3d(
    terminal='svg,
    axis_3d=false,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
gnuplot_contains("unset xtics", "unset ytics", "unset ztics", "set border 0");
true$
execute_test (draw3d(
    terminal='svg,
    axis_3d=true,
    explicit(sin(x*y),x,1,10,y,1,10)
),0);
0$
gnuplot_contains("unset xtics");
false$
gnuplot_contains("unset ytics");
false$
gnuplot_contains("unset ztics");
false$
gnuplot_contains("set border 0");
false$

/* test the other axis_* commands */
execute_test (draw2d(
    terminal='svg,
    axis_bottom = false,
    explicit(sin(x),x,1,10)
),0);
0$
gnuplot_contains("set border 14");
true$
execute_test (draw2d(
    terminal='svg,
    axis_top = false,
    explicit(sin(x),x,1,10)
),0);
0$
gnuplot_contains("set border 11");
true$
execute_test (draw2d(
    terminal='svg,
    axis_left = false,
    explicit(sin(x),x,1,10)
),0);
0$
gnuplot_contains("set border 13");
true$
execute_test (draw2d(
    terminal='svg,
    axis_right = false,
    explicit(sin(x),x,1,10)
),0);
0$
gnuplot_contains("set border 7");
true$


/* test all combination of border and transparent */
execute_test (draw2d(
    terminal='svg,
    border = true, transparent = true,
    polygon([[3,2],[7,2],[5,5]])
),0);
0$
gnuplot_contains_string("lt ");
true$
gnuplot_contains_string("filledcurves ");
false$
execute_test (draw2d(
    terminal='svg,
    border = false, transparent = false,
    polygon([[3,2],[7,2],[5,5]])
),0);
0$
gnuplot_contains_string("lt ");
false$
gnuplot_contains_string("filledcurves ");
true$
execute_test (draw2d(
    terminal='svg,
    border = true, transparent = false,
    polygon([[3,2],[7,2],[5,5]])
),0);
0$
gnuplot_contains_string("lt ");
true$
gnuplot_contains_string("filledcurves ");
true$

/* test background_color */
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    background_color="#FF0000",
    explicit(sin(x),x,0,10)
),0);
0$
gnuplot_contains_string("obj 1 fc rgb '#ff0000'");
true$
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    background_color="#00FF0080",
    explicit(sin(x),x,0,10)
),0);
0$
gnuplot_contains_string("obj 1 fc rgb '#00ff0080'");
true$
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    background_color='yellow,
    explicit(sin(x),x,0,10)
),0);
0$
gnuplot_contains_string("obj 1 fc rgb '#ffff00'");
true$

/* test line_width and line colors including semi-transparent ones */
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    color="#FF0000",
    explicit(sin(x),x,0,10),
    color="#0000FF80",
    explicit(cos(x),x,0,10)
),0);
0$
gnuplot_contains_string("lw 50");
true$
gnuplot_contains_string("lw 50");
true$
gnuplot_contains_string("lc rgb '#800000ff'");
true$
gnuplot_contains_string("lc rgb '#ff0000'");
true$
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    color='red,
    explicit(sin(x),x,0,10),
    color='blue,
    explicit(cos(x),x,0,10)
),0);
0$
gnuplot_contains_string("lc rgb '#ff0000'");
true$
gnuplot_contains_string("lc rgb '#0000ff'");
true$

/* test colorbox */
execute_test (draw(
    terminal='svg,
    gr2d(image(apply('matrix,
        makelist(makelist(random(200),i,1,30),i,1,30)),0,0,30,30))
),0);
0$
gnuplot_contains("set colorbox");
true$
gnuplot_contains("unset colorbox");
false$
execute_test (draw(
    terminal='svg,
    gr2d(colorbox = false, image(apply('matrix,
        makelist(makelist(random(200),i,1,30),i,1,30)),0,0,30,30))
),0);
0$
gnuplot_contains("set colorbox");
false$
gnuplot_contains("unset colorbox");
true$

/* test "columns=" */
execute_test (draw(
    terminal='svg,
    gr2d(nticks=30,
        parametric(2*cos(t),5*sin(t),t,0,2*%pi)),
    gr2d(polygon([4,5,7],[6,4,2])),
    columns=2),
    0
)$
0$
gnuplot_contains("set size 1.0, 0.5");
false$
gnuplot_contains("set size 0.5, 1.0");
true$
execute_test (draw(
    terminal='svg,
    gr2d(title="Ellipse",
        nticks=30,
        parametric(2*cos(t),5*sin(t),t,0,2*%pi)),
    gr2d(title="Triangle",
        polygon([4,5,7],[6,4,2])),
    columns=1),
    0
)$
0$
gnuplot_contains("set size 1.0, 0.5");
true$
gnuplot_contains("set size 0.5, 1.0");
false$
gnuplot_contains("set title 'Ellipse'");
true$
gnuplot_contains("set title 'Triangle'");
true$

/* test "allocation=" */
execute_test (draw(
    terminal='svg,
    dimensions=[1123,1124],
    gr2d(
        explicit(x^2,x,-1,1)),
    gr2d(
        allocation = [[1/4, 1/4],[1/2, 1/2]],
        explicit(x^3,x,-1,1),
        grid = true)
    ),
    0
);
0$
gnuplot_contains("set size 0.5, 0.5");
true$
gnuplot_contains("set origin 0.25, 0.25");
true$
gnuplot_contains_string("size 1123, 1124");
true$

/* test "delay=" */
execute_test (draw(
    terminal='animated_gif,
    delay     = 100,
    gr2d(explicit(x^2,x,-1,1)),
    gr2d(explicit(x^3,x,-1,1)),
    gr2d(explicit(x^4,x,-1,1))),0);
0$
gnuplot_contains_string("delay 100");
true$
gnuplot_contains_string("set terminal gif enhanced animate");
true$

/* test "enhanced3d=". In this instance we don't look at the .gnuplot file
   but at the data this file causes gnuplot to plot instead.
*/
execute_test (draw3d(
    terminal='svg,
    enhanced3d='none,
    points([1,2,3,4],[3,5,3,1],[1,7,5,3])),
0);
0$
read_nested_list (sconcat (maxima_tempdir, "/", file_name_data_gnuplot));
[[1.0,3.0,1.0],[2.0,5.0,7.0],[3.0,3.0,5.0],[4.0,1.0,3.0],[],[]]$
execute_test (draw3d(
    terminal='svg,
    enhanced3d=false,
    points([1,2,3,4],[3,5,3,1],[1,7,5,3])),
0);
0$
read_nested_list (sconcat (maxima_tempdir, "/", file_name_data_gnuplot));
[[1.0,3.0,1.0],[2.0,5.0,7.0],[3.0,3.0,5.0],[4.0,1.0,3.0],[],[]]$
execute_test (draw3d(
    terminal='svg,
    enhanced3d = [x-z/10,x,y,z],
    points([1,2,3,4],[3,5,3,1],[1,7,5,3])),
0);
0$
read_nested_list (sconcat (maxima_tempdir, "/", file_name_data_gnuplot));
[[1.0,3.0,1.0,0.9],[2.0,5.0,7.0,1.3],[3.0,3.0,5.0,2.5],[4.0,1.0,3.0,3.7],[],[]]$
execute_test (draw3d(
    terminal='svg,
    enhanced3d=true,
    points([1,2,3,4],[3,5,3,1],[1,7,5,3])),
0);
0$
read_nested_list (sconcat (maxima_tempdir, "/", file_name_data_gnuplot));
[[1.0,3.0,1.0,1.0],[2.0,5.0,7.0,7.0],[3.0,3.0,5.0,5.0],[4.0,1.0,3.0,3.0],[],[]]$
execute_test (draw3d(
    terminal='svg,
    enhanced3d = [sin(r*s),r,s],
    explicit(sin(x)*sin(y),x,-2,2,y,-2,2)),
0);
0$

/* For the errors object we can at least test if using any of its variants
   causes an error. */
execute_test (draw2d(
    terminal='svg,
    error_type = 'y,
    errors([[1,2,1], [3,5,3], [10,3,1], [17,6,2]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'x,
    errors([[1,2,1], [3,5,3], [10,3,1], [17,6,2]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'y,
    errors([[1,2,1,1], [3,5,3,2], [10,3,1,1], [17,6,2,2]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'x,
    errors([[1,2,1,1], [3,5,3,2], [10,3,1,1], [17,6,2,2]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'xy,
    errors([[1,2,1,1], [3,5,3,3], [10,3,1,2], [17,6,2,1]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'boxes,
    errors([[1,2,1,1], [3,5,3,3], [10,3,1,2], [17,6,2,1]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'xy,
    errors([[1,2,1,1,1,1], [3,5,3,3,1,1], [10,3,1,2,2,2], [17,6,2,1,2,1]])),0);
0$
execute_test (draw2d(
    terminal='svg,
    error_type = 'boxes,
    errors([[1,2,1,1,2,2], [3,5,3,3,1,1], [10,3,1,2,2,2], [17,6,2,1,2,1]])),0);
0$

/* fill_color and filled_func */
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    fill_color="#FF0000",
    filled_func=x,
    explicit(sin(x),x,0,10),
    fill_color="#0000FF80",
    explicit(cos(x),x,0,10)
),0);
0$
gnuplot_contains_string("lc rgb '#800000ff'");
true$
gnuplot_contains_string("lc rgb '#ff0000'");
true$
execute_test (draw2d(
    terminal='svg,
    line_width=50,
    fill_color='red,
    filled_func=1,
    explicit(sin(x),x,0,10),
    fill_color='green,
    explicit(cos(x),x,0,10)
),0);
0$
gnuplot_contains_string("lc rgb '#ff0000'");
true$
gnuplot_contains_string("lc rgb '#00ff00'");
true$

/* Test if drawing a grid works */
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,0,10),
    grid=true
),0);
0$
gnuplot_contains("set grid xtics ytics mxtics mytics");
true$
gnuplot_contains("set mxtics 1");
true$
gnuplot_contains("set mytics 1");
true$
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,0,10),
    grid=[10,1]
),0);
0$
gnuplot_contains("set grid xtics ytics mxtics mytics");
true$
gnuplot_contains("set mxtics 10");
true$
gnuplot_contains("set mytics 1");
true$
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,0,10),
    grid=[1,10]
),0);
0$
gnuplot_contains("set grid xtics ytics mxtics mytics");
true$
gnuplot_contains("set mxtics 1");
true$
gnuplot_contains("set mytics 10");
true$
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,0,10),
    grid=[1.2,10.6]
),0);
0$
gnuplot_contains("set grid xtics ytics mxtics mytics");
true$
gnuplot_contains("set mxtics 1");
true$
gnuplot_contains("set mytics 11");
true$
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,0,10),
    grid=[1.6,10.4]
),0);
0$
gnuplot_contains("set grid xtics ytics mxtics mytics");
true$
gnuplot_contains("set mxtics 2");
true$
gnuplot_contains("set mytics 10");
true$
execute_test (draw2d(
    terminal='svg,
    explicit(sin(x),x,0,10),
    grid=false
),0);
0$
gnuplot_contains("unset grid");
true$

/* Tests for head_length, head_angle, head_both and head_type */
execute_test (draw2d(
    terminal='svg,
    xrange      = [0,10],
    yrange      = [0,9],
    head_length = 0.7,
    head_angle  = 10,
    head_both   = false,
    vector([1,1],[0,6]),
    head_angle  = 20,
    vector([2,1],[0,6]),
    head_angle  = 30,
    vector([3,1],[0,6]),
    head_angle  = 40,
    vector([4,1],[0,6]),
    head_angle  = 60,
    vector([5,1],[0,6]),
    head_angle  = 90,
    head_both   = true,
    vector([6,1],[0,6]),
    head_angle  = 120,
    head_type='filled,
    vector([7,1],[0,6]),
    head_angle  = 160,
    head_type='empty,
    vector([8,1],[0,6]),
    head_angle  = 180,
    head_length = 0.3,
    head_type='nofilled,
    vector([9,1],[0,6]) ),0);
0$
gnuplot_contains_string("vect head size 0.7, 10.0");
true$
gnuplot_contains_string("vect head size 0.7, 20.0");
true$
gnuplot_contains_string("vect head size 0.7, 30.0");
true$
gnuplot_contains_string("vect head size 0.7, 40.0");
true$
gnuplot_contains_string("vect head size 0.7, 60.0");
true$
gnuplot_contains_string("vect heads size 0.7, 90.0");
true$
gnuplot_contains_string("vect heads size 0.7, 120.0 filled");
true$
gnuplot_contains_string("vect heads size 0.7, 160.0 empty");
true$
gnuplot_contains_string("vect heads size 0.3, 180.0 nofilled");
true$

/* Tests for points(...) with values which are not finite reals.
 * For implementations which permit non-finite IEEE 754 floats,
 * the symbols infty and nan can be assigned suitable values
 * before executing this script.
 * For other implementations, infty and nan can be left as symbols.
 *
 * SBCL, Clozure CL, ECL, CMUCL, and maybe other implementations
 * permit non-finite IEEE 754 floats. The details vary; here is
 * an incantation for SBCL:
 *
 * :lisp (sb-vm::set-floating-point-modes :traps nil)
 * :lisp (defparameter $infty (/ 1d0 0d0))
 * :lisp (defparameter $nan (/ 0d0 0d0))
 */

(xx: [2, 3, 5, 7, 11, 13, 17, 19],
 yy: [11, 7, 17, 5, 2, 13, 19, 3],
 xx1: copy (xx),
 xx1[1]: xx1[8]: infty,
 xx2: copy (xx),
 xx2[3]: xx2[4]: xx2[5]: nan,
 yy1: copy (yy),
 yy1[4]: yy1[5]: nan,
 yy2: copy (yy),
 yy2[2]: yy2[4]: yy2[6]: infty,
 array_from ([l]) :=
    if length (l) = 1
        then (make_array (any, length (l[1])), fillarray (%%, l[1]))
        else (make_array (any, length (l), length (l[1])), fillarray (%%, apply (append, l))),
 sanitize_nonfinite (l) := subst ([infty = 'infty, nan = 'nan], l),
 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx, yy), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (args (transpose (matrix (xx, yy)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (array_from (xx), array_from (yy)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (array_from (xx, yy)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (apply (array_from, args (transpose (matrix (xx, yy))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (matrix (xx, yy)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (transpose (matrix (xx, yy))), title = "points(matrix), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (xx1, yy), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (args (transpose (matrix (xx1, yy)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx1), array_from (yy)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx1, yy)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (apply (array_from, args (transpose (matrix (xx1, yy))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (matrix (xx1, yy)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (transpose (matrix (xx1, yy))), title = "points(matrix), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (xx, yy1), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (args (transpose (matrix (xx, yy1)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx), array_from (yy1)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx, yy1)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (apply (array_from, args (transpose (matrix (xx, yy1))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (matrix (xx, yy1)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (transpose (matrix (xx, yy1))), title = "points(matrix), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (xx1, yy1), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (args (transpose (matrix (xx1, yy1)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx1), array_from (yy1)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx1, yy1)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (apply (array_from, args (transpose (matrix (xx1, yy1))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (matrix (xx1, yy1)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx1)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy1)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (transpose (matrix (xx1, yy1))), title = "points(matrix), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (xx2, yy), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (args (transpose (matrix (xx2, yy)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx2), array_from (yy)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx2, yy)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (apply (array_from, args (transpose (matrix (xx2, yy))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (matrix (xx2, yy)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (transpose (matrix (xx2, yy))), title = "points(matrix), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (xx, yy2), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (args (transpose (matrix (xx, yy2)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx), array_from (yy2)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx, yy2)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (apply (array_from, args (transpose (matrix (xx, yy2))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (matrix (xx, yy2)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (transpose (matrix (xx, yy2))), title = "points(matrix), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (xx2, yy2), title = "points(flat-list, flat-list)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (args (transpose (matrix (xx2, yy2)))), title = "points(nested-list), 2 elements per sublist"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx2), array_from (yy2)), title = "points(array-1d, array-1d)"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (array_from (xx2, yy2)), title = "points(array-2d), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (apply (array_from, args (transpose (matrix (xx2, yy2))))), title = "points(array-2d), 2 columns"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (matrix (xx2, yy2)), title = "points(matrix), 2 rows"), 0);
0;

execute_test (draw2d (xlabel = printf (false, "x = ~a", sanitize_nonfinite (xx2)), ylabel = printf (false, "y = ~a", sanitize_nonfinite (yy2)), terminal = 'png, point_type = 7, points_joined = true, points (xx - 0.1, yy - 0.1), color = red, points (transpose (matrix (xx2, yy2))), title = "points(matrix), 2 columns"), 0);
0;

/* SF bug #4424: "draw2d doesnt accept fill_density in order to create opaque shapes" */

execute_test (draw2d (title = "fill\\_density works!", proportional_axes = 'xy, grid = true, xrange = [-4, 0], yrange = [-3, 3], xlabel = "Re(h λ)", ylabel = "Im(h λ)", key = "stability region", transparent = false, color = blue, line_width = 1, fill_color = light_pink, fill_density = 0.3, nticks = 80, ellipse(-1, 0, 1, 1, 0, 360), terminal = 'png), 0);
0;

execute_test (draw2d(fill_color = red, filled_func = true, fill_density = 0.5, explicit(-sin(x),x,0,%pi), terminal = 'png), 0);
0;

block ([L: flatten (rest (arrayinfo (draw_tests), 2)), linel: 1000],
       with_stdout (sconcat (maxima_tempdir, "/draw-tests-summary.txt"),
           for f in L do print (f, "pertains to", string (draw_tests[f]))),
       0);
0;
