Exemplo n.º 1
0
def test_procedure_check_occurrence():
    interpretation = Interpretation(type_groups)
    atoms = [
        StateAtom(1, 1),
        StateAtom(0, 1),
        ActionAtom(Action()),
        StateAtom(0, 0)
    ]
    for atom in atoms:
        interpretation.extend(atom)
    procedure = Procedure([[atoms[1], atoms[2]]])
    procedure.connect_with_children()
    child_occurrence = StorithmOccurrence(atoms[2], 2, 2)

    expected_occurrence = StorithmOccurrence(procedure, 1, 2)
    occurrence = procedure.check_occurrence(interpretation, child_occurrence,
                                            (0, 1))
    assert expected_occurrence == occurrence
Exemplo n.º 2
0
def test_procedure_create():
    trial_count = 500
    seed(500)

    interpretation = Interpretation(type_groups)
    atoms = [
        ActionAtom(Action(0)),
        ActionAtom(Action(1)),
        ActionAtom(Action(2)),
        StateAtom(0, 0),
        StateAtom(0, 0)
    ]
    procedure = Procedure([[atoms[1], atoms[2]]])
    procedure_occurrence = StorithmOccurrence(procedure, 1, 2)
    for atom in atoms:
        interpretation.extend(atom)
    interpretation.add(procedure_occurrence)

    expected_children = [[atoms[0], procedure]]
    expected_storithm = Procedure(expected_children)
    expected_proposal = StorithmOccurrence(expected_storithm, 0, 2)
    proposed = False
    for i in range(trial_count):
        proposal = Procedure.create(interpretation, lambda: 1)
        if same(proposal, expected_proposal):
            proposed = True
            break
    assert proposed
Exemplo n.º 3
0
def test_conditional_statement_check_occurrence():
    interpretation = Interpretation(type_groups)
    atoms = [StateAtom(1, 1), ActionAtom(Action(0))]
    interpretation.extend()
    for atom in atoms:
        interpretation.add_at_the_end(atom)
    condition = Condition([atoms[0]])
    interpretation.add_at_the_end(condition)

    conditional_statement = ConditionalStatement(condition, atoms[1])
    conditional_statement.connect_with_children()

    occurrence = conditional_statement.check_occurrence(
        interpretation, StorithmOccurrence(condition, 0, 0),
        ConditionalStatement.POSITION_CONDITION)
    expected_occurrence = StorithmOccurrence(conditional_statement, 0, 0)
    assert expected_occurrence == occurrence
Exemplo n.º 4
0
def test_state_atom_create():
    trial_count = 5000
    seed(500)

    interpretation = Interpretation(type_groups)
    interpretation.internal_trajectory.observations = [[0, 1], [1, 1]]
    interpretation.internal_trajectory.actions = [Action(0)]

    expected_proposal = StorithmOccurrence(StateAtom(0, 1), 1, 1)
    proposed = False
    for i in range(trial_count):
        proposal = StateAtom.create(interpretation, lambda: choice([0, 1]))
        if same(proposal, expected_proposal):
            proposed = True
            break
    assert proposed
Exemplo n.º 5
0
def test_condition_check_occurrence():
    interpretation = Interpretation(type_groups)
    atoms = [StateAtom(1, 1), StateAtom(0, 1), StateAtom(0, 0)]
    interpretation.extend()
    for atom in atoms[0:2]:
        interpretation.add_at_the_end(atom)
    condition = Condition(atoms[1:3])
    condition.connect_with_children()
    child_occurrence = StorithmOccurrence(atoms[1], 0, 0)

    occurrence = condition.check_occurrence(interpretation, child_occurrence,
                                            (0, 1))
    assert occurrence is None

    interpretation.add_at_the_end(atoms[2])
    occurrence = condition.check_occurrence(interpretation, child_occurrence,
                                            (0, 1))
    expected_occurrence = StorithmOccurrence(condition, 0, 0)
    assert expected_occurrence == occurrence
Exemplo n.º 6
0
def test_loop_create():
    trial_count = 5000
    seed(500)

    atoms = [StateAtom(1, 1), ActionAtom(Action(0))]
    condition = Condition([atoms[0]])
    interpretation = Interpretation(type_groups)
    for _ in range(5):
        interpretation.extend()
        interpretation.add_at_the_end(atoms[0])
        interpretation.add_at_the_end(atoms[1])
        interpretation.add_at_the_end(condition)

    loop = Loop(condition, atoms[1])
    expected_proposal = StorithmOccurrence(loop, 0, 4)
    proposed = False
    for i in range(trial_count):
        proposal = Loop.create(interpretation, lambda: 1)
        if same(proposal, expected_proposal):
            proposed = True
            break
    assert proposed
Exemplo n.º 7
0
def test_conditional_statement_create():
    trial_count = 5000
    seed(500)

    interpretation = Interpretation(type_groups)
    atoms = [StateAtom(1, 1), ActionAtom(Action(0))]
    interpretation.extend()
    for atom in atoms:
        interpretation.add_at_the_end(atom)
    condition = Condition([atoms[0]])
    interpretation.add_at_the_end(condition)

    conditional_statement = ConditionalStatement(condition, atoms[1])
    expected_proposal = StorithmOccurrence(conditional_statement, 0, 0)

    proposed = False
    for i in range(trial_count):
        proposal = ConditionalStatement.create(interpretation, lambda: 0)
        if same(proposal, expected_proposal):
            proposed = True
            break
    assert proposed
Exemplo n.º 8
0
def test_condition_create():
    trial_count = 500
    seed(500)

    interpretation = Interpretation(type_groups)
    atoms = [StateAtom(1, 1), StateAtom(0, 1), StateAtom(0, 0)]
    interpretation.extend()
    for atom in atoms:
        interpretation.add_at_the_end(atom)

    expected_proposal = StorithmOccurrence(Condition(atoms[1:3]), 0, 0)

    proposed = False
    for i in range(trial_count):
        proposal = Condition.create(interpretation, lambda: 0)
        if same(proposal, expected_proposal):
            proposed = True
            break
    assert proposed