diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/test/test_utils.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index 0be6f50eb..f533e3f90 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -48,6 +48,14 @@ class UtilTests < Homebrew::TestCase assert_predicate $?, :success? end + def test_pretty_duration + assert_equal "2 seconds", pretty_duration(1) + assert_equal "2 seconds", pretty_duration(2.5) + assert_equal "42 seconds", pretty_duration(42) + assert_equal "4.2 minutes", pretty_duration(252) + assert_equal "4.2 minutes", pretty_duration(252.45) + end + def test_plural assert_equal "", plural(1) assert_equal "s", plural(0) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index c874ec03c..b1a242044 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -140,7 +140,7 @@ end def pretty_duration(s) return "2 seconds" if s < 3 # avoids the plural problem ;) return "#{s.to_i} seconds" if s < 120 - "%.1f minutes" % (s/60) + "%.1f minutes" % (s/60.0) end def plural(n, s = "s") |
