Read and respond to this message at: 
https://sourceforge.net/forum/message.php?msg_id=3825327
By: xsaero00

Unit Test Code:

import unittest

from Packages.Utilities.validate import *

class validateTest( unittest.TestCase ):
   """ Class to test validation functions """
   
   def testIsLargeID(self):
      """ Test isLargeID function """
      self.assert_( isLargeID( 1 ) )
      self.assert_( isLargeID( '1' ) )
      self.assert_( isLargeID( u'1' ) )
      self.assert_( isLargeID( r'1' ) )
      self.assert_( isLargeID( 0 ) )
      self.assert_( isLargeID( '0' ) )
      self.assert_( isLargeID( 00000000 ) )
      self.assert_( isLargeID( '0000000' ) )
      self.assert_( isLargeID( MAX_LARGE_ID ) )
      self.assert_( isLargeID( MAX_SMALL_ID ) )
      self.assert_( isLargeID( MIN_LARGE_ID ) )
      
      self.assert_( not isLargeID( -1 ) )
      self.assert_( not isLargeID( '-1' ) )
      self.assert_( not isLargeID( u'-1' ) )
      self.assert_( not isLargeID( None ) )
      self.assert_( not isLargeID( '' ) )
      self.assert_( not isLargeID( MAX_LARGE_ID + 1) )
      self.assert_( not isLargeID( MIN_LARGE_ID - 1 ) )
      self.assert_( not isLargeID( '0.0' ) )
      self.assert_( not isLargeID( float( MAX_LARGE_ID ) ) )
   
   def testIsSmallID(self):
      """ Test isSmallID function """
      self.assert_( isSmallID( 1 ) )
      self.assert_( isSmallID( '1' ) )
      self.assert_( isSmallID( u'1' ) )
      self.assert_( isSmallID( r'1' ) )
      self.assert_( isSmallID( 0 ) )
      self.assert_( isSmallID( '0' ) )
      self.assert_( isSmallID( 00000000 ) )
      self.assert_( isSmallID( '0000000' ) )
      self.assert_( isSmallID( MAX_SMALL_ID ) )
      self.assert_( isSmallID( MIN_SMALL_ID ) )
      
      self.assert_( not isSmallID( -1 ) )
      self.assert_( not isSmallID( '-1' ) )
      self.assert_( not isSmallID( u'-1' ) )
      self.assert_( not isSmallID( r'-1' ) )
      self.assert_( not isSmallID( None ) )
      self.assert_( not isSmallID( '' ) )
      self.assert_( not isSmallID( '   ' ) )
      self.assert_( not isSmallID( 'as' ) )
      self.assert_( not isSmallID( '1a' ) )
      self.assert_( not isSmallID( MAX_SMALL_ID + 1) )
      self.assert_( not isSmallID( MIN_SMALL_ID - 1 ) )
      self.assert_( not isSmallID( '0.0' ) )
      self.assert_( not isSmallID( float( MAX_SMALL_ID ) ) )      
   
def TestSuite():
   return unittest.makeSuite(validateTest)

if __name__ == '__main__':
   unittest.main()


And here are the validation functions:

def isLargeID( id ):
   """ Function to tell whether the id is a large id """
   return isInteg( id ) and withinRange( id , MIN_LARGE_ID, MAX_LARGE_ID )

def isSmallID( id ):
   """ Function to tell whether the id is a small id """
   return isInteg( id ) and withinRange( id , MIN_SMALL_ID, MAX_SMALL_ID )

def withinRange( value, min, max ):
   """ Function to check the range """
   if isNumeric( value )  and isNumeric( min ) and isNumeric( max ):
      value = float( value )
      min = float( min )
      max = float( max )
      return min <= max and value >= min and value <= max

______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit: 
https://sourceforge.net/forum/unmonitor.php?forum_id=293649

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Pydev-users mailing list
Pydev-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pydev-users

Reply via email to