Repository: pberkes/big_O

Issue:
Add units to string representation
The formulas printed with the complexity classes have no reference units.
Consider rescaling coefficients to milliseconds instead of seconds.

Discussion:

Patch:
diff --git a/big_o/big_o.py b/big_o/big_o.py
index 1dbeae4..61f40b8 100755
--- a/big_o/big_o.py
+++ b/big_o/big_o.py
@@ -70,7 +70,7 @@ def infer_big_o_class(ns, time, classes=ALL_CLASSES, verbose=False):
 
     ns -- Array of values of N for which execution time has been measured.
 
-    time -- Array of execution times for each N in `ns`.
+    time -- Array of execution times for each N in seconds.
 
     classes -- The complexity classes to consider. This is a list of subclasses
                of `big_o.complexities.ComplexityClass`.
diff --git a/big_o/complexities.py b/big_o/complexities.py
index 6319949..0b9c4a9 100755
--- a/big_o/complexities.py
+++ b/big_o/complexities.py
@@ -24,7 +24,7 @@ class ComplexityClass(object):
 
         n -- Array of values of N for which execution time has been measured.
 
-        t -- Array of execution times for each N in `ns`.
+        t -- Array of execution times for each N in seconds.
 
         Output:
         -------
@@ -55,7 +55,7 @@ class ComplexityClass(object):
 
         if self.coeff is None:
             return prefix + ': not yet fitted'
-        return prefix + self.format_str().format(*tuple(self.coeff))
+        return prefix + self.format_str().format(*tuple(self.coeff)) + ' (sec)'
 
     # --- abstract methods
 


Test patch:
diff --git a/big_o/test/test_complexities.py b/big_o/test/test_complexities.py
index 3935c88..4de6035 100644
--- a/big_o/test/test_complexities.py
+++ b/big_o/test/test_complexities.py
@@ -17,3 +17,11 @@ class TestComplexities(unittest.TestCase):
     def test_not_fitted(self):
         linear = complexities.Linear()
         self.assertRaises(complexities.NotFittedError, linear.compute, 100)
+
+    def test_str_includes_units(self):
+        x = np.linspace(10, 100, 100)
+        y = 3.0 * x + 2.0
+        linear = complexities.Linear()
+        linear.fit(x, y)
+        linear_str = str(linear)
+        assert '(sec)' in linear_str