From 1497522ab0b84f39a04774b4a6a86dea32aa9a3e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 11 Jan 2005 22:06:05 +0000 Subject: Fixed the half applied 393 changeset git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@395 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/numeric_ext_test.rb | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 activesupport/test/core_ext/numeric_ext_test.rb (limited to 'activesupport/test/core_ext/numeric_ext_test.rb') diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb new file mode 100644 index 0000000000..6057c8f8c3 --- /dev/null +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -0,0 +1,42 @@ +require 'test/unit' +require File.dirname(__FILE__) + '/../../lib/core_ext/numeric' + +class NumericExtTimeTest < Test::Unit::TestCase + def setup + @now = Time.now + @seconds = { + 1.minute => 60, + 10.minutes => 600, + 1.hour + 15.minutes => 4500, + 2.days + 4.hours + 30.minutes => 189000, + 5.years + 1.month + 1.fortnight => 161481600 + } + end + + def test_time_units + @seconds.each do |actual, expected| + assert_equal expected, actual + assert_equal expected.since(@now), @now + actual + assert_equal expected.until(@now), @now - actual + end + end +end + +class NumericExtSizeTest < Test::Unit::TestCase + + def test_unit_in_terms_of_another + relationships = { + 1024.kilobytes => 1.megabyte, + 3584.0.kilobytes => 3.5.megabytes, + 3584.0.megabytes => 3.5.gigabytes, + 1.kilobyte ** 4 => 1.terabyte, + 1024.kilobytes + 2.megabytes => 3.megabytes, + 2.gigabytes / 4 => 512.megabytes, + 256.megabytes * 20 + 5.gigabytes => 10.gigabytes + } + + relationships.each do |left, right| + assert_equal right, left + end + end +end -- cgit v1.2.3