def test_injector(): a = aida.Var('a') b = aida.Var('b') node = a | b inj = aida.Injector([a, b], node) inj.assign([{'a': 'a1', 'b': 'b1'}, {'a': 'a2', 'b': 'b2'}]) assert aida.render(inj) == 'a1 b1' assert aida.render(inj) == 'a2 b2'
def test_render_simple_choice(): x = aida.Var() x.assign('Alice') y = aida.Var() y.assign('Bob') choices = aida.Choices(x, y, seed=42) assert aida.render(choices) == 'Alice' x.assign('Chris') assert aida.render(choices) == 'Chris'
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)
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.'
def test_branch(): x = aida.Var('val') k = aida.Const(3) t = aida.Const(True) branch = aida.Branch((x > k) & (t == True), 'greater', 'not greater') x.assign(1) assert aida.render(branch) == 'not greater' x.assign(5) assert aida.render(branch) == 'greater' branch = aida.Branch((x > k) & (t == False), 'greater', 'not greater') assert aida.render(branch) == 'not greater'