Skip to content

Commit a1eab07

Browse files
authored
Merge pull request #82 from Prakriti-nith/plot_spec
Improve tests coverage for plot.rb
2 parents b687544 + f9b9ce2 commit a1eab07

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

spec/plot_spec.rb

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@
2121
context 'chart using DataFrame' do
2222
it { expect(plot_df).to be_a Daru::View::Plot }
2323
it { expect(plot_df.chart.class).to eq Nyaplot::Plot }
24+
it { expect(plot_df.data).to eq df}
25+
it { expect(plot_df.options).to eq type: :line, x: :a, y: :c}
2426
end
2527

2628
context 'chart using Vector' do
2729
it { expect(plot_dv).to be_a Daru::View::Plot }
2830
it { expect(plot_dv.chart).to be_a Nyaplot::Plot }
31+
it { expect(plot_dv.data).to eq dv}
32+
it { expect(plot_dv.options).to eq type: :line}
2933
end
3034

3135
context 'fails when other than DataFrame and Vector is as data' do
@@ -41,22 +45,42 @@
4145
context 'Highcharts library' do
4246
before { Daru::View.plotting_library = :highcharts }
4347
let(:lib) { Daru::View.plotting_library }
44-
let(:plot_array) { Daru::View::Plot.new([1, 2, 3]) }
48+
let(:df) do
49+
Daru::DataFrame.new(
50+
{
51+
a: [1, 2, 3, 4, 5, 6],
52+
b: [1, 5, 2, 5, 1, 0],
53+
c: [1, 6, 7, 2, 6, 0]
54+
}, index: 'a'..'f'
55+
)
56+
end
57+
let(:dv) { Daru::Vector.new [1, 2, 3] }
58+
let(:plot_df) { Daru::View::Plot.new(df, type: :line, x: :a, y: :c) }
59+
let(:plot_dv) { Daru::View::Plot.new(dv, type: :line) }
60+
let(:plot_array) { Daru::View::Plot.new([1, 2, 3], type: :line) }
4561
it 'check plotting library' do
4662
expect(lib).to eq(:highcharts)
4763
end
4864

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

5472
it 'Highcharts chart using DataFrame' do
55-
# todo
73+
expect(plot_df).to be_a Daru::View::Plot
74+
expect(plot_df.chart).to be_a LazyHighCharts::HighChart
75+
expect(plot_df.data).to eq df
76+
expect(plot_df.options).to eq type: :line, x: :a, y: :c
5677
end
5778

5879
it 'Highcharts chart using Vector' do
59-
# todo
80+
expect(plot_dv).to be_a Daru::View::Plot
81+
expect(plot_dv.chart).to be_a LazyHighCharts::HighChart
82+
expect(plot_dv.data).to eq dv
83+
expect(plot_dv.options).to eq type: :line
6084
end
6185
end
6286
end # initialize context end
@@ -67,23 +91,44 @@
6791
context 'Googlecharts library' do
6892
before { Daru::View.plotting_library = :googlecharts }
6993
let(:lib) { Daru::View.plotting_library }
94+
let(:options) {{width: 800, height: 720}}
95+
let(:df) do
96+
Daru::DataFrame.new(
97+
{
98+
a: [1, 2, 3, 4, 5, 6],
99+
b: [1, 5, 2, 5, 1, 0],
100+
c: [1, 6, 7, 2, 6, 0]
101+
}, index: 'a'..'f'
102+
)
103+
end
104+
let(:dv) { Daru::Vector.new [1, 2, 3] }
105+
let(:plot_df) { Daru::View::Plot.new(df, options) }
106+
let(:plot_dv) { Daru::View::Plot.new(dv, options) }
70107
let(:plot_array) { Daru::View::Plot.new(
71-
[['col1', 'col2', 'col3'],[1, 2, 3]]) }
108+
[['col1', 'col2', 'col3'],[1, 2, 3]], options) }
72109
it 'check plotting library' do
73110
expect(lib).to eq(:googlecharts)
74111
end
75112

76113
it 'Googlecharts chart using Array' do
77114
expect(plot_array).to be_a Daru::View::Plot
78115
expect(plot_array.chart).to be_a GoogleVisualr::Interactive::LineChart
116+
expect(plot_array.data).to eq [[1, 2, 3]]
117+
expect(plot_array.options).to eq options
79118
end
80119

81120
it 'Googlecharts chart using DataFrame' do
82-
# todo
121+
expect(plot_df).to be_a Daru::View::Plot
122+
expect(plot_df.chart).to be_a GoogleVisualr::Interactive::LineChart
123+
expect(plot_df.data).to eq df
124+
expect(plot_df.options).to eq options
83125
end
84126

85127
it 'Googlecharts chart using Vector' do
86-
# todo
128+
expect(plot_dv).to be_a Daru::View::Plot
129+
expect(plot_dv.chart).to be_a GoogleVisualr::Interactive::LineChart
130+
expect(plot_dv.data).to eq dv
131+
expect(plot_dv.options).to eq options
87132
end
88133
end
89134
end # initialize context end

0 commit comments

Comments
 (0)