-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_genotype.py
More file actions
110 lines (77 loc) · 3.12 KB
/
Copy pathtest_genotype.py
File metadata and controls
110 lines (77 loc) · 3.12 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pytest
from memevolve.evolution.genotype import (
MemoryGenotype,
EncodeConfig,
StoreConfig,
RetrieveConfig,
ManageConfig,
GenotypeFactory
)
import sys
# sys.path.insert(0, 'src') # No longer needed with package structure
def test_genotype_creation():
"""Test genotype creation."""
genotype = MemoryGenotype()
assert isinstance(genotype.encode, EncodeConfig)
assert isinstance(genotype.store, StoreConfig)
assert isinstance(genotype.retrieve, RetrieveConfig)
assert isinstance(genotype.manage, ManageConfig)
assert isinstance(genotype.metadata, dict)
def test_genome_id():
"""Test genome ID generation."""
genotype1 = MemoryGenotype()
genotype2 = MemoryGenotype()
id1 = genotype1.get_genome_id()
id2 = genotype2.get_genome_id()
assert len(id1) == 8
assert len(id2) == 8
assert id1 == id2
genotype3 = MemoryGenotype(encode=EncodeConfig(temperature=0.5))
id3 = genotype3.get_genome_id()
assert id3 != id1
def test_factory_baseline():
"""Test baseline genotype factory."""
genotype = GenotypeFactory.create_baseline_genotype()
assert isinstance(genotype, MemoryGenotype)
assert "lesson" in genotype.encode.encoding_strategies
assert genotype.store.backend_type == "json"
def test_factory_agentkb():
"""Test AgentKB genotype factory."""
genotype = GenotypeFactory.create_agentkb_genotype()
assert genotype.metadata["architecture"] == "agentkb"
assert "lesson" in genotype.encode.encoding_strategies
assert not genotype.encode.enable_abstractions
def test_factory_lightweight():
"""Test Lightweight genotype factory."""
genotype = GenotypeFactory.create_lightweight_genotype()
assert genotype.metadata["architecture"] == "lightweight"
assert genotype.encode.batch_size == 20
assert genotype.manage.auto_prune_threshold == 500
def test_factory_riva():
"""Test Riva genotype factory."""
genotype = GenotypeFactory.create_riva_genotype()
assert genotype.metadata["architecture"] == "riva"
assert genotype.store.backend_type == "vector"
assert genotype.retrieve.strategy_type == "hybrid"
def test_factory_cerebra():
"""Test Cerebra genotype factory."""
genotype = GenotypeFactory.create_cerebra_genotype()
assert genotype.metadata["architecture"] == "cerebra"
assert "tool" in genotype.encode.encoding_strategies
assert genotype.store.backend_type == "vector"
def test_genotype_serialization():
"""Test genotype JSON serialization/deserialization."""
original = MemoryGenotype(
encode=EncodeConfig(temperature=0.5),
store=StoreConfig(backend_type="json")
)
json_str = original.to_json()
restored = MemoryGenotype.from_json(json_str)
assert restored.encode.temperature == 0.5
assert restored.store.backend_type == "json"
def test_genotype_mutation():
"""Test genotype mutation."""
original = GenotypeFactory.create_baseline_genotype()
mutated = GenotypeFactory.mutate_genotype(original, mutate_probability=0.0)
assert mutated.encode.temperature == original.encode.temperature
assert mutated is not original