help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting an Integer into Human Readable String


From: Ted Zlatanov
Subject: Re: Converting an Integer into Human Readable String
Date: Thu, 12 May 2011 14:30:28 -0500
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux)

On Mon, 11 Apr 2011 10:31:32 -0500 Ted Zlatanov <tzz@lifelogs.com> wrote: 

TZ> On Sat, 09 Apr 2011 15:13:16 +0300 Eli Zaretskii <eliz@gnu.org> wrote: 
EZ> Well, my contribution is now in files.el ;-)

TZ> Could you add the corresponding ERT tests, using the ad-hoc tests Pascal
TZ> already provided but converting to should/should-not as needed?

Eli, here's a test you can put in test/automated/ if you like it.

Please look at the 'si output for 1024000000 vs. 1000000000.  Is is
supposed to be 1G for both?  It's correct according to the code but it
seems like if there's just one significant figure before the decimal
point we want to show 1.02G or 1.024G.

Ted

#+begin_src lisp
(require 'ert)
(require 'files)

(ert-deftest files-file-size-human-readable ()
  "Test the `file-size-human-readable' function in files.el"
  (dolist (test '((123456789012 "115.0G" "123.5G" "115.0GiB")
                  (1024000000 "976.6M" "1G" "976.6MiB")
                  (1000000000 "953.7M" "1G" "953.7MiB")
                  (102400000 "97.7M" "102.4M" "97.7MiB")
                  (100000000 "95.4M" "100M" "95.4MiB")
                  (10240000 "9.8M" "10.2M" "9.8MiB")
                  (10000000 "9.5M" "10M" "9.5MiB")
                  (1024000 "1000k" "1M" "1000KiB")
                  (1000000 "976.6k" "1M" "976.6KiB")
                  (100000 "97.7k" "100k" "97.7KiB")
                  (65536 "64k" "65.5k" "64KiB")
                  (0 "0" "0" "0iB")
                  (900 "900" "900" "900iB")
                  (1023 "1023" "1k" "1023iB")))
    (let ((n (nth 0 test))
          (s (nth 1 test))
          (si (nth 2 test))
          (iec (nth 3 test)))
      (message "testing regular conversion of %s" n)
      (should (string-equal s (file-size-human-readable n)))
      (message "testing SI conversion of %s" n)
      (should (string-equal si (file-size-human-readable n 'si)))
      (message "testing IEC conversion of %s" n)
      (should (string-equal iec (file-size-human-readable n 'iec))))))

#+end_src


reply via email to

[Prev in Thread] Current Thread [Next in Thread]