]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/Tests/Unit/StringUtilsTest.py
Added tests for the StringUtils module.
[dead/census-tools.git] / src / Tests / Unit / StringUtilsTest.py
diff --git a/src/Tests/Unit/StringUtilsTest.py b/src/Tests/Unit/StringUtilsTest.py
new file mode 100644 (file)
index 0000000..d67a6a6
--- /dev/null
@@ -0,0 +1,56 @@
+import unittest
+
+import Tests.Fixtures
+import SummaryFile1
+import GPS
+import StringUtils
+
+
+class IsTypeTest(unittest.TestCase):
+
+    def testIntegersPassIsInteger(self):
+        """
+        If we take a bunch of integers, is_integer() should
+        return True for all of then, right?
+        """
+        for x in [ '0', '1', '902733', '-2142', '114', '65535', '65536', '-99999999' ]:
+            self.assertTrue(StringUtils.is_integer(x))
+
+
+    def testNonIntegersFailIsInteger(self):
+        """
+        Likewise, if we take a bunch of floats or whatever,
+        is_integer() should return False.
+        """
+        for x in [ '0.235', '-0235.021', 'string', GPS.Coordinates() ]:
+            self.assertFalse(StringUtils.is_integer(x))
+
+
+    def testFloatsPassIsFloat(self):
+        """
+        Do the same thing we did for is_integer(), only
+        now we check floats to make sure they pass.
+        """
+
+        # Note that integers can be converted to floats successfully.
+        for x in [ '0.024', '1.024234', '-12.902733',
+                   '-2142', '114', '65535', '65536', '-99999999' ]:
+            self.assertTrue(StringUtils.is_float(x))
+
+
+    def testNonFloatsFailIsFloat(self):
+        """
+        Pass some strings and other objects to is_float(), and hope
+        that they fail.
+        """
+
+        for x in [ 'cinnammon0.024', '1.024letters234',
+                   'nothing but string', GPS.Coordinates() ]:
+            self.assertFalse(StringUtils.is_float(x))
+
+
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(IsTypeTest))
+    return suite