• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testutils.Qit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_iterator_first_maybe

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,代码行数:7,代码来源:test_iterator.py


示例2: test_range_variable_generate

def test_range_variable_generate():
    c = Qit()
    x = Variable(Int(), "x")
    r = Range(x).generate().take(30)
    result = c.run(r, { "x": 3 })
    for i in result:
        assert 0 <= i < 3
开发者ID:msurkovsky,项目名称:qit,代码行数:7,代码来源:test_range.py


示例3: test_iterator_first_no_default

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,代码行数:7,代码来源:test_iterator.py


示例4: test_union_sort

def test_union_sort():
    ctx = Qit()
    u = Union(A=Int(), B=None, C=Int())
    v = (("A", 10), ("B", None), ("C", 5), ("B", None), ("C", 5), ("A", 0), ("A", 20))
    values = u.values(*v)
    result = ctx.run(values.iterate().sort())
    assert result == sorted(v)
开发者ID:spirali,项目名称:qit,代码行数:7,代码来源:test_union.py


示例5: test_iterator_first_default_value

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,代码行数:7,代码来源:test_iterator.py


示例6: test_range_function_iterate

def test_range_function_iterate():
    c = Qit()

    x = Variable(Int(), "x")
    r = Range(x).iterate().to_vector()
    f = r.make_function()
    assert [[], [0], [0,1], [0,1,2]] == c.run(Range(4).iterate().map(f))
开发者ID:msurkovsky,项目名称:qit,代码行数:7,代码来源:test_range.py


示例7: test_queue_variable

def test_queue_variable():
    ctx = Qit()
    s = Struct(Int(), Int())
    q = Queue(s)
    x = Variable(q, "x")
    result = ctx.run(x, args={x: [(11,12), (5, 2)] })
    assert result == [(11, 12), (5, 2)]
开发者ID:spirali,项目名称:qit,代码行数:7,代码来源:test_queue.py


示例8: test_product_copy

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,代码行数:26,代码来源:test_build_product.py


示例9: test_filter_product

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,代码行数:7,代码来源:test_filter.py


示例10: test_outer_variables

def test_outer_variables():
    c = Qit()
    x = Variable(Int(), "x")
    f = Function().takes(Int(), "a").returns(Int()).reads(x)
    f.code("return a * x;")
    r = Range(x).iterate().map(f)
    assert [0, 5, 10, 15, 20] == c.run(r, args={ x: 5 })
开发者ID:spirali,项目名称:qit,代码行数:7,代码来源:test_function.py


示例11: test_filter_even

def test_filter_even():
    r = Range(5)
    q = Qit()

    f = Function("filter").returns(Bool()).takes(r.type, "r").code("return r % 2 == 0;")

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


示例12: test_vector_variable

def test_vector_variable():
    ctx = Qit()
    s = Struct(Int(), Int())
    v = Vector(s)
    x = Variable(v, "x")
    result = ctx.run(x, args={x: [(11,12), (5, 2)]})
    assert result == [(11,12), (5, 2)]
开发者ID:spirali,项目名称:qit,代码行数:7,代码来源:test_vector.py


示例13: test_functor_variable

def test_functor_variable():
    ctx = Qit()
    ftype = Functor("f_functor", Int(), (Int(), "x"), (Int(), "y"))

    # functions
    fplus = Function().takes(Int(), "x").takes(Int(), "y").returns(Int())
    fplus.code("return x + y;")

    ftimes = Function().takes(Int(), "x").takes(Int(), "y").returns(Int())
    ftimes.code("return x * y;")

    fmod = Function().takes(Int(), "x").takes(Int(), "y").returns(Int())
    fmod.code("return x % y;")

    # apply function in variable fvar to the given list of pairs
    fvar = ftype.variable("f")
    p = Product((Range(1, 4), "x"), (Range(1, 3), "y"))
    apply_f = Function().takes(p, "p").reads(fvar).returns(Int()).code("""
        return f(p.x, p.y);
    """)
    g = p.iterate().map(apply_f).make_function((fvar, ))

    bind_function = Function().takes(ftype, "f")\
                              .returns(Vector(ftype.return_type))
    bind_function.code("return {{g}}(f);", g=g)
    res = ctx.run(ftype.values(fplus, ftimes, fmod).iterate().map(bind_function))
    assert res == [[2, 3, 4, 3, 4, 5], [1, 2, 3, 2, 4, 6], [0, 0, 0, 1, 0, 1]]
开发者ID:spirali,项目名称:qit,代码行数:27,代码来源:test_function.py


示例14: test_mapping_product_sequence

