コード例 #1
0
ファイル: testhelper.py プロジェクト: ilaotu/octocat
def testlength():
 test_length = [[0 for col in range(3)] for row in range(6)]
 test_length[0][0] = 6
 test_length[0][1] = 6
 test_length[0][2] = 6 
 test_length[1][0] = 9
 test_length[1][1] = 3
 test_length[1][2] = -1
 test_length[2][0] = -3
 test_length[2][1] = 9
 test_length[2][2] = -2
 test_length[3][0] = 0
 test_length[3][1] = 0
 test_length[3][2] = 0
 test_length[4][0] = 9
 test_length[4][1] = -3
 test_length[4][2] = -1
 test_length[5][0] = -6
 test_length[5][1] = -3
 test_length[5][2] = -2

 for i in range(6):
  l = lengthhelper.length(test_length[i][0],test_length[i][1])
  if l != test_length[i][2]:
   print 'error! function is lengthhelper.length(' + str(test_length[i][0]) + ',' + str(test_length[i][1]) + '),the result is ' + str(l) + ', the expect is ' + str(test_length[i][2])

 l = lengthhelper.length(3,6)
 if l < 3 or l > 6:
  print 'error! function is lengthhelper.length(3,6), the result is ' + str(l)
コード例 #2
0
ファイル: cat.py プロジェクト: ilaotu/octocat
def makestring():
 #get command from cmd
 options = commandhelper.cmd()

 #get the length of the string
 if options.total is None:
  max = options.max
  min = options.min
  length = lengthhelper.length(min,max)
 else:
  length = options.total

 #select upper or lower character
 if options.upper == options.lower:
   uplow = string.ascii_letters
 elif options.upper is True:
   uplow = string.ascii_uppercase
 elif options.lower is True:
   uplow = string.ascii_lowercase 
 else:
   uplow = ''

 #select letters or digits character
 if options.charactoronly == options.numberonly:
  only = uplow + string.digits
 elif options.numberonly is True:
  only = string.digits
 elif options.charactoronly is True:
  only =  uplow
 else:
  only = string.ascii_letters + string.digits

 if not options.spechar is None:
  spec = options.spechar
  only = only + spec

#begin a string or add a string
 if not options.beginwith is None: 
  begin = options.beginwith
 else:
  begin = ''
 if not options.endwith is None:
  end = options.endwith
 else:
  end = '' 

# real create a string
 func = getattr(stringhelper.Character,'letters_digits')
 print stringhelper.Character.begin_with_end(func,only,length,begin,end)