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

Tests for table.rb file #81

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/daru/view/plot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def adapter=(adapter)
#
# Daru::View.plotting_library = :highcharts
#
# To use a particular apdater in certain plot object(s), then user
# To use a particular adapter in certain plot object(s), then user
# must pass the adapter in `options` hash. e.g. `adapter: :highcharts`
#
def initialize(data=[], options={}, &block)
Expand Down
85 changes: 85 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
describe Daru::View::Table, 'Generating Table with Googlecharts library' do
context 'initialize with Googlecharts library' do
before do
Daru::View.table_library = :googlecharts
end
let(:options) {{width: 800, height: 720}}
let(:lib) { Daru::View.table_library }
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(:array) {[['col1', 'col2', 'col3'],[1, 2, 3]]}
let(:table_df) { Daru::View::Table.new(df, options) }
let(:table_dv) { Daru::View::Table.new(dv, options) }
let(:table_array) { Daru::View::Table.new(array, options) }

it 'check table library' do
expect(lib).to eq(:googlecharts)
end

it 'Googlecharts table using Array' do
expect(table_array).to be_a Daru::View::Table
expect(table_array.table).to be_a GoogleVisualr::DataTable
expect(table_array.options).to eq options
expect(table_array.data).to eq array
end

it 'Googlecharts table using DataFrame' do
expect(table_df).to be_a Daru::View::Table
expect(table_df.table).to be_a GoogleVisualr::DataTable
expect(table_df.options).to eq options
expect(table_df.data).to eq df
end

it 'Googlecharts table using Vector' do
expect(table_dv).to be_a Daru::View::Table
expect(table_dv.table).to be_a GoogleVisualr::DataTable
expect(table_dv.options).to eq options
expect(table_dv.data).to eq dv
end
end # initialize context end
end

describe Daru::View::Table, 'Generating Table with daru-data_tables library' do
context 'initialize with daru-data_tables library' do
before { Daru::View.table_library = :datatables }
let(:options) {{width: 800, height: 720}}
let(:lib) { Daru::View.table_library }
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(:table_df) { Daru::View::Table.new(df, options) }
let(:table_dv) { Daru::View::Table.new(dv, options) }
it 'check table library' do
expect(lib).to eq(:datatables)
end

it 'daru-data_tables table using DataFrame' do
expect(table_df).to be_a Daru::View::Table
expect(table_df.table).to be_a Daru::DataTables::DataTable
expect(table_df.options).to eq options
expect(table_df.data).to eq df
end

it 'daru-data_tables table using Vector' do
expect(table_dv).to be_a Daru::View::Table
expect(table_dv.table).to be_a Daru::DataTables::DataTable
expect(table_dv.options).to eq options
expect(table_dv.data).to eq dv
end
end # initialize context end
end