Permalink
Browse files

including density tests in repo

  • Loading branch information...
1 parent 4130e54 commit 64e4abd925013b5c973b5d48af665149a0cfaccb @shenry shenry committed Dec 2, 2010
Showing with 14 additions and 0 deletions.
  1. +14 −0 test/alchemist_test.rb
@@ -3,6 +3,14 @@
require 'test/unit'
require 'alchemist'
+class Float
+ # truncates float to specified decimal places
+ def truncate(dec = 0)
+ return to_i if dec == 0
+ sprintf("%.#{dec}f", self).to_f
+ end
+end
+
class AlchemistTest < Test::Unit::TestCase
def test_equivalence
@@ -69,4 +77,10 @@ def test_temperature
assert_in_delta(1.fahrenheit, 1.fahrenheit.to.fahrenheit, 1e-5)
end
+ def test_density
+ assert_equal(25.brix.to_f, 1.1058.sg.to.brix.truncate(1))
+ assert_equal(25.brix, 13.87.baume.truncate(1))
+ assert_equal(25.plato, 25.125.brix)
+ end
+
end

0 comments on commit 64e4abd

Please sign in to comment.