PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_bytes.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 71 lines | 46 code | 20 blank | 5 comment | 0 complexity | eee1b409e002bd95c10164c58ada6148 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test lib/facets/bytes.rb
  2. require 'facets/bytes.rb'
  3. require 'test/unit'
  4. class TC_Numeric < Test::Unit::TestCase
  5. # bits
  6. def test_bits
  7. assert_equal( 8, 8.bits )
  8. end
  9. def test_kilobits
  10. assert_equal( 1024**1, 1.kilobit )
  11. end
  12. def test_megabits
  13. assert_equal( 1024**2, 1.megabit )
  14. end
  15. def test_gigabits
  16. assert_equal( 1024**3, 1.gigabit )
  17. end
  18. def test_terabits
  19. assert_equal( 1024**4, 1.terabit )
  20. end
  21. # bytes
  22. def test_bytes
  23. assert_equal( 8192, 1024.bytes )
  24. end
  25. def test_kilobytes
  26. assert_equal( 1024**1*8, 1.kilobyte )
  27. end
  28. def test_megabytes
  29. assert_equal( 1024**2*8, 1.megabyte )
  30. end
  31. def test_gigabytes
  32. assert_equal( 1024**3*8, 1.gigabyte )
  33. end
  34. def test_terabytes
  35. assert_equal( 1024**4*8, 1.terabyte )
  36. end
  37. # bits_to_s
  38. def test_strfbits
  39. assert_equal( "1.00 kb", 1024.strfbits )
  40. assert_equal( "1.00 mb", 1048576.strfbits )
  41. assert_equal( "1.00 gb", 1073741824.strfbits )
  42. assert_equal( "1.00 tb", 1099511627776.strfbits )
  43. end
  44. # bytes_to_s
  45. def test_strfbytes
  46. assert_equal( "1.00 KB", 1024.strfbytes )
  47. assert_equal( "1.00 MB", 1048576.strfbytes )
  48. assert_equal( "1.00 GB", 1073741824.strfbytes )
  49. assert_equal( "1.00 TB", 1099511627776.strfbytes )
  50. end
  51. end