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 __init__(self): pass def generate(self): ''' generate of random length array. ''' import random return lambda : [random.choice(CountryArbitrary.COUNTRIES) for x in range(10)] describe "Custom Arbitrary Test": it "generate custom arbitrary.": arbitrary = CountryArbitrary() assert isinstance(arbitrary, CountryArbitrary) == True it "arbitrary test run.": test_label = "set(x).issubset({'JAPAN', 'GERMANY', 'USA', 'UK', 'AUSTRALIA'}" test_func = lambda x: set(x).issubset({'JAPAN', 'GERMANY', 'USA', 'UK', 'AUSTRALIA'}) result = ( Arbitrary( CountryArbitrary() ).property( test_label, test_func ).run(1000).test_result ) assert result.label == test_label assert result.success == 1000 assert result.failure == 0
from _import import PyQCheck, Arbitrary, Prop, PropRunner describe "Prop Test": before each: PyQCheck.TEST_STACK = [] it "should succeed all tests when Prop shows true.": test_label = 'x + y == y + x' test_func = lambda x, y: x + y == y + x result = ( PropRunner(1000).run( Prop( Arbitrary( ('number', {"min":5, "max":10}), ('number', {"min":5, "max":10}) ), test_func, test_label ) ).test_result ) assert result.label == test_label assert result.success == 1000 assert result.failure == 0 it "should be able to catch errors.": test_label = 'n <= 10 == True' test_number = 1000 def ten_or_less(n): if n > 10:
# -*- 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
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
def run(): Arbitrary('string').property( 'x =~ /^[a-zA-Z0-9]+$/g', lambda x : re.match(r'^[a-zA-Z0-9]+$', x) is not None ).run(100).result(verbose=False)
# -*- 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)