-
Notifications
You must be signed in to change notification settings - Fork 20
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
76f2868
Improve test coverage for googlecharts.rb
Prakriti-nith 0a8833c
Verify data and options attribute
Prakriti-nith 809073a
Add test cases for GoogleCharts DataTable
Prakriti-nith e614c86
Reduce line length
Prakriti-nith 327e358
Optimized googlecharts_spec.rb
Prakriti-nith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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( | ||
@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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also verify the |
||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.