-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_flowchart_agent.py
More file actions
70 lines (54 loc) · 1.88 KB
/
Copy pathtest_flowchart_agent.py
File metadata and controls
70 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Tests de caracterización para FlowchartAgent (portado desde Programming-Logic)."""
import pytest
from src.multiagent_core.flowchart_agent import FlowchartAgent
@pytest.fixture
def agent() -> FlowchartAgent:
return FlowchartAgent()
def test_genera_graph_td_para_funcion_con_if_else(agent: FlowchartAgent):
codigo = """
def clasificar_convergencia(error):
if error < 0.01:
estado = "Convergente"
else:
estado = "No convergente"
return estado
"""
resultado = agent.build_mermaid_flowchart(codigo)
assert "graph TD" in resultado
assert "-- Sí -->" in resultado
assert "-- No -->" in resultado
def test_genera_nodo_de_iteracion_para_for(agent: FlowchartAgent):
codigo = """
def simular_monte_carlo(muestras):
total = 0
for muestra in muestras:
total = total + muestra
return total
"""
resultado = agent.build_mermaid_flowchart(codigo)
assert "Para Iterar" in resultado
def test_genera_nodo_de_iteracion_para_while(agent: FlowchartAgent):
codigo = """
def metropolis_hastings(x0, n_iter):
x = x0
while n_iter > 0:
n_iter = n_iter - 1
return x
"""
resultado = agent.build_mermaid_flowchart(codigo)
assert "Mientras Iterar" in resultado
def test_mensaje_cuando_no_hay_funcion(agent: FlowchartAgent):
resultado = agent.build_mermaid_flowchart("x = 1 + 1")
assert "No se encontró una definición de función" in resultado
def test_mensaje_controlado_con_sintaxis_invalida(agent: FlowchartAgent):
resultado = agent.build_mermaid_flowchart("def foo(:\n pass")
assert resultado.startswith("%% Error al parsear código")
def test_node_counter_se_reinicia_en_cada_llamada(agent: FlowchartAgent):
codigo = """
def simple():
x = 1
return x
"""
primera = agent.build_mermaid_flowchart(codigo)
segunda = agent.build_mermaid_flowchart(codigo)
assert primera == segunda