aboutsummaryrefslogtreecommitdiff
path: root/tests/test_human_readable.test
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-09-03 20:36:44 -0500
committerRob Landley <rob@landley.net>2015-09-03 20:36:44 -0500
commitd06ea3708d12e3e87fa26441715ac47f6dc63032 (patch)
tree18a517dd614a27ec99b36f51822a90d3a1155736 /tests/test_human_readable.test
parent5640847b0328c5319f353eed985781e166547ef7 (diff)
downloadtoybox-d06ea3708d12e3e87fa26441715ac47f6dc63032.tar.gz
Make human_readable() handle base 1024 units without floating point.
Rounds correctly via brute force, displayed digits are decimal even when working with powers of 2, shows at most 3 significant (decimal) digits. (So no "1023M" nonsense, that's 1.0G.)
Diffstat (limited to 'tests/test_human_readable.test')
-rwxr-xr-xtests/test_human_readable.test10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/test_human_readable.test b/tests/test_human_readable.test
new file mode 100755
index 00000000..a66b4fda
--- /dev/null
+++ b/tests/test_human_readable.test
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+testing "human_readable" "test_human_readable 123456789" "123M\n" "" ""
+testing "human_readable -b" "test_human_readable -b 123456789" "123MB\n" "" ""
+testing "human_readable -s" "test_human_readable -s 123456789" "123 M\n" "" ""
+testing "human_readable -i" "test_human_readable -i 5675" "5.5k\n" "" ""