Permalink
Browse files

encode 0 with a max of 0 with all encoding types

  • Loading branch information...
1 parent 248fd24 commit 412b6cb26f6449c8f7b04b28dbae28213179658a @raykrueger raykrueger committed Mar 5, 2010
Showing with 11 additions and 3 deletions.
  1. +2 −2 lib/google_chart.rb
  2. +9 −1 spec/gchartrb_spec.rb
View
@@ -24,10 +24,10 @@ def encode(encoding, n, max)
case encoding
when :simple
return "_" if n.nil?
- SIMPLE_CHARS[((n/max.to_f) * (SIMPLE_CHARS.size - 1)).round]
+ SIMPLE_CHARS[((n.zero? ? 0 : n/max.to_f) * (SIMPLE_CHARS.size - 1)).round]
when :text
return "-1" if n.nil?
- ((((n/max.to_f) * 1000.0).round)/10.0).to_s
+ ((((n.zero? ? 0 : n/max.to_f) * 1000.0).round)/10.0).to_s
when :extended
return "__" if n.nil?
EXTENDED_PAIRS[max.zero? ? 0 : ((n/max.to_f) * (EXTENDED_PAIRS.size - 1)).round]
View
@@ -111,7 +111,15 @@ class <<self ; public :new ; end
GoogleChart.encode(:extended, nil, 1).should == "__"
end
- it "encodes 0 with a max of 0 correctly" do
+ it "encodes 0 with a max of 0 correctly using extended" do
GoogleChart.encode(:extended, 0, 0).should == "AA"
end
+
+ it "encodes 0 with a max of 0 correctly using simple" do
+ GoogleChart.encode(:simple, 0, 0).should == "A"
+ end
+
+ it "encodes 0 with a max of 0 correctly using text" do
+ GoogleChart.encode(:text, 0, 0).should == "0.0"
+ end
end

0 comments on commit 412b6cb

Please sign in to comment.