Commits

Konstantine Rybnikov  committed c028da8

Show bytes as just number.

  • Participants
  • Parent commits 22096ed

Comments (0)

Files changed (2)

File Duplicates/Utils.hs

 
 humanReadableFileSize :: Integer -> String
 humanReadableFileSize size =
-  humanReadableFileSize' (fromInteger size) ["", "K", "M", "G", "T"]
+  humanReadableFileSize' (fromInteger size) ["B", "K", "M", "G", "T"]
   where humanReadableFileSize' size [] = (prettyShowDouble size)
-        humanReadableFileSize' size labels =
+        humanReadableFileSize' size (l:ls) =
           if size < 1024.0 && size > -1024.0
-          then (prettyShowDouble size) ++ (head labels)
-          else humanReadableFileSize' (size / 1024) (tail labels)
+          then case l of
+            "B" -> show (truncate size)
+            _ -> (prettyShowDouble size) ++ l
+          else humanReadableFileSize' (size / 1024) ls

File tests/TestUtils.hs

 import Test.HUnit
 import Duplicates.Utils
 
+should_show_bytes =
+  TestCase (
+    assertEqual "should_show_bytes"
+    "32"
+    (humanReadableFileSize 32))
+
 should_show_kibibytes =
   TestCase (
     assertEqual "should_show_kibibytes"
     (humanReadableFileSize (ceiling $ 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1.8)))
 
 tests = TestList [
+  TestLabel "should_show_bytes" should_show_bytes,
   TestLabel "should_show_kibibytes" should_show_kibibytes,
   TestLabel "should_show_kibibytes_complex" should_show_kibibytes_complex,
   TestLabel "should_show_mebibytes" should_show_mebibytes,