summaryrefslogtreecommitdiff
path: root/lulua
diff options
context:
space:
mode:
Diffstat (limited to 'lulua')
-rw-r--r--lulua/report.py2
-rw-r--r--lulua/test_report.py20
-rw-r--r--lulua/test_stats.py15
3 files changed, 22 insertions, 15 deletions
diff --git a/lulua/report.py b/lulua/report.py
index 200bb9b..b6c6f7e 100644
--- a/lulua/report.py
+++ b/lulua/report.py
@@ -14,7 +14,7 @@ def approx (i):
units = ['', 'thousand', 'million', 'billion']
base = Decimal (1000)
i = Decimal (i)
- while i >= base and len (units) > 1:
+ while round (i, 1) >= base and len (units) > 1:
i /= base
units.pop (0)
return round (i, 1), units[0]
diff --git a/lulua/test_report.py b/lulua/test_report.py
new file mode 100644
index 0000000..816aa85
--- /dev/null
+++ b/lulua/test_report.py
@@ -0,0 +1,20 @@
+from decimal import Decimal
+
+from .report import approx
+
+def test_approx ():
+ assert approx (0) == (Decimal ('0'), '')
+ assert approx (0.01) == (Decimal ('0'), '')
+ assert approx (0.05) == (Decimal ('0.1'), '')
+ assert approx (1) == (Decimal ('1'), '')
+ assert approx (100) == (Decimal ('100'), '')
+ assert approx (999.9) == (Decimal ('999.9'), '')
+ assert approx (999.91) == (Decimal ('999.9'), '')
+ assert approx (999.99) == (Decimal ('1'), 'thousand')
+
+ assert approx (10**3) == (Decimal ('1'), 'thousand')
+ assert approx (10**6) == (Decimal ('1'), 'million')
+ assert approx (10**9) == (Decimal ('1'), 'billion')
+ assert approx (10**12) == (Decimal ('1000'), 'billion')
+
+
diff --git a/lulua/test_stats.py b/lulua/test_stats.py
index 3259bcd..48c4b0d 100644
--- a/lulua/test_stats.py
+++ b/lulua/test_stats.py
@@ -21,7 +21,7 @@
import operator
import pytest
-from .stats import updateDictOp, approx, SimpleStats, TriadStats, allStats
+from .stats import updateDictOp, SimpleStats, TriadStats, allStats
from .keyboard import defaultKeyboards
from .layout import defaultLayouts, ButtonCombination
from .writer import Writer, SkipEvent
@@ -40,19 +40,6 @@ def test_updateDictOp ():
assert a == {'foo': {1: 3+7}}
assert b == {'foo': {1: 7}}
-def test_approx ():
- assert approx (0) == (0, 0, '')
- assert approx (0.01) == (0, 0, '')
- assert approx (0.05) == (0, 1, '')
- assert approx (1) == (1, 0, '')
- assert approx (100) == (100, 0, '')
- assert approx (999.9) == (999, 9, '')
-
- assert approx (10**3) == (1, 0, 'thousand')
- assert approx (10**6) == (1, 0, 'million')
- assert approx (10**9) == (1, 0, 'billion')
- assert approx (10**12) == (1000, 0, 'billion')
-
@pytest.fixture
def writer ():
""" Return a default, safe writer with known properties for a fixed layout """