Skip to content

Commit

Permalink
Optimized googlecharts_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakriti-nith committed Mar 1, 2018
1 parent e614c86 commit 327e358
Showing 1 changed file with 18 additions and 47 deletions.
65 changes: 18 additions & 47 deletions spec/adapters/googlecharts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
@data_vec2 = Daru::Vector.new([15 ,30, 40])
@data_df = Daru::DataFrame.new(arr1: @data_vec1, arr2: @data_vec2)
@options = {width: 800, height: 720}

@plot = Daru::View::Plot.new(@data_df, @options)

@data_hash = {
cols: [
{id: 'Name', label: 'Name', type: 'string'},
Expand All @@ -24,7 +22,6 @@
{c:[{v: 'Bob'}, {v: 7000, f: '$7,000'}, {v: true}]},
]
}

@data_array2 = [
['Galaxy', 'Distance', 'Brightness'],
['Canis Major Dwarf', 8000, 230.3],
Expand All @@ -33,12 +30,16 @@
['Lg. Magellanic Cloud', 50000, 120.9],
['Bootes I', 60000, 1223.1]
]
@table_array = Daru::View::Table.new(@data_array2, @options)
@table_dv = Daru::View::Table.new(@data_vec1, @options)
@table_df = Daru::View::Table.new(@data_df, @options)
@table_hash = Daru::View::Table.new(@data_hash, @options)
end

describe "initialization Charts" do
it "Default chart GoogleVisualr::Interactive::LineChart " do
expect(Daru::View::Plot.new.chart
).to be_a GoogleVisualr::Interactive::LineChart
expect(Daru::View::Plot.new.chart)
.to be_a GoogleVisualr::Interactive::LineChart
end
it "Bar chart GoogleVisualr::Interactive::BarChart " do
expect(Daru::View::Plot.new(
Expand All @@ -61,57 +62,27 @@
end
it "Table class must be GoogleVisualr::DataTable when data objects are" \
" of class Daru::Vector" do
expect(Daru::View::Table.new(
@data_vec1,
@options).table
).to be_a GoogleVisualr::DataTable
expect(Daru::View::Table.new(
@data_vec1,
@options).options
).to eq @options
expect(Daru::View::Table.new(
@data_vec1,
@options).data
).to eq @data_vec1
expect(@table_dv.table).to be_a GoogleVisualr::DataTable
expect(@table_dv.options).to eq @options
expect(@table_dv.data).to eq @data_vec1
end
it "Table class must be GoogleVisualr::DataTable when data objects are" \
" of class Daru::DataFrame" do
expect(Daru::View::Table.new(
@data_df,
@options).table
).to be_a GoogleVisualr::DataTable
expect(Daru::View::Table.new(@data_df, @options).options).to eq @options
expect(Daru::View::Table.new(@data_df, @options).data).to eq @data_df
expect(@table_df.table).to be_a GoogleVisualr::DataTable
expect(@table_df.options).to eq @options
expect(@table_df.data).to eq @data_df
end
it "Table class must be GoogleVisualr::DataTable when data objects are" \
" of class Array" do
expect(Daru::View::Table.new(
@data_array2,
@options).table
).to be_a GoogleVisualr::DataTable
expect(Daru::View::Table.new(
@data_array2,
@options).options
).to eq @options
expect(Daru::View::Table.new(
@data_array2,
@options).data
).to eq @data_array2
expect(@table_array.table).to be_a GoogleVisualr::DataTable
expect(@table_array.options).to eq @options
expect(@table_array.data).to eq @data_array2
end
it "Table class must be GoogleVisualr::DataTable when data objects are" \
" of class Hash" do
expect(Daru::View::Table.new(
@data_hash,
@options).table
).to be_a GoogleVisualr::DataTable
expect(Daru::View::Table.new(
@data_hash,
@options).options
).to eq @options
expect(Daru::View::Table.new(
@data_hash,
@options).data
).to eq @data_hash
expect(@table_hash.table).to be_a GoogleVisualr::DataTable
expect(@table_hash.options).to eq @options
expect(@table_hash.data).to eq @data_hash
end
it "Raise error when data objects are none of the above" do
expect{Daru::View::Table.new("daru")}.to raise_error(ArgumentError)
Expand Down

0 comments on commit 327e358

Please sign in to comment.