Example #1
0
from qc import integers, floats, unicodes, characters, lists, tuples, dicts, objects, forall

@forall(tries=10, i=integers())
def test_integers(i):
    assert type(i) == int
    assert i >= 0 and i <= 100

@forall(tries=10, l=lists(items=integers()))
def test_a_int_list(l):
    assert type(l) == list

@forall(tries=10, l=tuples(items=integers()))
def test_a_int_tuple(l):
    assert type(l) == tuple

@forall(tries=10, i=floats())
def test_floats(i):
    assert type(i) == float
    assert i >= 0.0 and i <= 100.0

@forall(tries=10, l=lists(items=floats()))
def test_a_float_list(l):
    assert type(l) == list
    assert reduce(lambda x,y: x and type(y) == float, l, True)

@forall(tries=10, ul=lists(items=unicodes()))
def test_unicodes_list(ul):
    assert type(ul) == list
    if len(ul):
        assert type(ul[0]) == unicode
Example #2
0
def locations(lat = floats(-90,+90),
              lon = floats(-180, +180),
              height = floats(0, 30000)):
    while True:
        yield Location(lat.next(), lon.next(), height.next())
Example #3
0
def test_floats_coverage():
    negative_inf = False
    negative_max = False
    negative_large = False
    negative_one = False
    negative_small = False
    negative_min = False
    zero = False
    positive_min = False
    positive_small = False
    positive_one = False
    positive_large = False
    positive_max = False
    positive_inf = False
    nan = False

    gen = floats()
    for i in range(100):              # 100 opportunities should be plenty
        f = gen.next()
        print "value = ", f
        if math.isinf(f) and f < 0:
            negative_inf = True
        elif f == -sys.float_info.max:
            negative_max = True
        elif -sys.float_info.max / 2 < f < -2:
            negative_large = True
        elif f == -1.0:
            negative_one = True
        elif -0.5 < f < -sys.float_info.min * 2:
            negative_small = True
        elif f == -sys.float_info.min:
            negative_min = True
        elif f == 0:
            zero = True
        elif f == sys.float_info.min:
            positive_min = True
        elif sys.float_info.min * 2 < f < 0.5:
            positive_small = True
        elif f == 1.0:
            positive_one = True
        elif 2 < f < sys.float_info.max / 2:
            positive_large = True
        elif f == sys.float_info.max:
            positive_max = True
        elif math.isinf(f) and f > 0:
            positive_inf = True
        elif math.isnan(f):
            nan = True

    assert negative_inf == True
    assert negative_max == True
    assert negative_large == True
    assert negative_one == True
    assert negative_small == True
    assert negative_min == True
    assert zero == True
    assert positive_min == True
    assert positive_small == True
    assert positive_one == True
    assert positive_large == True
    assert positive_max == True
    assert positive_inf == True
    assert nan == True
Example #4
0
def test_integers(i):
    assert type(i) == int, "expected an int, instead got a " + str(type(i))

@forall(tries=10, i=integers(low=0, high=100))
def test__nonnegative_integers(i):
    assert type(i) == int, "expected an int, instead got a " + str(type(i))
    assert 0 <= i <= 100, "not the expected range"

@forall(tries=10, i=integers(low=-100, high=0))
def test__nonpositive_integers(i):
    assert type(i) == int, "expected an int, instead got a " + str(type(i))
    assert -100 <= i <= 0, "not the expected range"

# Floats

@forall(tries=10, i=floats())
def test_floats(i):
    assert type(i) == float, "expected a float, instead got a " + str(type(i))

@forall(tries=10, i=floats(low=0, high=100))
def test_nonnegative_floats(i):
    assert type(i) == float, "expected a float, instead got a " + str(type(i))
    assert 0 <= i <= 100 or math.isnan(i) or math.isinf(i), "not the expected range"

@forall(tries=10, i=floats(low=-100, high=0))
def test_nonpositive_floats(i):
    assert type(i) == float, "expected a float, instead got a " + str(type(i))
    assert -100 <= i <= 0 or math.isnan(i) or math.isinf(i), "not the expected range"

@forall(tries=10, i=floats(low=-100, high=-100, special=False))
def test_nonspecial_floats(i):
Example #5
0
def test_integers(i):
    assert type(i) == int
    assert i >= 0 and i <= 100


@forall(tries=10, l=lists(items=integers()))
def test_a_int_list(l):
    assert type(l) == list


@forall(tries=10, l=tuples(items=integers()))
def test_a_int_tuple(l):
    assert type(l) == tuple


@forall(tries=10, i=floats())
def test_floats(i):
    assert type(i) == float
    assert i >= 0.0 and i <= 100.0


@forall(tries=10, l=lists(items=floats()))
def test_a_float_list(l):
    assert type(l) == list
    assert reduce(lambda x, y: x and type(y) == float, l, True)


@forall(tries=10, ul=lists(items=unicodes()))
def test_unicodes_list(ul):
    assert type(ul) == list
    if len(ul):
Example #6
0
from qc import integers, floats, unicodes, characters, lists, tuples, dicts, objects, forall, qc_shrink, call_and_shrink

@forall(tries=10, i=integers())
def test_integers(i):
    assert type(i) == int
    assert i >= 0 and i <= 100

@forall(tries=10, l=lists(items=integers()))
def test_a_int_list(l):
    assert type(l) == list

@forall(tries=10, l=tuples(items=integers()))
def test_a_int_tuple(l):
    assert type(l) == tuple

@forall(tries=10, i=floats())
def test_floats(i):
    assert type(i) == float
    assert i >= 0.0 and i <= 100.0

@forall(tries=10, l=lists(items=floats()))
def test_a_float_list(l):
    assert type(l) == list
    assert reduce(lambda x,y: x and type(y) == float, l, True)

@forall(tries=10, ul=lists(items=unicodes()))
def test_unicodes_list(ul):
    assert type(ul) == list
    if len(ul):
        assert type(ul[0]) == unicode
Example #7
0
File: test_qc.py Project: lbolla/qc
from qc import integers, floats, unicodes, characters, lists, tuples, dicts, forall

@forall(tries=10, i=integers())
def test_integers(i):
    assert type(i) == int
    assert i >= 0 and i <= 100

@forall(tries=10, l=lists(items=integers()))
def test_a_int_list(l):
    assert type(l) == list

@forall(tries=10, l=tuples(items=integers()))
def test_a_int_tuple(l):
    assert type(l) == tuple

@forall(tries=10, i=floats())
def test_floats(i):
    assert type(i) == float
    assert i >= 0.0 and i <= 100.0

@forall(tries=10, l=lists(items=floats()))
def test_a_float_list(l):
    assert type(l) == list
    assert reduce(lambda x,y: x and type(y) == float, l, True)

@forall(tries=10, ul=lists(items=unicodes()))
def test_unicodes_list(ul):
    assert type(ul) == list
    if len(ul):
        assert type(ul[0]) == unicode