From 76f2868785a7a442bea5ef055f5d1e82e381fb68 Mon Sep 17 00:00:00 2001 From: Prakriti Gupta Date: Mon, 26 Feb 2018 13:57:38 +0530 Subject: [PATCH 1/5] Improve test coverage for googlecharts.rb --- spec/adapters/googlecharts_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/adapters/googlecharts_spec.rb b/spec/adapters/googlecharts_spec.rb index 5d1637f..dd2d1be 100644 --- a/spec/adapters/googlecharts_spec.rb +++ b/spec/adapters/googlecharts_spec.rb @@ -30,5 +30,9 @@ 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 + end end end From 0a8833c224ee76c892d56977946ac87e5cc07a77 Mon Sep 17 00:00:00 2001 From: Prakriti Gupta Date: Tue, 27 Feb 2018 18:10:34 +0530 Subject: [PATCH 2/5] Verify data and options attribute --- spec/adapters/googlecharts_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/adapters/googlecharts_spec.rb b/spec/adapters/googlecharts_spec.rb index dd2d1be..47b51bb 100644 --- a/spec/adapters/googlecharts_spec.rb +++ b/spec/adapters/googlecharts_spec.rb @@ -33,6 +33,8 @@ 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 end end From 809073a5e78001550558fe33f7b2e38c6eabdffd Mon Sep 17 00:00:00 2001 From: Prakriti Gupta Date: Wed, 28 Feb 2018 17:51:03 +0530 Subject: [PATCH 3/5] Add test cases for GoogleCharts DataTable --- spec/adapters/googlecharts_spec.rb | 47 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/spec/adapters/googlecharts_spec.rb b/spec/adapters/googlecharts_spec.rb index 47b51bb..d60ccd8 100644 --- a/spec/adapters/googlecharts_spec.rb +++ b/spec/adapters/googlecharts_spec.rb @@ -3,14 +3,36 @@ 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 @@ -36,5 +58,26 @@ 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 end end From e614c868fc50defa26ba7cf98624567566e74171 Mon Sep 17 00:00:00 2001 From: Prakriti Gupta Date: Wed, 28 Feb 2018 19:41:22 +0530 Subject: [PATCH 4/5] Reduce line length --- spec/adapters/googlecharts_spec.rb | 63 ++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/spec/adapters/googlecharts_spec.rb b/spec/adapters/googlecharts_spec.rb index d60ccd8..682e73e 100644 --- a/spec/adapters/googlecharts_spec.rb +++ b/spec/adapters/googlecharts_spec.rb @@ -37,13 +37,20 @@ 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 @@ -54,27 +61,57 @@ 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(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).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 + 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 + 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) From 327e3587ece7201b5592f11d94351ba7e5ac120c Mon Sep 17 00:00:00 2001 From: Prakriti Gupta Date: Thu, 1 Mar 2018 17:54:39 +0530 Subject: [PATCH 5/5] Optimized googlecharts_spec.rb --- spec/adapters/googlecharts_spec.rb | 65 +++++++++--------------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/spec/adapters/googlecharts_spec.rb b/spec/adapters/googlecharts_spec.rb index 682e73e..33ab183 100644 --- a/spec/adapters/googlecharts_spec.rb +++ b/spec/adapters/googlecharts_spec.rb @@ -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'}, @@ -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], @@ -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( @@ -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)