|
76 | 76 | end |
77 | 77 | end |
78 | 78 |
|
79 | | -@moduletestset "UnicodePlots" begin |
80 | | - import UnicodePlots |
81 | 79 |
|
82 | | - io = IOBuffer() |
83 | | - ht, wd = 50, 120 |
84 | | - ioc = IOContext(io, :displaysize => (ht, wd)) |
| 80 | +@moduletestset "Plots" begin |
| 81 | + using Plots |
| 82 | + |
| 83 | + rv = rand(1000) |
| 84 | + K = kde(rv, lo = 0.0, hi = 1.0, boundary = :closed) |
| 85 | + |
| 86 | + # simply test that invocation is not an error |
| 87 | + @test plot(K) isa Plots.Plot |
| 88 | + @test plot(K, linetype = :steppre) isa Plots.Plot |
| 89 | + |
| 90 | + # default labels are set |
| 91 | + p = plot(K) |
| 92 | + @test p[1][:xaxis][:guide] == "value" |
| 93 | + @test p[1][:yaxis][:guide] == "density" |
| 94 | +end |
85 | 95 |
|
86 | | - K = kde(collect(0:0.01:1), bandwidth = 0.5, boundary = :closed) |
87 | | - show(ioc, MIME"text/plain"(), K) |
88 | | - str = String(take!(io)) |
89 | 96 |
|
90 | | - let S = split(str, '\n') |
91 | | - @test all(length(s) <= wd for s in S) |
92 | | - @test length(S) < ht |
| 97 | +@moduletestset "UnicodePlots" begin |
| 98 | + using UnicodePlots |
| 99 | + |
| 100 | + K = kde(sqrt.(0:0.01:1), bandwidth = 0.5, boundary = :closed) |
| 101 | + |
| 102 | + function termprint(x) |
| 103 | + context = (:displaysize => (50, 120), :color => true) |
| 104 | + return sprint(x; context) do io, obj |
| 105 | + show(io, MIME"text/plain"(), obj) |
| 106 | + end |
93 | 107 | end |
94 | | - @test any(!isascii, str) |
| 108 | + |
| 109 | + # generate an empty plot (to check that plotting is different from) |
| 110 | + empty = termprint(Plot(Float64[], Float64[]; xlim = (0, 1), ylim = (0, 3))) |
| 111 | + |
| 112 | + # plot from scratch |
| 113 | + p1 = lineplot(K, color = :green) |
| 114 | + str1 = termprint(p1) |
| 115 | + @test str1 != empty |
| 116 | + @test any(!isascii, str1) |
| 117 | + |
| 118 | + # plot into a canvas |
| 119 | + p2 = Plot(Float64[], Float64[]; xlim = (0, 1), ylim = (0, 3)) |
| 120 | + lineplot!(p2, K, color = :green) |
| 121 | + str2 = termprint(p2) |
| 122 | + @test str1 == str2 |
| 123 | + # change color and overplot, resulting in different (color!) plot |
| 124 | + lineplot!(p2, K, color = :blue) |
| 125 | + str3 = termprint(p2) |
| 126 | + @test str3 != str2 |
| 127 | + # but contents are the same if the color information is stripped away |
| 128 | + # pattern based on https://en.wikipedia.org/wiki/ANSI_escape_code#Colors |
| 129 | + stripcolor(s) = replace(s, r"\e\[(\d+;)*\d*m" => "") |
| 130 | + @test stripcolor(str3) == stripcolor(str2) |
95 | 131 | end |
0 commit comments