X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTests%2FUnit%2FStringUtilsTest.py;fp=src%2FTests%2FUnit%2FStringUtilsTest.py;h=d67a6a65394725a3af33a067520a743f1b6a96cf;hb=af1c16f00734808c24e61e776db5bedd52494d13;hp=0000000000000000000000000000000000000000;hpb=767b5cac8c137b5318b5527746ff28d580a0a1de;p=dead%2Fcensus-tools.git 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