From c11cacbb996c5225fac5aa286f031c3fa3d1ef7a Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Thu, 3 Sep 2015 18:05:30 -0400 Subject: [PATCH] tests --- src/Plots.jl | 2 ++ src/plot.jl | 4 ++-- test/runtests.jl | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index d903ee82..0803a119 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -6,6 +6,8 @@ export plotter!, plot, plot!, + currentPlot, + currentPlot!, savepng # --------------------------------------------------------- diff --git a/src/plot.jl b/src/plot.jl index 76098ef7..9129aa34 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -116,8 +116,8 @@ When plotting multiple lines, you can give every line the same trait by using th # this creates a new plot with args/kw and sets it to be the current plot function plot(args...; kw...) plt = newplot(plotter()) - currentPlot!(plt) plot!(plt, args...; kw...) + currentPlot!(plt) plt end @@ -144,7 +144,7 @@ end function plot!(plt::Plot, y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1) n,m = size(y) for i in 1:m - plot!(plt; x = 1:m, y = y[:,i], kw...) + plot!(plt; x = 1:n, y = y[:,i], kw...) end plt end diff --git a/test/runtests.jl b/test/runtests.jl index dd139101..4f8c236d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,30 @@ facts("Qwt") do @fact plotter!(:qwt) --> nothing @fact plotter() --> Plots.QwtPackage() @fact typeof(plot(1:10, show=false)) --> Plot + + # plot(y::AVec; kw...) # one line... x = 1:length(y) + @fact plot(1:10, show=false) --> not(nothing) + @fact length(currentPlot().o.lines) --> 1 + + # plot(x::AVec, y::AVec; kw...) # one line (will assert length(x) == length(y)) + @fact plot(Int[1,2,3], rand(3); show=false) --> not(nothing) + @fact_throws plot(1:5, 1:4) + + # plot(y::AMat; kw...) # multiple lines (one per column of x), all sharing x = 1:size(y,1) + @fact plot!(rand(10,2)) --> not(nothing) + @fact length(currentPlot().o.lines) --> 3 + + # plot(x::AVec, y::AMat; kw...) # multiple lines (one per column of x), all sharing x (will assert length(x) == size(y,1)) + @fact plot(sort(rand(10)), rand(Int, 10, 3)) --> not(nothing) + + # plot(x::AMat, y::AMat; kw...) # multiple lines (one per column of x/y... will assert size(x) == size(y)) + # plot(x::AVec, f::Function; kw...) # one line, y = f(x) + # plot(x::AMat, f::Function; kw...) # multiple lines, yᵢⱼ = f(xᵢⱼ) + # plot(x::AVec, fs::AVec{Function}; kw...) # multiple lines, yᵢⱼ = fⱼ(xᵢ) + # plot(y::AVec{AVec}; kw...) # multiple lines, each with x = 1:length(y[i]) + # plot(x::AVec, y::AVec{AVec}; kw...) # multiple lines, will assert length(x) == length(y[i]) + # plot(x::AVec{AVec}, y::AVec{AVec}; kw...) # multiple lines, will assert length(x[i]) == length(y[i]) + # plot(n::Integer; kw...) # n lines, all empty (for updating plots) end facts("Gadfly") do