Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coverage for googlecharts.rb file #80

Merged
merged 5 commits into from
Mar 1, 2018
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 91 additions & 5 deletions spec/adapters/googlecharts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,54 @@
describe Daru::View::Plot, 'plotting with googlecharts' do
before { Daru::View.plotting_library = :googlecharts }
before(:each) do
@data_array = [[1, 15], [2, 30], [4, 40]]
@data_array1 = [[1, 15], [2, 30], [4, 40]]
@data_vec1 = Daru::Vector.new([1 ,2, 4])
@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'},
{id: 'Salary', label: 'Salary', type: 'number'},
{type: 'boolean', label: 'Full Time Employee' },
],
rows: [
{c:[{v: 'Mike'}, {v: 10000, f: '$10,000'}, {v: true}]},
{c:[{v: 'Jim'}, {v:8000, f: '$8,000'}, {v: false}]},
{c:[{v: 'Alice'}, {v: 12500, f: '$12,500'}, {v: true}]},
{c:[{v: 'Bob'}, {v: 7000, f: '$7,000'}, {v: true}]},
]
}

@data_array2 = [
['Galaxy', 'Distance', 'Brightness'],
['Canis Major Dwarf', 8000, 230.3],
['Sagittarius Dwarf', 24000, 4000.5],
['Ursa Major II Dwarf', 30000, 1412.3],
['Lg. Magellanic Cloud', 50000, 120.9],
['Bootes I', 60000, 1223.1]
]
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([], type: :bar).chart).to be_a GoogleVisualr::Interactive::BarChart
expect(Daru::View::Plot.new(
[],
type: :bar).chart
).to be_a GoogleVisualr::Interactive::BarChart
end
it "Column chart GoogleVisualr::Interactive::ColumnChart " do
expect(Daru::View::Plot.new([], type: :column).chart).to be_a GoogleVisualr::Interactive::ColumnChart
expect(Daru::View::Plot.new(
[],
type: :column).chart
).to be_a GoogleVisualr::Interactive::ColumnChart
end
# TODO: all other kinds of charts
end
Expand All @@ -30,5 +59,62 @@
it "Table class must be GoogleVisualr::DataTable " do
expect(Daru::View::Table.new.table).to be_a GoogleVisualr::DataTable
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
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
end
it "Table class must be GoogleVisualr::DataTable when data objects are" \
" of class Array" do
expect(Daru::View::Table.new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't better to put Daru::View::Table.new(@data_array2,@ options) into one variable and use it in next 2 line rather than executing it again and again? Follow it in all cases.

@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
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
end
it "Raise error when data objects are none of the above" do
expect{Daru::View::Table.new("daru")}.to raise_error(ArgumentError)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also verify the data and options attribute in Daru::View::Table class.

end
end