"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/grouping_test.rb" between
ruport-1.7.1.tar.gz and ruport-1.8.0.tar.gz

About: Ruport (Ruby Reports) is a simple, extensible reporting system built for Rubyists. It provides tools for data acquisition, database interaction, formatting, and parsing/munging.

grouping_test.rb  (ruport-1.7.1):grouping_test.rb  (ruport-1.8.0)
skipping to change at line 269 skipping to change at line 269
assert_equal [], expected.column_names - actual.column_names assert_equal [], expected.column_names - actual.column_names
end end
def test_grouping_sigma def test_grouping_sigma
assert_respond_to @grouping, :sigma assert_respond_to @grouping, :sigma
assert_respond_to @grouping, :sum assert_respond_to @grouping, :sum
expected = {} expected = {}
@grouping.data[@grouping.data.keys.first].column_names.each do |col| @grouping.data[@grouping.data.keys.first].column_names.each do |col|
expected[col] = @grouping.inject(0) do |s, (group_name, group)| expected[col] = @grouping.inject(0) do |s, (_group_name, group)|
s + group.sigma(col) s + group.sigma(col)
end end
end end
expected.keys.each do |col| expected.keys.each do |col|
assert_equal expected[col], @grouping.sigma(col) assert_equal expected[col], @grouping.sigma(col)
end end
expected = {} expected = {}
@grouping.data[@grouping.data.keys.first].column_names.each do |col| @grouping.data[@grouping.data.keys.first].column_names.each do |col|
expected[col] = @grouping.inject(0) do |s, (group_name, group)| expected[col] = @grouping.inject(0) do |s, (_group_name, group)|
s + group.sigma {|r| r[col] + 2 } s + group.sigma {|r| r[col] + 2 }
end end
end end
expected.keys.each do |col| expected.keys.each do |col|
assert_equal expected[col], @grouping.sigma {|r| r[col] + 2 } assert_equal expected[col], @grouping.sigma {|r| r[col] + 2 }
end end
end end
describe "when sorting groupings" do describe "when sorting groupings" do
def setup def setup
@table = Ruport.Table(%w[a b c]) << ["dog",1,2] << ["cat",3,5] << @table = Ruport.Table(%w[a b c]) << ["dog",1,2] << ["cat",3,5] <<
["banana",8,1] << ["dog",5,6] << ["dog",2,4] << ["banana",7,9] ["banana",8,1] << ["dog",5,6] << ["dog",2,4] << ["banana",7,9]
end end
def specify_can_set_by_group_name_order_in_constructor def test_specify_can_set_by_group_name_order_in_constructor
a = Grouping(@table, :by => "a", :order => :name) a = Grouping(@table, :by => "a", :order => :name)
names = %w[banana cat dog] names = %w[banana cat dog]
data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ] data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ]
a.each do |name,group| a.each do |name,group|
assert_equal names.shift, name assert_equal names.shift, name
assert_equal data.shift, group.map { |r| r.to_a } assert_equal data.shift, group.map { |r| r.to_a }
end end
end end
def specify_can_set_by_proc_ordering_in_constructor def test_specify_can_set_by_proc_ordering_in_constructor
a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } ) a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
names = %w[dog banana cat] names = %w[dog banana cat]
data = [ [[1,2],[5,6],[2,4]], [[8,1],[7,9]], [[3,5]] ] data = [ [[1,2],[5,6],[2,4]], [[8,1],[7,9]], [[3,5]] ]
a.each do |name,group| a.each do |name,group|
assert_equal names.shift, name assert_equal names.shift, name
assert_equal data.shift, group.map { |r| r.to_a } assert_equal data.shift, group.map { |r| r.to_a }
end end
end end
def specify_can_override_sorting def test_specify_can_override_sorting
a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } ) a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
a.sort_grouping_by!(:name) a.sort_grouping_by!(:name)
names = %w[banana cat dog] names = %w[banana cat dog]
data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ] data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ]
a.each do |name,group| a.each do |name,group|
assert_equal names.shift, name assert_equal names.shift, name
assert_equal data.shift, group.map { |r| r.to_a } assert_equal data.shift, group.map { |r| r.to_a }
end end
end end
def specify_can_get_a_new_sorted_grouping def test_specify_can_get_a_new_sorted_grouping
a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } ) a = Grouping(@table, :by => "a", :order => lambda { |g| -g.length } )
b = a.sort_grouping_by(:name) b = a.sort_grouping_by(:name)
names = %w[banana cat dog] names = %w[banana cat dog]
data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ] data = [ [[8,1],[7,9]], [[3,5]], [[1,2],[5,6],[2,4]] ]
b.each do |name,group| b.each do |name,group|
assert_equal names.shift, name assert_equal names.shift, name
assert_equal data.shift, group.map { |r| r.to_a } assert_equal data.shift, group.map { |r| r.to_a }
end end
 End of changes. 6 change blocks. 
6 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)