当前位置: 首页>>代码示例>>Python>>正文


Python Qit.run方法代码示例

本文整理汇总了Python中testutils.Qit.run方法的典型用法代码示例。如果您正苦于以下问题:Python Qit.run方法的具体用法?Python Qit.run怎么用?Python Qit.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testutils.Qit的用法示例。


在下文中一共展示了Qit.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_filter_product

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_filter_product():
    p = Product((Range(5), "x"), (Range(5), "y"))
    q = Qit()

    f = Function("filter").returns(Bool()).takes(p.type, "p").code("return p.x == p.y;")

    q.run(p.iterate().filter(f)) == [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
开发者ID:msurkovsky,项目名称:qit,代码行数:9,代码来源:test_filter.py

示例2: test_product_copy

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_product_copy():
    p = Product("P", (Range(4), "x"), (Range(4), "y"))

    p2 = p.copy()
    p2.set("x", Range(2))

    q = Product("Q", (p, "p1"), (p, "p2"))

    q2 = q.copy()
    q2.set_generator("p2", p2.generator)
    q2.set_iterator("p1", p2.iterator)

    v_r4 = list(range(4))
    v_r2 = list(range(2))
    v_p = list(itertools.product(v_r4, v_r4))
    v_p2 = list(itertools.product(v_r2, v_r4))
    v_q2_generator = set(itertools.product(v_p, v_p2))
    v_q2_iterator = set(itertools.product(v_p2, v_p))

    c = Qit()
    for v in c.run(q2.generate().take(200).collect()):
        assert v in v_q2_generator

    result = c.run(q2.iterate().collect())
    assert len(v_q2_iterator) == len(result)
    assert v_q2_iterator == set(result)
开发者ID:Kobzol,项目名称:qit,代码行数:28,代码来源:test_build_product.py

示例3: test_iterator_first_default_value

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_iterator_first_default_value():
    ctx = Qit()
    fn = Function().takes(Int(), "a").returns(Int()).code("return a > 100;")
    result = ctx.run(Range(91, 120, 2).iterate().filter(fn).first(111))
    assert result == 101
    result = ctx.run(Range(10, 20, 2).iterate().filter(fn).first(111))
    assert result == 111
开发者ID:spirali,项目名称:qit,代码行数:9,代码来源:test_iterator.py

示例4: test_iterator_first_maybe

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_iterator_first_maybe():
    ctx = Qit()
    fn = Function().takes(Int(), "a").returns(Int()).code("return a > 100;")
    result = ctx.run(Range(91, 120, 2).iterate().filter(fn).first_maybe())
    assert result == ("Just", 101)
    result = ctx.run(Range(10, 20, 2).iterate().filter(fn).first_maybe())
    assert result == ("Nothing", None)
开发者ID:spirali,项目名称:qit,代码行数:9,代码来源:test_iterator.py

示例5: test_iterator_first_no_default

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_iterator_first_no_default():
    ctx = Qit()
    fn = Function().takes(Int(), "a").returns(Int()).code("return a > 100;")
    result = ctx.run(Range(91, 120, 2).iterate().filter(fn).first())
    assert result == 101
    with pytest.raises(ProgramCrashed):
        ctx.run(Range(10, 20, 2).iterate().filter(fn).first())
开发者ID:spirali,项目名称:qit,代码行数:9,代码来源:test_iterator.py

示例6: test_map_value

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_map_value():
    ctx = Qit()
    m = { 1: 1, 2: 2, 3: 3 }
    assert ctx.run(Map(Int(), Int()).value(m)) == m

    m = { (1, 2) : (2, 1), (3, 4): (4, 3), (5, 6): (6, 5) }
    s = Struct(Int(), Int())
    assert ctx.run(Map(s, s).value(m)) == m
开发者ID:spirali,项目名称:qit,代码行数:10,代码来源:test_map.py

示例7: test_map_variable

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_map_variable():
    ctx = Qit()
    m = Variable(Map(Int(), Int()), "m")
    assert ctx.run(m, args={m: { 2: 1, 1: 2 }}) == { 2: 1, 1: 2 }

    m = Map(Int(), Int() * Int())
    x = Variable(Int(), "x")
    assert ctx.run(m.value({1: (x, 20)}), args={x: 123}) == {1: (123, 20)}
开发者ID:spirali,项目名称:qit,代码行数:10,代码来源:test_map.py

示例8: test_filter_map

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_filter_map():
    r = Range(5)
    q = Qit()

    f = Function("f").returns(Int()).takes(Int(), "r").code("return r * 2;")
    g = Function("g").returns(Bool()).takes(Int(), "x").code("return x == 4;")
    h = Function("h").returns(Int()).takes(Int(), "r").code("return r + 1;")

    q.run(r.iterate().map(f).filter(g).map(h)) == 5
开发者ID:msurkovsky,项目名称:qit,代码行数:11,代码来源:test_filter.py

示例9: test_bool_variable

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_bool_variable():
    ctx = Qit()
    x = Variable(Bool(), "x")

    result = ctx.run(x, args={x: True})
    assert result is True

    result = ctx.run(x, args={x: False})
    assert result is False
开发者ID:spirali,项目名称:qit,代码行数:11,代码来源:test_bool.py

示例10: test_product_values

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_product_values():
    ctx = Qit()
    p = Range(4) * Range(10)
    v = p.values((0, 0), (1, 7), (3, 2))

    result = ctx.run(v.iterate())
    assert [(0, 0), (1, 7), (3, 2)] == result

    result = ctx.run(v.generate().take(100))
    assert all(i in ((0, 0), (1, 7), (3, 2)) for i in result)
开发者ID:msurkovsky,项目名称:qit,代码行数:12,代码来源:test_values.py

示例11: test_range_size

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_range_size():
    ctx = Qit()
    r = Range(11)
    assert ctx.run(r.size) == 11

    start = Variable(Int(), "start")
    end = Variable(Int(), "end")
    step = Variable(Int(), "step")
    r = Range(start, end, step)
    assert ctx.run(r.size, args={ "start" : 5, "end" : 10, "step" : 1 }) == 5
    assert ctx.run(r.size, args={ "start" : 5, "end" : 10, "step" : 2 }) == 2
开发者ID:msurkovsky,项目名称:qit,代码行数:13,代码来源:test_range.py

示例12: test_range_indexer

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_range_indexer():
    ctx = Qit()
    r = Range(10)
    ctx.run(r.indexer(5)) == 5

    start = Variable(Int(), "start")
    end = Variable(Int(), "end")
    step = Variable(Int(), "step")
    r = Range(start, end, step)
    result = ctx.run(r.iterate().map(r.indexer), args={"start" : 5, "end": 21, "step" : 3})
    assert result == list(range(6))
开发者ID:msurkovsky,项目名称:qit,代码行数:13,代码来源:test_range.py

示例13: test_run_circular_deps

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_run_circular_deps():
    ctx = Qit()

    x = Int().variable("x")
    y = Int().variable("y")

    with pytest.raises(QitException):
        ctx.run(x, args = {
            x : y,
            y : x,
        })
开发者ID:spirali,项目名称:qit,代码行数:13,代码来源:test_run.py

示例14: test_union_different_types

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_union_different_types():
    ctx = Qit()
    a = Int()
    b = Int() * Int()
    c = Vector(b)
    d = Set(a)
    e = Map(b, c)
    u = Union(A=a, B=b, C=c, D=d, E=e, G=None)
    assert ctx.run(u.value(("B", (25, 16)))) == ("B", (25, 16))
    assert ctx.run(u.value(("C", [(25, 16), (3, -2)]))) == ("C", [(25, 16), (3, -2)])
    assert ctx.run(u.value(("G", None))) == ("G", None)
开发者ID:spirali,项目名称:qit,代码行数:13,代码来源:test_union.py

示例15: test_basic_functor

# 需要导入模块: from testutils import Qit [as 别名]
# 或者: from testutils.Qit import run [as 别名]
def test_basic_functor():
    ctx = Qit()

    f_functor = Functor("f_functor", Int(), (Int(), "x"), (Int(), "y"))
    f = Function("f").takes(Int(), "x").takes(Int(), "y").returns(Int()).code("return x + y;")
    g = Function("g").takes(f_functor, "f")\
                     .takes(Int(), "x")\
                     .takes(Int(), "y")\
                     .returns(Int())
    g.code("return f(x, y);")
    assert ctx.run(g(f_functor.value(f), 3, 4)) == 7

    f_functor = FunctorFromFunction(f)
    assert ctx.run(g(f_functor.value(f), -2, 4)) == 2
开发者ID:spirali,项目名称:qit,代码行数:16,代码来源:test_function.py


注:本文中的testutils.Qit.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。