def test_mapping_product_sequence():
    ctx = Qit()
    r = Range(2) * Range(1)
    s = Sequence(Enumerate("X", "Y"), 2)
    m = Mapping(r, s)
    result = ctx.run(m.iterate())

    expected = [
            {(1, 0): ['X', 'X'], (0, 0): ['X', 'X']},
            {(1, 0): ['X', 'X'], (0, 0): ['Y', 'X']},
            {(1, 0): ['X', 'X'], (0, 0): ['X', 'Y']},
            {(1, 0): ['X', 'X'], (0, 0): ['Y', 'Y']},
            {(1, 0): ['Y', 'X'], (0, 0): ['X', 'X']},
            {(1, 0): ['Y', 'X'], (0, 0): ['Y', 'X']},
            {(1, 0): ['Y', 'X'], (0, 0): ['X', 'Y']},
            {(1, 0): ['Y', 'X'], (0, 0): ['Y', 'Y']},
            {(1, 0): ['X', 'Y'], (0, 0): ['X', 'X']},
            {(1, 0): ['X', 'Y'], (0, 0): ['Y', 'X']},
            {(1, 0): ['X', 'Y'], (0, 0): ['X', 'Y']},
            {(1, 0): ['X', 'Y'], (0, 0): ['Y', 'Y']},
            {(1, 0): ['Y', 'Y'], (0, 0): ['X', 'X']},
            {(1, 0): ['Y', 'Y'], (0, 0): ['Y', 'X']},
            {(1, 0): ['Y', 'Y'], (0, 0): ['X', 'Y']},
            {(1, 0): ['Y', 'Y'], (0, 0): ['Y', 'Y']} ]

    def to_tuple(d):
        for key, value in d.items():
            return (tuple(key), tuple(value))

    assert set(map(to_tuple, result)) == set(map(to_tuple, expected))
开发者ID:spirali,项目名称:qit,代码行数:30,代码来源:test_mapping.py


示例15: test_map_in_map

def test_map_in_map():
    def prepare_map (start, size):
        return dict((start + i, start * i) for i in range(size))

    ctx = Qit()
    d = dict((i, prepare_map(i, 10)) for i in range(3))
    assert ctx.run(Map(Int(), Map(Int(), Int())).value(d)) == d
开发者ID:spirali,项目名称:qit,代码行数:7,代码来源:test_map.py


示例16: test_struct_variable

def test_struct_variable():
    ctx = Qit()
    s = Struct(Int(), Int())
    s2 = Struct(s, Int(), s)
    x = Variable(s2, "x")
    result = ctx.run(x, args={x: ((11,12), 13, (5, 2))})
    assert result == ((11,12), 13, (5, 2))
开发者ID:spirali,项目名称:qit,代码行数:7,代码来源:test_struct.py


示例17: test_system_rule_variable

def test_system_rule_variable():
    ctx = Qit()
    x = Variable(Int(), "x")
    f = Function("f").takes(Int(), "a").returns(Int()).reads(x).code("return x;")
    s = System(Int().values(5), (f,))
    result = ctx.run(s.states(3).iterate(), args={"x": 5})
    assert result == [5]
开发者ID:msurkovsky,项目名称:qit,代码行数:7,代码来源:test_system.py


示例18: test_filter_empty

def test_filter_empty():
    r = Range(5)
    q = Qit()

    f = Function("filter").returns(Bool()).takes(r.type, "r").code("return false;")

    assert len(q.run(r.iterate().filter(f))) == 0
开发者ID:msurkovsky,项目名称:qit,代码行数:7,代码来源:test_filter.py


示例19: test_min_step_range_iterate_variables

def test_min_step_range_iterate_variables():
    x = Variable(Int(), "x")
    y = Variable(Int(), "y")
    z = Variable(Int(), "z")
    expr = Range(x, y, z).iterate()
    c = Qit()
    assert list(range(10, 20, 4)) == c.run(expr, args={"x": 10, "y": 20, "z": 4})
开发者ID:msurkovsky,项目名称:qit,代码行数:7,代码来源:test_range.py


示例20: test_vector_constructor

def test_vector_constructor():
    ctx = Qit()
    s = Struct(Int(), Int())
    v = Vector(s)
    x = Variable(s, "x")
    result = ctx.run(v.value([x, s.value((7, 2)), (1, 2)]),
            args={x: (11,12)})
    assert result == [ (11, 12), (7, 2), (1, 2) ]
开发者ID:spirali,项目名称:qit,代码行数:8,代码来源:test_vector.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mock.mock函数代码示例发布时间:2022-05-27
下一篇:
Python testutils.ConnectingTestCase类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap