test/unit_test.rb in measured-2.0.0.pre1 vs test/unit_test.rb in measured-2.0.0.pre2

- old
+ new

@@ -1,11 +1,11 @@ require "test_helper" class Measured::UnitTest < ActiveSupport::TestCase setup do @unit = Measured::Unit.new(:Pie, value: "10 Cake") - @unit_with_aliases = Measured::Unit.new(:Pie, aliases: ["Cake", "Tart"]) + @unit_with_aliases = Measured::Unit.new(:Pie, aliases: %w(Cake Tart)) end test "#initialize converts the name to a string" do assert_equal "Pie", @unit.name end @@ -13,11 +13,11 @@ test "#initialize converts aliases to strings and makes a list of sorted names" do assert_equal %w(Cake pie sweets), Measured::Unit.new(:pie, aliases: ["Cake", :sweets]).names end test "#initialize parses out the unit and the number part" do - assert_equal BigDecimal(10), @unit.conversion_amount + assert_equal 10, @unit.conversion_amount assert_equal "Cake", @unit.conversion_unit unit = Measured::Unit.new(:pie, value: "5.5 sweets") assert_equal BigDecimal("5.5"), unit.conversion_amount assert_equal "sweets", unit.conversion_unit @@ -37,16 +37,16 @@ end end test "#to_s returns an expected string" do assert_equal "pie", Measured::Unit.new(:pie).to_s - assert_equal "pie (1/2 sweet)", Measured::Unit.new(:pie, aliases: ["cake"], value: [Rational(1,2), "sweet"]).to_s + assert_equal "pie (1/2 sweet)", Measured::Unit.new(:pie, aliases: ["cake"], value: "0.5 sweet").to_s end test "#inspect returns an expected string" do assert_equal "#<Measured::Unit: pie (pie) >", Measured::Unit.new(:pie).inspect - assert_equal "#<Measured::Unit: pie (cake, pie) 1/2 sweet>", Measured::Unit.new(:pie, aliases: ["cake"], value: [Rational(1,2), "sweet"]).inspect + assert_equal "#<Measured::Unit: pie (cake, pie) 1/2 sweet>", Measured::Unit.new(:pie, aliases: ["cake"], value: "1/2 sweet").inspect end test "includes Comparable mixin" do assert Measured::Unit.ancestors.include?(Comparable) end @@ -60,20 +60,20 @@ assert_equal 0, @unit <=> Measured::Unit.new(:Pie, value: "10 cake") assert_equal 0, @unit <=> Measured::Unit.new("Pie", value: "10 cake") assert_equal 0, @unit <=> Measured::Unit.new("Pie", value: [10, :cake]) end - test "#<=> is 1 for units with names that come after Pie lexicographically" do - assert_equal 1, @unit <=> Measured::Unit.new(:Pigs, value: "10 bacon") - assert_equal 1, @unit <=> Measured::Unit.new("Pig", aliases: %w(Pigs), value: "10 bacon") - assert_equal 1, @unit <=> Measured::Unit.new(:Pig, value: [11, :bacon]) + test "#<=> is -1 for units with names that come after Pie lexicographically" do + assert_equal -1, @unit <=> Measured::Unit.new(:Pigs, value: "10 bacon") + assert_equal -1, @unit <=> Measured::Unit.new("Pig", aliases: %w(Pigs), value: "10 bacon") end - - test "#inverse_conversion_amount returns 1/amount for BigDecimal" do - assert_equal BigDecimal(1) / 10, @unit.inverse_conversion_amount + + test "#<=> compares #conversion_amount when unit names the same" do + assert_equal -1, @unit <=> Measured::Unit.new(:Pie, value: [11, :pancake]) + assert_equal 0, @unit <=> Measured::Unit.new(:Pie, value: [10, :foo]) + assert_equal 1, @unit <=> Measured::Unit.new(:Pie, value: [9, :pancake]) end - test "#inverse_conversion_amount swaps the numerator and denominator for Rational" do - unit = Measured::Unit.new(:pie, value: [Rational(3, 7), "cake"]) - assert_equal Rational(7, 3), unit.inverse_conversion_amount + test "#inverse_conversion_amount returns 1/amount" do + assert_equal Rational(1, 10), @unit.inverse_conversion_amount end end