-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_quick.py
More file actions
executable file
·44 lines (35 loc) · 1.28 KB
/
Copy pathtest_quick.py
File metadata and controls
executable file
·44 lines (35 loc) · 1.28 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
#!/usr/bin/env python3
"""
快速测试脚本
验证代码进化实验室是否正常工作
"""
from evolution_engine import EvolutionEngine
from code_executor import CodeExecutor
print("🧬 代码进化实验室 - 快速测试")
print("=" * 50)
# 测试 1:代码执行器
print("\n📝 测试 1:代码执行器")
executor = CodeExecutor()
bubble_sort = """def sort_array(arr):
n = len(arr)
for i in range(n):
for j in range(n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr"""
time_taken = executor.measure_time(bubble_sort)
print(f"✅ 冒泡排序耗时: {time_taken:.6f}s")
correct, message = executor.test_correctness(bubble_sort)
print(f"✅ 正确性测试: {message}")
# 测试 2:进化引擎
print("\n📝 测试 2:进化引擎")
engine = EvolutionEngine()
# 测试 3:快速进化(5 代)
print("\n📝 测试 3:快速进化(5 代)")
result = engine.evolve(bubble_sort, generations=5, variants_per_gen=2)
print("\n" + "=" * 50)
print("🎉 测试完成!")
print(f"最终性能: {result['final_time']:.6f}s")
print(f"总提升: {((result['history'][0]['time'] - result['final_time']) / result['history'][0]['time'] * 100):.1f}%")
print("\n最终代码:")
print(result['final_code'])