diff tests/test_cast.py @ 18:56596902e9ae default tip

add some setup + tests
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 17:57:03 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_cast.py	Sun Dec 10 17:57:03 2017 -0800
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+"""
+data casting functions
+"""
+
+import unittest
+from lemiformes import cast
+
+class TestCast(unittest.TestCase):
+
+    def test_isiterable(self):
+        assert not cast.isiterable(1)
+        assert cast.isiterable(range(5))
+
+    def test_make_iterable(self):
+        iterval = cast.iterable(1)
+        assert cast.isiterable(iterval)
+        assert list(iterval) == [1]
+        assert cast.iterable([1,2,3]) == [1,2,3]
+
+    def test_interference(self):
+        ints = ['1', '2', '3']
+        floats = ['1', '2', '3.5']
+        strings = ['1', '2', "I'm a kitty!"]
+
+        assert cast.infer(ints) == int
+        assert cast.infer(floats) == float
+        assert cast.infer(strings) == str
+
+    def test_casting(self):
+        ints = ['1', '2', '3']
+        floats = ['1', '2', '3.5']
+        strings = ['1', '2', "I'm a kitty!"]
+
+        assert cast.cast(ints) == [1, 2, 3]
+        assert cast.cast(floats) == [1., 2., 3.5]
+        assert cast.cast(strings) == strings
+
+
+if __name__ == '__main__':
+    unittest.main()