Ejemplo n.º 1
0
def test_alt():
    x = aida.Const('Alice')
    other_names = aida.Choices('Bob', 'Chris', seed=42)
    ctx = aida.Ctx()
    alt = aida.create_alt(x, other_names)

    assert aida.render(alt, ctx) == 'Alice'
    assert aida.render(alt, ctx) == 'Bob'
Ejemplo n.º 2
0
def test_in_ctx():
    ctx = aida.Ctx()
    k = aida.Const('Alice')
    branch = aida.Branch(k.in_ctx(), 'yes', 'no')

    assert aida.render(branch, ctx=ctx) == 'no'

    k.render(ctx)
    assert aida.render(branch, ctx=ctx) == 'yes'
Ejemplo n.º 3
0
def test_arithmetic():
    ctx = aida.Ctx()
    x = aida.Var('x')
    cond = (x + 1) > 2

    x.assign(2)
    assert cast(Operation, cond.value).render(ctx)

    x.assign(1)
    assert not cast(Operation, cond.value).render(ctx)
Ejemplo n.º 4
0
def test_sentence_ctx():
    ref = aida.create_ref('Geralt of Rivia', 'Geralt')
    sentence = aida.Empty + 'Toss a coin to' | ref + '.'

    ctx = aida.Ctx()
    assert aida.render(sentence, ctx=ctx) == 'Toss a coin to Geralt of Rivia.'
    assert aida.render(sentence, ctx=ctx) == 'Toss a coin to Geralt.'
    assert aida.render(sentence, ctx=ctx) == 'Toss a coin to Geralt.'

    sentence2 = ref | 'is nice.'
    assert aida.render(sentence2, ctx=ctx) == 'Geralt is nice.'
Ejemplo n.º 5
0
def test_concat():
    x = aida.Var('name')
    x.assign('Alice')
    sent = aida.Const('good')
    ctx = aida.Ctx()

    node = x | 'is a' | sent | 'person.'
    assert aida.render(node, ctx) == 'Alice is a good person.'

    x.assign('Bob')
    assert aida.render(node, ctx) == 'Bob is a good person.'