Skip to content

Commit 307c0f1

Browse files
Update test_jellyfish.cpp
1 parent 4b559bd commit 307c0f1

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

code/tests/cases/test_jellyfish.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,32 @@ FOSSIL_TEST_CASE(cpp_test_jellyfish_chain_save_and_load) {
9797
ai.learn("input1", "output1");
9898
ai.learn("input2", "output2");
9999

100+
// Set known confidence values to ensure they're saved/loaded properly
101+
fossil_jellyfish_chain& chain = ai.get_chain();
102+
chain.memory[0].confidence = 0.85f;
103+
chain.memory[1].confidence = 0.65f;
104+
100105
const char *filename = "test_jellyfish_save_load.jellyfish";
101106
bool save_result = ai.save(filename);
102107
ASSUME_ITS_TRUE(save_result);
103108

104109
JellyfishAI loaded;
105110
bool load_result = loaded.load(filename);
106111
ASSUME_ITS_TRUE(load_result);
112+
107113
const fossil_jellyfish_chain& loaded_chain = loaded.get_chain();
108114
ASSUME_ITS_EQUAL_SIZE(loaded_chain.count, 2);
115+
109116
ASSUME_ITS_EQUAL_CSTR(loaded_chain.memory[0].input, "input1");
117+
ASSUME_ITS_EQUAL_CSTR(loaded_chain.memory[0].output, "output1");
118+
ASSUME_ITS_EQUAL_CSTR(loaded_chain.memory[1].input, "input2");
110119
ASSUME_ITS_EQUAL_CSTR(loaded_chain.memory[1].output, "output2");
111120

121+
// Confirm confidence values persisted (within tolerance)
122+
ASSUME_ITS_TRUE(fabsf(loaded_chain.memory[0].confidence - 0.85f) < 0.01f);
123+
ASSUME_ITS_TRUE(fabsf(loaded_chain.memory[1].confidence - 0.65f) < 0.01f);
124+
125+
// Clean up
112126
remove(filename);
113127
}
114128

@@ -147,14 +161,27 @@ FOSSIL_TEST_CASE(cpp_test_jellyfish_decay_confidence) {
147161
JellyfishAI ai;
148162
ai.learn("a", "b");
149163
fossil_jellyfish_chain& chain = ai.get_chain();
164+
165+
// Set up one valid block
150166
chain.memory[0].confidence = 1.0f;
151167
chain.memory[0].valid = 1;
152168
chain.count = 1;
153169

154-
ai.decay_confidence(0.5f);
155-
ASSUME_ITS_TRUE(chain.memory[0].confidence < 1.0f);
156-
ai.decay_confidence(0.9f);
157-
ASSUME_ITS_TRUE(chain.memory[0].valid == 0 || chain.memory[0].confidence < 0.05f);
170+
// Simulate old timestamp to force decay
171+
time_t now = time(NULL);
172+
time_t past = now - 172800; // 2 days ago (48h)
173+
chain.memory[0].timestamp = (uint64_t)past * 1000; // assuming ms
174+
175+
ai.decay_confidence(0.0f); // decay_rate is unused but required by API
176+
177+
float conf = chain.memory[0].confidence;
178+
int valid = chain.memory[0].valid;
179+
180+
// Confidence should be decayed significantly (2 half-lives)
181+
ASSUME_ITS_TRUE(conf < 0.26f); // 0.5^2 = 0.25
182+
183+
// Should be invalidated if too low
184+
ASSUME_ITS_TRUE(valid == 0 || conf < 0.05f);
158185
}
159186

160187
FOSSIL_TEST_CASE(cpp_test_jellyfish_tokenize) {

0 commit comments

Comments
 (0)