Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tests for the sum column

  • Loading branch information...
commit c25f1cdab45e568123bc85dce411281e05697216 1 parent b665326
Brad Seefeld authored
View
2  lib/rgviz/data_table/query_executor.rb
@@ -51,6 +51,8 @@ def self.execute(rows, query)
rows
end
+ protected
+
##
# Execute the select statements against the rows. This potentially removes columns from
# the result set.
View
22 spec/rgviz/data_table/sum_column_spec.rb
@@ -0,0 +1,22 @@
+require "spec_helper"
+
+describe Rgviz::DataTable::SumColumn do
+
+ before(:each) do
+ @col = Rgviz::DataTable::SumColumn.new("a", "sum(a)")
+ end
+
+ it "finds the sum" do
+ rows = [{"a" => 1}, {"a" => 3}, {"a" => 1}]
+ @col.evaluate(rows).should == 5
+ end
+
+ it "returns zero when no rows given" do
+ @col.evaluate([]).should == 0
+ end
+
+ it "returns zero when column does not exist" do
+ rows = [{"b" => 1}, {"b" => 3}, {"b" => 1}]
+ @col.evaluate(rows).should == 0
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.