changeset 135:12649a88545c

stubbing: hooking this up to command line
author Jeff Hammel <k0scist@gmail.com>
date Tue, 17 Mar 2015 11:53:33 -0700
parents b6242f916cef
children cffa11cb91a0
files numerics/manipulate.py numerics/sort.py tests/test_sort.py
diffstat 3 files changed, 56 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/numerics/manipulate.py	Tue Mar 17 11:38:43 2015 -0700
+++ b/numerics/manipulate.py	Tue Mar 17 11:53:33 2015 -0700
@@ -12,6 +12,7 @@
 from .convert import default_cast, cast_columns
 from .data import transpose
 from .read import CSVParser
+from .sort import Sorter
 
 # module globals
 __all__ = ['ManipulationParser', 'FloatParser', 'main']
--- a/numerics/sort.py	Tue Mar 17 11:38:43 2015 -0700
+++ b/numerics/sort.py	Tue Mar 17 11:53:33 2015 -0700
@@ -6,7 +6,17 @@
 """
 
 # module globals
-__all__ = ['Sorter']
+__all__ = ['sort_arg', 'Sorter']
+
+def sort_arg(string):
+    """converter appropriate for command line argument conversion"""
+
+    forward = True
+    if string.startswith('-'):
+        forward = False
+        string = string[1:]
+    return (int(string), forward)
+
 
 class Sorter(object):
     """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_sort.py	Tue Mar 17 11:53:33 2015 -0700
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+unit tests for sort
+"""
+
+import unittest
+from numerics.sort import Sorter
+
+class SortUnitTest(unittest.TestCase):
+
+    def test_sort(self):
+        """test array sorter"""
+
+        data = [[1,2,3],
+                [5,6,4],
+                [2,7,2]]
+
+        # forward
+        self.assertEqual(Sorter((-1, True))(data),
+                         [[2,7,2],
+                          [1,2,3],
+                          [5,6,4]])
+        self.assertEqual(Sorter((0, True))(data),
+                         [[1,2,3],
+                          [2,7,2],
+                          [5,6,4]])
+        self.assertEqual(Sorter((1, True))(data),
+                         [[1,2,3],
+                          [5,6,4],
+                          [2,7,2]])
+    def test_reverse(self):
+        data = [[1,2,3],
+                [5,6,4],
+                [2,7,2]]
+        self.assertEqual(Sorter((-1, False))(data),
+                         [[5,6,4],
+                          [1,2,3],
+                          [2,7,2]])
+
+if __name__ == '__main__':
+    unittest.main()
+