summary refs log tree commit diff stats
ModeNameSize
-rw-r--r--COPYING745log stats plain blame
-rw-r--r--README2404log stats plain blame
-rw-r--r--TODO2008log stats plain blame
-rwxr-xr-xall_tests.py409log stats plain blame
d---------doc107log stats plain
-rwxr-xr-xmake_doc.py693log stats plain blame
-rwxr-xr-xranger.py2142log stats plain blame
d---------ranger568log stats plain
d---------test446log stats plain
color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import unittest
from ranger.ext.human_readable import human_readable as hr

class HumanReadableTest(unittest.TestCase):
	def test_basic(self):
		self.assertEqual("0", hr(0))
		self.assertEqual("1 B", hr(1))
		self.assertEqual("1 K", hr(2 ** 10))
		self.assertEqual("1 M", hr(2 ** 20))
		self.assertEqual("1 G", hr(2 ** 30))
		self.assertEqual(">9000", hr(2 ** 100))

	def test_big(self):
		self.assertEqual("1023 G", hr(2 ** 30 * 1023))
		self.assertEqual("1024 G", hr(2 ** 40 - 1))
		self.assertEqual("1 T",    hr(2 ** 40))

	def test_small(self):
		self.assertEqual("1000 B", hr(1000))
		self.assertEqual("1.66 M", hr(1.66 * 2 ** 20))
		self.assertEqual("1.46 K", hr(1500))
		self.assertEqual("1.5 K",  hr(2 ** 10 + 2 ** 9))
		self.assertEqual("1.5 K",  hr(2 ** 10 + 2 ** 9 - 1))

	def test_no_exponent(self):
		for i in range(2 ** 10, 2 ** 20, 512):
			self.assertTrue('e' not in hr(i), "%d => %s" % (i, hr(i)))

if __name__ == '__main__':
	unittest.main()