def run(): # decimal setting getcontext().prec = 60 start = time.time() def is_hiragana(chars): result = [ord('\u3040') <= ord(x) <= ord('\u309F') for x in chars] return len(set(result)) == 1 and list(set(result))[0] == True def ten_or_less(n): if n > 10: raise ValueError return True # running test. PyQCheck(verbose=False, process=3).add( Arbitrary('integer', 'integer', 'integer').property('x + y + z == z + y + x', lambda x, y, z: x + y + z == z + y + x) ).add( Arbitrary('number', 'number', 'number').property( 'Decimal(x) + Decimal(y) + Decimal(z) == Decimal(z) + Decimal(y) + Decimal(x)', lambda x, y, z: Decimal(x) + Decimal(y) + Decimal(z) == Decimal(z) + Decimal(y) + Decimal(x))).add( Arbitrary('hiragana').property( 'check characters whether hiragana.', is_hiragana)).add( Arbitrary(('integer', dict(max=20))).property( 'n <= 10 == True', ten_or_less, ValueError, )).run(1000).result() end = time.time() - start print(('finish: ' + str(end)))
def test(): PyQCheck(verbose=True).add( Arbitrary(('integer', dict(max=30))).property( 'n <= 10 == True', ten_or_less, ValueError, )).run(10).result()
def test(): PyQCheck().add( Arbitrary( ('integer', dict(min=10, max=100)), # range of 10 - 100 ('integer', dict(min=30)), # range of 30 - max of default ).property( '10 <= x <= 100 and y >= 30', lambda x, y : 10 <= x <= 100 and y >= 30 ) ) @set_arbitrary( ('string', dict(min=10, max=20)), ('integer', dict(max=30))) def repeat(chars, n): ''' (chars * n).split(chars) == n + 1 ''' repeat_string = chars * n return len(repeat_string.split(chars)) == n + 1 PyQCheck(verbose=True).run(10).result()
def run(): # decimal setting getcontext().prec = 60 start = time.time() @set_arbitrary('integer', 'integer', 'integer') def equal(x, y, z): ''' x + y + z == z + y + x ''' return x + y + z == z + y + x @set_arbitrary('number', 'number', 'number') def equal_use_decimal(x, y, z): ''' Decimal(x) + Decimal(y) + Decimal(z) == Decimal(z) + Decimal(y) + Decimal(x) ''' return Decimal(x) + Decimal(y) + Decimal(z) == Decimal(z) + Decimal( y) + Decimal(x) @set_arbitrary('hiragana') def is_hiragana(chars): ''' check characters whether hiragana. ''' result = [ord('\u3040') <= ord(x) <= ord('\u309F') for x in chars] return len(set(result)) == 1 and list(set(result))[0] == True @set_arbitrary(('integer', dict(max=20)), exceptions=(ValueError, )) def lower_10(n): ''' n <= 10 == True ''' if n > 10: raise ValueError return True # running test. PyQCheck(verbose=False).run(1000).result() end = time.time() - start print(('finish: ' + str(end)))
# -*- coding:utf-8 -*- from _import import PyQCheck, Arbitrary describe "Arbitrary Test": before each: PyQCheck().clear() it "generate arbitrary instance.": arbitrary = Arbitrary('number', 'number') assert isinstance(arbitrary, Arbitrary) == True it "generate random variable.": gen_arbitraries = Arbitrary('number', 'string').generate_arbitraries() assert len(gen_arbitraries) == 2 assert str(type(gen_arbitraries[0])).find("function") != -1 assert str(type(gen_arbitraries[1])).find("function") != -1 assert isinstance(gen_arbitraries[0](), float) assert isinstance(gen_arbitraries[1](), str) it "should work with the obsolete property method.": def eq(x,y): return x * y == y * x and x + y == y + x test_label1 = '!(x || y) == !x && !y' test_func1 = lambda x, y: (not(x or y)) == ((not x) and (not y)) test_label2 = 'x * y == y * x and x + y == y + x' test_func2 = eq test_count = 1000
# -*- coding:utf-8 -*- from _import import PyQCheck, Arbitrary, set_arbitrary, for_all from decimal import Decimal, getcontext getcontext().prec = 60 describe "PyQCheck Test": before each: PyQCheck().clear() it "later run.": PyQCheck().add( Arbitrary( ('string', dict(min=10, max=1000)), ('integer', dict(max=30)) ).property( 'len(x * y) == len(x) * y', lambda x, y: len(x * y) == len(x) * y ) ) @set_arbitrary( ('number', dict(max=100.5)), ('integer', dict(min=3))) def identical(x, y): ''' x * y == y * x ''' return x * y == y * x results = PyQCheck().run(100).results
# -*- coding:utf-8 -*- import sys import io from _import import PyQCheck, Arbitrary, PrettyPrinter describe "With emoji": before each: PyQCheck().clear() it "should be result is always success": results = PyQCheck(verbose=True).add( Arbitrary('integer').property( 'allways true', lambda x: True ) ).run(10).results printer = PrettyPrinter(True, True) for result in results: for v in printer.to_verbose_string(result.prop_results): assert v.startswith(u'\u2600') it "should be result is always failure": results = PyQCheck(verbose=True).add( Arbitrary('integer').property( 'allways false', lambda x: False ) ).run(10).results printer = PrettyPrinter(True, True)
# -*- coding:utf-8 -*- from _import import PyQCheck, Arbitrary, set_arbitrary from decimal import Decimal, getcontext getcontext().prec = 60 describe "PyQCheck Test": before each: PyQCheck().clear() it "later run.": PyQCheck().add( Arbitrary( ('string', dict(min=10, max=1000)), ('integer', dict(max=30)) ).property( 'len(x * y) == len(x) * y', lambda x, y: len(x * y) == len(x) * y ) ) @set_arbitrary( ('number', dict(max=100.5)), ('integer', dict(min=3))) def identical(x, y): ''' x * y == y * x ''' return x * y == y * x results = PyQCheck().run(100).results