all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Converting an Integer into Human Readable String
Date: Thu, 12 May 2011 14:30:28 -0500	[thread overview]
Message-ID: <8739kjzpgr.fsf@lifelogs.com> (raw)
In-Reply-To: 87tye4n6sr.fsf@lifelogs.com

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


      parent reply	other threads:[~2011-05-12 19:30 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-07 10:02 Converting an Integer into Human Readable String Nordlöw
2011-04-07 11:34 ` Deniz Dogan
2011-04-07 12:04   ` Eli Zaretskii
2011-04-07 11:52 ` Eli Zaretskii
2011-04-07 12:51 ` Drew Adams
2011-04-07 17:43   ` Eli Zaretskii
2011-04-07 18:13     ` Drew Adams
2011-04-07 18:35       ` Eli Zaretskii
2011-04-07 18:51         ` Drew Adams
2011-04-07 20:10           ` Eli Zaretskii
2011-04-07 18:44       ` Eli Zaretskii
2011-04-07 19:01         ` Thierry Volpiatto
     [not found]         ` <mailman.17.1302204476.27822.help-gnu-emacs@gnu.org>
2011-04-08  6:35           ` Klaus Straubinger
2011-04-08  7:07             ` Thierry Volpiatto
2011-04-08  8:29               ` Eli Zaretskii
2011-04-08  9:38                 ` Thierry Volpiatto
2011-04-08 11:41 ` Pascal J. Bourguignon
2011-04-08 15:19   ` Eli Zaretskii
2011-04-08 19:12     ` Thierry Volpiatto
2011-04-08 21:36       ` Eli Zaretskii
2011-04-09  5:24         ` Thierry Volpiatto
2011-04-09  8:46   ` Eli Zaretskii
     [not found]   ` <mailman.1.1302338931.20547.help-gnu-emacs@gnu.org>
2011-04-09  9:33     ` Pascal J. Bourguignon
2011-04-09 12:13       ` Eli Zaretskii
     [not found]       ` <mailman.0.1302351322.29796.help-gnu-emacs@gnu.org>
2011-04-11 15:31         ` Ted Zlatanov
2011-04-11 16:57           ` Eli Zaretskii
2011-05-12 19:30           ` Ted Zlatanov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8739kjzpgr.fsf@lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.