aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/numeric_ext_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 18:03:25 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:10:53 +0200
commita731125f12c5834de7eae3455fad63ea4d348034 (patch)
tree0ada76c652c1a2a1fd68cdbecf5adc2df6beeb51 /activesupport/test/core_ext/numeric_ext_test.rb
parentd66e7835bea9505f7003e5038aa19b6ea95ceea1 (diff)
downloadrails-a731125f12c5834de7eae3455fad63ea4d348034.tar.gz
rails-a731125f12c5834de7eae3455fad63ea4d348034.tar.bz2
rails-a731125f12c5834de7eae3455fad63ea4d348034.zip
applies new string literal convention in activesupport/test
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'activesupport/test/core_ext/numeric_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/numeric_ext_test.rb234
1 files changed, 117 insertions, 117 deletions
diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb
index 69c30a8a9e..793f34897c 100644
--- a/activesupport/test/core_ext/numeric_ext_test.rb
+++ b/activesupport/test/core_ext/numeric_ext_test.rb
@@ -1,7 +1,7 @@
-require 'abstract_unit'
-require 'active_support/time'
-require 'active_support/core_ext/numeric'
-require 'active_support/core_ext/integer'
+require "abstract_unit"
+require "active_support/time"
+require "active_support/core_ext/numeric"
+require "active_support/core_ext/integer"
class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase
def setup
@@ -158,9 +158,9 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("800 555 1212", 8005551212.to_s(:phone, :delimiter => " "))
assert_equal("(800) 555-1212 x 123", 8005551212.to_s(:phone, :area_code => true, :extension => 123))
assert_equal("800-555-1212", 8005551212.to_s(:phone, :extension => " "))
- assert_equal("555.1212", 5551212.to_s(:phone, :delimiter => '.'))
+ assert_equal("555.1212", 5551212.to_s(:phone, :delimiter => "."))
assert_equal("+1-800-555-1212", 8005551212.to_s(:phone, :country_code => 1))
- assert_equal("+18005551212", 8005551212.to_s(:phone, :country_code => 1, :delimiter => ''))
+ assert_equal("+18005551212", 8005551212.to_s(:phone, :country_code => 1, :delimiter => ""))
assert_equal("22-555-1212", 225551212.to_s(:phone))
assert_equal("+45-22-555-1212", 225551212.to_s(:phone, :country_code => 45))
end
@@ -199,7 +199,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("100%", 100.to_s(:percentage, :precision => 0))
assert_equal("302.06%", 302.0574.to_s(:percentage, :precision => 2))
assert_equal("123.4%", 123.400.to_s(:percentage, :precision => 3, :strip_insignificant_zeros => true))
- assert_equal("1.000,000%", 1000.to_s(:percentage, :delimiter => '.', :separator => ','))
+ assert_equal("1.000,000%", 1000.to_s(:percentage, :delimiter => ".", :separator => ","))
assert_equal("1000.000 %", 1000.to_s(:percentage, :format => "%n %"))
end
@@ -216,16 +216,16 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
end
def test_to_s__delimited__with_options_hash
- assert_equal '12 345 678', 12345678.to_s(:delimited, :delimiter => ' ')
- assert_equal '12,345,678-05', 12345678.05.to_s(:delimited, :separator => '-')
- assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :separator => ',', :delimiter => '.')
- assert_equal '12.345.678,05', 12345678.05.to_s(:delimited, :delimiter => '.', :separator => ',')
+ assert_equal "12 345 678", 12345678.to_s(:delimited, :delimiter => " ")
+ assert_equal "12,345,678-05", 12345678.05.to_s(:delimited, :separator => "-")
+ assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, :separator => ",", :delimiter => ".")
+ assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, :delimiter => ".", :separator => ",")
end
def test_to_s__rounded_with_custom_delimiter_and_separator
- assert_equal '31,83', 31.825.to_s(:rounded, :precision => 2, :separator => ',')
- assert_equal '1.231,83', 1231.825.to_s(:rounded, :precision => 2, :separator => ',', :delimiter => '.')
+ assert_equal "31,83", 31.825.to_s(:rounded, :precision => 2, :separator => ",")
+ assert_equal "1.231,83", 1231.825.to_s(:rounded, :precision => 2, :separator => ",", :delimiter => ".")
end
def test_to_s__rounded__with_significant_digits
@@ -264,133 +264,133 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
end
def test_to_s__human_size
- assert_equal '0 Bytes', 0.to_s(:human_size)
- assert_equal '1 Byte', 1.to_s(:human_size)
- assert_equal '3 Bytes', 3.14159265.to_s(:human_size)
- assert_equal '123 Bytes', 123.0.to_s(:human_size)
- assert_equal '123 Bytes', 123.to_s(:human_size)
- assert_equal '1.21 KB', 1234.to_s(:human_size)
- assert_equal '12.1 KB', 12345.to_s(:human_size)
- assert_equal '1.18 MB', 1234567.to_s(:human_size)
- assert_equal '1.15 GB', 1234567890.to_s(:human_size)
- assert_equal '1.12 TB', 1234567890123.to_s(:human_size)
- assert_equal '1.1 PB', 1234567890123456.to_s(:human_size)
- assert_equal '1.07 EB', 1234567890123456789.to_s(:human_size)
- assert_equal '1030 EB', exabytes(1026).to_s(:human_size)
- assert_equal '444 KB', kilobytes(444).to_s(:human_size)
- assert_equal '1020 MB', megabytes(1023).to_s(:human_size)
- assert_equal '3 TB', terabytes(3).to_s(:human_size)
- assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2)
- assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4)
- assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2)
- assert_equal '1.01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4)
- assert_equal '10 KB', kilobytes(10.000).to_s(:human_size, :precision => 4)
- assert_equal '1 Byte', 1.1.to_s(:human_size)
- assert_equal '10 Bytes', 10.to_s(:human_size)
+ assert_equal "0 Bytes", 0.to_s(:human_size)
+ assert_equal "1 Byte", 1.to_s(:human_size)
+ assert_equal "3 Bytes", 3.14159265.to_s(:human_size)
+ assert_equal "123 Bytes", 123.0.to_s(:human_size)
+ assert_equal "123 Bytes", 123.to_s(:human_size)
+ assert_equal "1.21 KB", 1234.to_s(:human_size)
+ assert_equal "12.1 KB", 12345.to_s(:human_size)
+ assert_equal "1.18 MB", 1234567.to_s(:human_size)
+ assert_equal "1.15 GB", 1234567890.to_s(:human_size)
+ assert_equal "1.12 TB", 1234567890123.to_s(:human_size)
+ assert_equal "1.1 PB", 1234567890123456.to_s(:human_size)
+ assert_equal "1.07 EB", 1234567890123456789.to_s(:human_size)
+ assert_equal "1030 EB", exabytes(1026).to_s(:human_size)
+ assert_equal "444 KB", kilobytes(444).to_s(:human_size)
+ assert_equal "1020 MB", megabytes(1023).to_s(:human_size)
+ assert_equal "3 TB", terabytes(3).to_s(:human_size)
+ assert_equal "1.2 MB", 1234567.to_s(:human_size, :precision => 2)
+ assert_equal "3 Bytes", 3.14159265.to_s(:human_size, :precision => 4)
+ assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, :precision => 2)
+ assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, :precision => 4)
+ assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, :precision => 4)
+ assert_equal "1 Byte", 1.1.to_s(:human_size)
+ assert_equal "10 Bytes", 10.to_s(:human_size)
end
def test_to_s__human_size_with_si_prefix
assert_deprecated do
- assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :prefix => :si)
- assert_equal '123 Bytes', 123.0.to_s(:human_size, :prefix => :si)
- assert_equal '123 Bytes', 123.to_s(:human_size, :prefix => :si)
- assert_equal '1.23 KB', 1234.to_s(:human_size, :prefix => :si)
- assert_equal '12.3 KB', 12345.to_s(:human_size, :prefix => :si)
- assert_equal '1.23 MB', 1234567.to_s(:human_size, :prefix => :si)
- assert_equal '1.23 GB', 1234567890.to_s(:human_size, :prefix => :si)
- assert_equal '1.23 TB', 1234567890123.to_s(:human_size, :prefix => :si)
- assert_equal '1.23 PB', 1234567890123456.to_s(:human_size, :prefix => :si)
- assert_equal '1.23 EB', 1234567890123456789.to_s(:human_size, :prefix => :si)
+ assert_equal "3 Bytes", 3.14159265.to_s(:human_size, :prefix => :si)
+ assert_equal "123 Bytes", 123.0.to_s(:human_size, :prefix => :si)
+ assert_equal "123 Bytes", 123.to_s(:human_size, :prefix => :si)
+ assert_equal "1.23 KB", 1234.to_s(:human_size, :prefix => :si)
+ assert_equal "12.3 KB", 12345.to_s(:human_size, :prefix => :si)
+ assert_equal "1.23 MB", 1234567.to_s(:human_size, :prefix => :si)
+ assert_equal "1.23 GB", 1234567890.to_s(:human_size, :prefix => :si)
+ assert_equal "1.23 TB", 1234567890123.to_s(:human_size, :prefix => :si)
+ assert_equal "1.23 PB", 1234567890123456.to_s(:human_size, :prefix => :si)
+ assert_equal "1.23 EB", 1234567890123456789.to_s(:human_size, :prefix => :si)
end
end
def test_to_s__human_size_with_options_hash
- assert_equal '1.2 MB', 1234567.to_s(:human_size, :precision => 2)
- assert_equal '3 Bytes', 3.14159265.to_s(:human_size, :precision => 4)
- assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2)
- assert_equal '1.01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4)
- assert_equal '10 KB', kilobytes(10.000).to_s(:human_size, :precision => 4)
- assert_equal '1 TB', 1234567890123.to_s(:human_size, :precision => 1)
- assert_equal '500 MB', 524288000.to_s(:human_size, :precision=>3)
- assert_equal '10 MB', 9961472.to_s(:human_size, :precision=>0)
- assert_equal '40 KB', 41010.to_s(:human_size, :precision => 1)
- assert_equal '40 KB', 41100.to_s(:human_size, :precision => 2)
- assert_equal '1.0 KB', kilobytes(1.0123).to_s(:human_size, :precision => 2, :strip_insignificant_zeros => false)
- assert_equal '1.012 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :significant => false)
- assert_equal '1 KB', kilobytes(1.0123).to_s(:human_size, :precision => 0, :significant => true) #ignores significant it precision is 0
+ assert_equal "1.2 MB", 1234567.to_s(:human_size, :precision => 2)
+ assert_equal "3 Bytes", 3.14159265.to_s(:human_size, :precision => 4)
+ assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, :precision => 2)
+ assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, :precision => 4)
+ assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, :precision => 4)
+ assert_equal "1 TB", 1234567890123.to_s(:human_size, :precision => 1)
+ assert_equal "500 MB", 524288000.to_s(:human_size, :precision=>3)
+ assert_equal "10 MB", 9961472.to_s(:human_size, :precision=>0)
+ assert_equal "40 KB", 41010.to_s(:human_size, :precision => 1)
+ assert_equal "40 KB", 41100.to_s(:human_size, :precision => 2)
+ assert_equal "1.0 KB", kilobytes(1.0123).to_s(:human_size, :precision => 2, :strip_insignificant_zeros => false)
+ assert_equal "1.012 KB", kilobytes(1.0123).to_s(:human_size, :precision => 3, :significant => false)
+ assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, :precision => 0, :significant => true) #ignores significant it precision is 0
end
def test_to_s__human_size_with_custom_delimiter_and_separator
- assert_equal '1,01 KB', kilobytes(1.0123).to_s(:human_size, :precision => 3, :separator => ',')
- assert_equal '1,01 KB', kilobytes(1.0100).to_s(:human_size, :precision => 4, :separator => ',')
- assert_equal '1.000,1 TB', terabytes(1000.1).to_s(:human_size, :precision => 5, :delimiter => '.', :separator => ',')
+ assert_equal "1,01 KB", kilobytes(1.0123).to_s(:human_size, :precision => 3, :separator => ",")
+ assert_equal "1,01 KB", kilobytes(1.0100).to_s(:human_size, :precision => 4, :separator => ",")
+ assert_equal "1.000,1 TB", terabytes(1000.1).to_s(:human_size, :precision => 5, :delimiter => ".", :separator => ",")
end
def test_number_to_human
- assert_equal '-123', -123.to_s(:human)
- assert_equal '-0.5', -0.5.to_s(:human)
- assert_equal '0', 0.to_s(:human)
- assert_equal '0.5', 0.5.to_s(:human)
- assert_equal '123', 123.to_s(:human)
- assert_equal '1.23 Thousand', 1234.to_s(:human)
- assert_equal '12.3 Thousand', 12345.to_s(:human)
- assert_equal '1.23 Million', 1234567.to_s(:human)
- assert_equal '1.23 Billion', 1234567890.to_s(:human)
- assert_equal '1.23 Trillion', 1234567890123.to_s(:human)
- assert_equal '1.23 Quadrillion', 1234567890123456.to_s(:human)
- assert_equal '1230 Quadrillion', 1234567890123456789.to_s(:human)
- assert_equal '490 Thousand', 489939.to_s(:human, :precision => 2)
- assert_equal '489.9 Thousand', 489939.to_s(:human, :precision => 4)
- assert_equal '489 Thousand', 489000.to_s(:human, :precision => 4)
- assert_equal '489.0 Thousand', 489000.to_s(:human, :precision => 4, :strip_insignificant_zeros => false)
- assert_equal '1.2346 Million', 1234567.to_s(:human, :precision => 4, :significant => false)
- assert_equal '1,2 Million', 1234567.to_s(:human, :precision => 1, :significant => false, :separator => ',')
- assert_equal '1 Million', 1234567.to_s(:human, :precision => 0, :significant => true, :separator => ',') #significant forced to false
+ assert_equal "-123", -123.to_s(:human)
+ assert_equal "-0.5", -0.5.to_s(:human)
+ assert_equal "0", 0.to_s(:human)
+ assert_equal "0.5", 0.5.to_s(:human)
+ assert_equal "123", 123.to_s(:human)
+ assert_equal "1.23 Thousand", 1234.to_s(:human)
+ assert_equal "12.3 Thousand", 12345.to_s(:human)
+ assert_equal "1.23 Million", 1234567.to_s(:human)
+ assert_equal "1.23 Billion", 1234567890.to_s(:human)
+ assert_equal "1.23 Trillion", 1234567890123.to_s(:human)
+ assert_equal "1.23 Quadrillion", 1234567890123456.to_s(:human)
+ assert_equal "1230 Quadrillion", 1234567890123456789.to_s(:human)
+ assert_equal "490 Thousand", 489939.to_s(:human, :precision => 2)
+ assert_equal "489.9 Thousand", 489939.to_s(:human, :precision => 4)
+ assert_equal "489 Thousand", 489000.to_s(:human, :precision => 4)
+ assert_equal "489.0 Thousand", 489000.to_s(:human, :precision => 4, :strip_insignificant_zeros => false)
+ assert_equal "1.2346 Million", 1234567.to_s(:human, :precision => 4, :significant => false)
+ assert_equal "1,2 Million", 1234567.to_s(:human, :precision => 1, :significant => false, :separator => ",")
+ assert_equal "1 Million", 1234567.to_s(:human, :precision => 0, :significant => true, :separator => ",") #significant forced to false
end
def test_number_to_human_with_custom_units
#Only integers
volume = {:unit => "ml", :thousand => "lt", :million => "m3"}
- assert_equal '123 lt', 123456.to_s(:human, :units => volume)
- assert_equal '12 ml', 12.to_s(:human, :units => volume)
- assert_equal '1.23 m3', 1234567.to_s(:human, :units => volume)
+ assert_equal "123 lt", 123456.to_s(:human, :units => volume)
+ assert_equal "12 ml", 12.to_s(:human, :units => volume)
+ assert_equal "1.23 m3", 1234567.to_s(:human, :units => volume)
#Including fractionals
distance = {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"}
- assert_equal '1.23 mm', 0.00123.to_s(:human, :units => distance)
- assert_equal '1.23 cm', 0.0123.to_s(:human, :units => distance)
- assert_equal '1.23 dm', 0.123.to_s(:human, :units => distance)
- assert_equal '1.23 m', 1.23.to_s(:human, :units => distance)
- assert_equal '1.23 dam', 12.3.to_s(:human, :units => distance)
- assert_equal '1.23 hm', 123.to_s(:human, :units => distance)
- assert_equal '1.23 km', 1230.to_s(:human, :units => distance)
- assert_equal '1.23 km', 1230.to_s(:human, :units => distance)
- assert_equal '1.23 km', 1230.to_s(:human, :units => distance)
- assert_equal '12.3 km', 12300.to_s(:human, :units => distance)
+ assert_equal "1.23 mm", 0.00123.to_s(:human, :units => distance)
+ assert_equal "1.23 cm", 0.0123.to_s(:human, :units => distance)
+ assert_equal "1.23 dm", 0.123.to_s(:human, :units => distance)
+ assert_equal "1.23 m", 1.23.to_s(:human, :units => distance)
+ assert_equal "1.23 dam", 12.3.to_s(:human, :units => distance)
+ assert_equal "1.23 hm", 123.to_s(:human, :units => distance)
+ assert_equal "1.23 km", 1230.to_s(:human, :units => distance)
+ assert_equal "1.23 km", 1230.to_s(:human, :units => distance)
+ assert_equal "1.23 km", 1230.to_s(:human, :units => distance)
+ assert_equal "12.3 km", 12300.to_s(:human, :units => distance)
#The quantifiers don't need to be a continuous sequence
gangster = {:hundred => "hundred bucks", :million => "thousand quids"}
- assert_equal '1 hundred bucks', 100.to_s(:human, :units => gangster)
- assert_equal '25 hundred bucks', 2500.to_s(:human, :units => gangster)
- assert_equal '25 thousand quids', 25000000.to_s(:human, :units => gangster)
- assert_equal '12300 thousand quids', 12345000000.to_s(:human, :units => gangster)
+ assert_equal "1 hundred bucks", 100.to_s(:human, :units => gangster)
+ assert_equal "25 hundred bucks", 2500.to_s(:human, :units => gangster)
+ assert_equal "25 thousand quids", 25000000.to_s(:human, :units => gangster)
+ assert_equal "12300 thousand quids", 12345000000.to_s(:human, :units => gangster)
#Spaces are stripped from the resulting string
- assert_equal '4', 4.to_s(:human, :units => {:unit => "", :ten => 'tens '})
- assert_equal '4.5 tens', 45.to_s(:human, :units => {:unit => "", :ten => ' tens '})
+ assert_equal "4", 4.to_s(:human, :units => {:unit => "", :ten => "tens "})
+ assert_equal "4.5 tens", 45.to_s(:human, :units => {:unit => "", :ten => " tens "})
end
def test_number_to_human_with_custom_format
- assert_equal '123 times Thousand', 123456.to_s(:human, :format => "%n times %u")
+ assert_equal "123 times Thousand", 123456.to_s(:human, :format => "%n times %u")
volume = {:unit => "ml", :thousand => "lt", :million => "m3"}
- assert_equal '123.lt', 123456.to_s(:human, :units => volume, :format => "%n.%u")
+ assert_equal "123.lt", 123456.to_s(:human, :units => volume, :format => "%n.%u")
end
def test_to_s__injected_on_proper_types
- assert_equal '1.23 Thousand', 1230.to_s(:human)
- assert_equal '1.23 Thousand', Float(1230).to_s(:human)
- assert_equal '100000 Quadrillion', (100**10).to_s(:human)
- assert_equal '1 Million', BigDecimal("1000010").to_s(:human)
+ assert_equal "1.23 Thousand", 1230.to_s(:human)
+ assert_equal "1.23 Thousand", Float(1230).to_s(:human)
+ assert_equal "100000 Quadrillion", (100**10).to_s(:human)
+ assert_equal "1 Million", BigDecimal("1000010").to_s(:human)
end
def test_to_formatted_s_is_deprecated
@@ -400,23 +400,23 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
end
def test_to_s_with_invalid_formatter
- assert_equal '123', 123.to_s(:invalid)
- assert_equal '2.5', 2.5.to_s(:invalid)
- assert_equal '100000000000000000000', (100**10).to_s(:invalid)
- assert_equal '1000010.0', BigDecimal("1000010").to_s(:invalid)
+ assert_equal "123", 123.to_s(:invalid)
+ assert_equal "2.5", 2.5.to_s(:invalid)
+ assert_equal "100000000000000000000", (100**10).to_s(:invalid)
+ assert_equal "1000010.0", BigDecimal("1000010").to_s(:invalid)
end
def test_default_to_s
- assert_equal '123', 123.to_s
- assert_equal '1111011', 123.to_s(2)
+ assert_equal "123", 123.to_s
+ assert_equal "1111011", 123.to_s(2)
- assert_equal '2.5', 2.5.to_s
+ assert_equal "2.5", 2.5.to_s
- assert_equal '100000000000000000000', (100**10).to_s
- assert_equal '1010110101111000111010111100010110101100011000100000000000000000000', (100**10).to_s(2)
+ assert_equal "100000000000000000000", (100**10).to_s
+ assert_equal "1010110101111000111010111100010110101100011000100000000000000000000", (100**10).to_s(2)
- assert_equal '1000010.0', BigDecimal("1000010").to_s
- assert_equal '10000 10.0', BigDecimal("1000010").to_s('5F')
+ assert_equal "1000010.0", BigDecimal("1000010").to_s
+ assert_equal "10000 10.0", BigDecimal("1000010").to_s("5F")
end
def test_in_milliseconds