Skip to content

Commit

Permalink
Merge pull request #82 from Prakriti-nith/plot_spec
Browse files Browse the repository at this point in the history
Improve tests coverage for plot.rb
  • Loading branch information
Shekharrajak authored Mar 1, 2018
2 parents b687544 + f9b9ce2 commit a1eab07
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions spec/plot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
context 'chart using DataFrame' do
it { expect(plot_df).to be_a Daru::View::Plot }
it { expect(plot_df.chart.class).to eq Nyaplot::Plot }
it { expect(plot_df.data).to eq df}
it { expect(plot_df.options).to eq type: :line, x: :a, y: :c}
end

context 'chart using Vector' do
it { expect(plot_dv).to be_a Daru::View::Plot }
it { expect(plot_dv.chart).to be_a Nyaplot::Plot }
it { expect(plot_dv.data).to eq dv}
it { expect(plot_dv.options).to eq type: :line}
end

context 'fails when other than DataFrame and Vector is as data' do
Expand All @@ -41,22 +45,42 @@
context 'Highcharts library' do
before { Daru::View.plotting_library = :highcharts }
let(:lib) { Daru::View.plotting_library }
let(:plot_array) { Daru::View::Plot.new([1, 2, 3]) }
let(:df) do
Daru::DataFrame.new(
{
a: [1, 2, 3, 4, 5, 6],
b: [1, 5, 2, 5, 1, 0],
c: [1, 6, 7, 2, 6, 0]
}, index: 'a'..'f'
)
end
let(:dv) { Daru::Vector.new [1, 2, 3] }
let(:plot_df) { Daru::View::Plot.new(df, type: :line, x: :a, y: :c) }
let(:plot_dv) { Daru::View::Plot.new(dv, type: :line) }
let(:plot_array) { Daru::View::Plot.new([1, 2, 3], type: :line) }
it 'check plotting library' do
expect(lib).to eq(:highcharts)
end

it 'Highcharts chart using Array' do
expect(plot_array).to be_a Daru::View::Plot
expect(plot_array.chart).to be_a LazyHighCharts::HighChart
expect(plot_array.data).to eq [1, 2, 3]
expect(plot_array.options).to eq type: :line
end

it 'Highcharts chart using DataFrame' do
# todo
expect(plot_df).to be_a Daru::View::Plot
expect(plot_df.chart).to be_a LazyHighCharts::HighChart
expect(plot_df.data).to eq df
expect(plot_df.options).to eq type: :line, x: :a, y: :c
end

it 'Highcharts chart using Vector' do
# todo
expect(plot_dv).to be_a Daru::View::Plot
expect(plot_dv.chart).to be_a LazyHighCharts::HighChart
expect(plot_dv.data).to eq dv
expect(plot_dv.options).to eq type: :line
end
end
end # initialize context end
Expand All @@ -67,23 +91,44 @@
context 'Googlecharts library' do
before { Daru::View.plotting_library = :googlecharts }
let(:lib) { Daru::View.plotting_library }
let(:options) {{width: 800, height: 720}}
let(:df) do
Daru::DataFrame.new(
{
a: [1, 2, 3, 4, 5, 6],
b: [1, 5, 2, 5, 1, 0],
c: [1, 6, 7, 2, 6, 0]
}, index: 'a'..'f'
)
end
let(:dv) { Daru::Vector.new [1, 2, 3] }
let(:plot_df) { Daru::View::Plot.new(df, options) }
let(:plot_dv) { Daru::View::Plot.new(dv, options) }
let(:plot_array) { Daru::View::Plot.new(
[['col1', 'col2', 'col3'],[1, 2, 3]]) }
[['col1', 'col2', 'col3'],[1, 2, 3]], options) }
it 'check plotting library' do
expect(lib).to eq(:googlecharts)
end

it 'Googlecharts chart using Array' do
expect(plot_array).to be_a Daru::View::Plot
expect(plot_array.chart).to be_a GoogleVisualr::Interactive::LineChart
expect(plot_array.data).to eq [[1, 2, 3]]
expect(plot_array.options).to eq options
end

it 'Googlecharts chart using DataFrame' do
# todo
expect(plot_df).to be_a Daru::View::Plot
expect(plot_df.chart).to be_a GoogleVisualr::Interactive::LineChart
expect(plot_df.data).to eq df
expect(plot_df.options).to eq options
end

it 'Googlecharts chart using Vector' do
# todo
expect(plot_dv).to be_a Daru::View::Plot
expect(plot_dv.chart).to be_a GoogleVisualr::Interactive::LineChart
expect(plot_dv.data).to eq dv
expect(plot_dv.options).to eq options
end
end
end # initialize context end
Expand Down

0 comments on commit a1eab07

Please sign in to comment.