Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fredo-dedup committed Mar 11, 2016
1 parent 551af87 commit fac51d5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 17 deletions.
3 changes: 3 additions & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
julia 0.4
JSON
RDatasets
45 changes: 28 additions & 17 deletions test/GP Lite.jl → test/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ title(1, "with plots using VegaLite") |> fontstyle(italic)
#------- plot ------------------------------------
@newchunk center


ts = sort(rand(10))
ys = Float64[ rand()*0.1 + cos(x) for x in ts]

Expand All @@ -40,6 +39,9 @@ v = data_values(time=ts, res=ys) +
encoding_x_quant(:time) +
encoding_y_quant(:res)

@newchunk center2


v2 = v + config_scale(round=true)
JSON.print(v2.vis)

Expand Down Expand Up @@ -89,34 +91,43 @@ data_values(mpg) +
data_values(mpg) +
mark_point() +
encoding_x_quant(:Cty, axis=false) +
encoding_y_quant(:Hwy) +
encoding_color_nominal(:Manufacturer)
encoding_y_quant(:Hwy, scale=scale(zero=false)) +
encoding_color_nominal(:Manufacturer) +
config_cell(width=350, height=400)

data_values(mpg) +
mark_line() +
encoding_x_ord(:Year,
axis = Dict(:labelAngle=>-45, :labelAlign=>"right"),
scale = Dict(:bandSize=>50)) +
axis = axis(labelAngle=-45, labelAlign="right"),
scale = scale(bandSize=50)) +
encoding_y_quant(:Hwy, aggregate="mean") +
encoding_color_nominal(:Manufacturer)


data_values(mpg) +
mark_point() +
encoding_column_ord(:Cyl) +
encoding_row_ord(:Year) +
encoding_x_quant(:Displ) +
encoding_y_quant(:Hwy) +
encoding_size_quant(:Cty) +
encoding_color_nominal(:Manufacturer)

{
"data": {"url": "data/cars.json"},
"mark": "text",
"encoding": {
"row": {"field": "Origin", "type": "ordinal"},
"column": {"field": "Cylinders", "type": "ordinal"},
"color": {"aggregate": "mean", "field": "Horsepower", "type": "quantitative"},
"text": {"aggregate": "count", "field": "*", "type": "quantitative"}
},
"config": {"mark": {"applyColorToBackground": true}}
}
data_values(mpg) +
mark_text() +
encoding_column_ord(:Cyl) +
encoding_row_ord(:Year) +
encoding_text_quant(:Displ, aggregate="mean") +
config_mark(fontStyle="italic", fontSize=12, font="courier")


{
"data": {"url": "data/cars.json"},
"mark": "text",
"encoding": {
"row": {"field": "Origin", "type": "ordinal"},
"column": {"field": "Cylinders", "type": "ordinal"},
"color": {"aggregate": "mean", "field": "Horsepower", "type": "quantitative"},
"text": {"aggregate": "count", "field": "*", "type": "quantitative"}
},
"config": {"mark": {"applyColorToBackground": true}}
}
48 changes: 48 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Base.Test
using VegaLite

@test_throws ErrorException config(abcd="trus")
@test_throws ErrorException config(viewport="trus")
@test isa(config(viewport=[400,330]), VegaLiteVis)


xs = collect(linspace(0,2,100))
ys = Float64[ rand()*0.1 + cos(x) for x in xs]

@test isa(data_values(time=xs, res=ys), VegaLiteVis)
@test isa(mark_line(), VegaLiteVis)
@test isa(encoding_x_quant(:time), VegaLiteVis)
@test isa(encoding_y_quant(:res), VegaLiteVis)

using RDatasets
mpg = dataset("ggplot2", "mpg")

@test isa(data_values(mpg), VegaLiteVis)
@test isa(mark_point(), VegaLiteVis)

@test isa(encoding_x_quant(:Cty, axis=false), VegaLiteVis)
@test isa(encoding_y_quant(:Hwy, scale=scale(zero=false)), VegaLiteVis)
@test isa(encoding_color_nominal(:Manufacturer), VegaLiteVis)
@test isa(config_cell(width=350, height=400), VegaLiteVis)

@test isa(encoding_x_ord(:Year,
axis = axis(labelAngle=-45, labelAlign="right"),
scale = scale(bandSize=50)), VegaLiteVis)

@test isa(encoding_column_ord(:Cyl), VegaLiteVis)
@test isa(encoding_row_ord(:Year), VegaLiteVis)

@test isa(encoding_x_quant(:Displ), VegaLiteVis)
@test isa(encoding_y_quant(:Hwy), VegaLiteVis)

@test isa(encoding_size_quant(:Cty), VegaLiteVis)

@test isa(mark_text(), VegaLiteVis)

@test isa(encoding_text_quant(:Displ, aggregate="mean"), VegaLiteVis)
@test isa(config_mark(fontStyle="italic", fontSize=12, font="courier"), VegaLiteVis)




println("Finished")

0 comments on commit fac51d5

Please sign in to comment.