def __runTest3(self, scale, setMin, setMax): getZeros = lambda x: (scale - len(str(x)))*"0" min = random.randint(-1*(10**scale), 10**scale) max = random.randint(min, min + 5**scale) #zeby testowalo tez np -100 do -10 format = "%0{0}d".format(scale) regexp = regexpgen.integer(format, min if setMin else None, max if setMax else None) info = lambda value: self.__getInfo(value, regexp, format, min if setMin else None, max if setMax else None) if min < 0 and max < 0: rangeLeft = min*2 rangeRight = -min*2 if min < 0 and max > 0: rangeLeft = min*2 rangeRight = max*2 if min > 0 and max > 0: rangeLeft = -max*2 rangeRight = max*2 if min == 0 and max != 0: rangeLeft = -max*2 rangeRight = max*2 if max == 0 and min != 0: rangeLeft = min*2 rangeRight = -min*2 if max == 0 and min == 0: rangeLeft = -100 rangeRight = 100 if setMin: for i in xrange(rangeLeft, min - 1): if i < 0: a = "-" + getZeros(int(math.fabs(i))) + str(int(math.fabs(i))) else: a = getZeros(int(math.fabs(i))) + str(i) self.assertFalse(re.match(regexp, str(i)), info(str(i))) self.assertFalse(re.match(regexp, a), info(a)) for i in xrange(min, max): if len(str(i)) > scale: break zeros = getZeros(int(math.fabs(i))) if i < 0: a = "-" + zeros + str(int(math.fabs(i))) b = "-" + zeros + "0" + str(int(math.fabs(i))) else: a = zeros + str(i); b = zeros + "0" + str(i) self.assertTrue(re.match(regexp, a), info(a)) self.assertFalse(re.match(regexp, b), info(b)) if len(zeros) > 0: if i < 0: c = "-" + zeros[:-1] + str(int(math.fabs(i))) #cuts last zero else: c = zeros[:-1] + str(i) #cuts last zero self.assertFalse(re.match(regexp, c), info(c)) if setMax: for i in xrange(max+1, rangeRight): if i < 0: a = "-" + getZeros(int(math.fabs(i))) + str(int(math.fabs(i))) else: a = getZeros(int(math.fabs(i))) + str(i) self.assertFalse(re.match(regexp, str(i)), info(str(i))) self.assertFalse(re.match(regexp, a), info(a))
def __runTest2(self, scale, setMin, setMax): min = random.randint(-1*(10**scale), 10**scale) max = random.randint(min, min + 5**scale) #zeby testowalo tez np -100 do -10 format = "%0d" regexp = regexpgen.integer(format, min if setMin else None, max if setMax else None) info = lambda value: self.__getInfo(value, regexp, format, min if setMin else None, max if setMax else None) if min < 0 and max < 0: rangeLeft = min*2 rangeRight = -min*2 if min < 0 and max > 0: rangeLeft = min*2 rangeRight = max*2 if min > 0 and max > 0: rangeLeft = -max*2 rangeRight = max*2 if min == 0 and max != 0: rangeLeft = -max*2 rangeRight = max*2 if max == 0 and min != 0: rangeLeft = min*2 rangeRight = -min*2 if max == 0 and min == 0: rangeLeft = -100 rangeRight = 100 if setMin: for i in xrange(rangeLeft, min - 1): self.assertFalse(re.match(regexp, str(i)), info(str(i))) for i in xrange(min, max): if i >= 0: a = "0" + str(i); b = "00" + str(i); c = "000" + str(i); d = "0000" + str(i); else: a = "-0" + str(-i); b = "-00" + str(-i); c = "-000" + str(-i); d = "-0000" + str(-i); self.assertTrue(re.match(regexp, str(i)), info(str(i))) self.assertFalse(re.match(regexp, a), info(a)) self.assertFalse(re.match(regexp, b), info(b)) self.assertFalse(re.match(regexp, c), info(c)) self.assertFalse(re.match(regexp, d), info(d)) if setMax: for i in xrange(max+1, rangeRight): self.assertFalse(re.search(regexp, str(i)), info(str(i)))
''' Created on Apr 27, 2011 @authors: Joanna Binczewska, Dawid Kowalski ''' import regexpgen print regexpgen.nnint("%04d", 71, 2319) print regexpgen.integer("%0d", -521, 132) print regexpgen.real("%lf", -12.7, 23.5) print regexpgen.real("%lf", -100.0, 100.0) print regexpgen.real("%lf", 0.0, 10.1) print regexpgen.concatenate([ ('int', "%d", 100, 105), ('\.',), ('int', "%d", 250, 255), ('\.',), ('int', "%d", 122, 122), ('\.',), ('int', "%d", 0, 240) ]) print regexpgen.time("%H:%M", "12:24", "17:59") print regexpgen.date("%Y-%m-%d", "2013-03-15", "2013-04-24") print regexpgen.date("%d/%m", "15/09")