From: Michael Orlitzky Date: Sat, 12 Sep 2009 16:30:34 +0000 (-0400) Subject: Added tests for the StringUtils module. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fcensus-tools.git;a=commitdiff_plain;h=af1c16f00734808c24e61e776db5bedd52494d13 Added tests for the StringUtils module. --- diff --git a/bin/run_tests b/bin/run_tests index dceafd0..742f795 100755 --- a/bin/run_tests +++ b/bin/run_tests @@ -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 index 0000000..d67a6a6 --- /dev/null +++ b/src/Tests/Unit/StringUtilsTest.py @@ -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