]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Added tests for the StringUtils module.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 12 Sep 2009 16:30:34 +0000 (12:30 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 12 Sep 2009 16:30:34 +0000 (12:30 -0400)
bin/run_tests
src/Tests/Unit/StringUtilsTest.py [new file with mode: 0644]

index dceafd05dee70f532be2108d98f0a2b82355f8b7..742f7959c501b8381523acdba6b623fd5b27f25e 100755 (executable)
@@ -6,7 +6,9 @@ site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + '/../src')
 
 import unittest
 from Tests.Unit import SummaryFile1Test
+from Tests.Unit import StringUtilsTest
 
 suite = unittest.TestSuite()
 suite.addTest(SummaryFile1Test.suite())
+suite.addTest(StringUtilsTest.suite())
 unittest.TextTestRunner(verbosity=2).run(suite)
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