Skip to content

Commit a8ab0c1

Browse files
adding more tests
1 parent cccc520 commit a8ab0c1

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

code/tests/cases/test_jellyfish.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,63 @@ FOSSIL_TEST_CASE(c_test_jellyfish_reason_fuzzy) {
168168
ASSUME_ITS_EQUAL_CSTR(out4, "Unknown");
169169
}
170170

171+
FOSSIL_TEST_CASE(c_test_jellyfish_reason_chain) {
172+
fossil_jellyfish_chain chain;
173+
fossil_jellyfish_init(&chain);
174+
175+
fossil_jellyfish_learn(&chain, "a", "b");
176+
fossil_jellyfish_learn(&chain, "b", "c");
177+
fossil_jellyfish_learn(&chain, "c", "d");
178+
179+
// Depth 0 returns input
180+
const char *out0 = fossil_jellyfish_reason_chain(&chain, "a", 0);
181+
ASSUME_ITS_EQUAL_CSTR(out0, "a");
182+
183+
// Depth 1 returns first reasoning
184+
const char *out1 = fossil_jellyfish_reason_chain(&chain, "a", 1);
185+
ASSUME_ITS_EQUAL_CSTR(out1, "b");
186+
187+
// Depth 2 returns second reasoning
188+
const char *out2 = fossil_jellyfish_reason_chain(&chain, "a", 2);
189+
ASSUME_ITS_EQUAL_CSTR(out2, "c");
190+
191+
// Depth 3 returns third reasoning
192+
const char *out3 = fossil_jellyfish_reason_chain(&chain, "a", 3);
193+
ASSUME_ITS_EQUAL_CSTR(out3, "d");
194+
195+
// Depth greater than chain returns last found
196+
const char *out4 = fossil_jellyfish_reason_chain(&chain, "a", 10);
197+
ASSUME_ITS_EQUAL_CSTR(out4, "d");
198+
199+
// Unknown input returns "Unknown"
200+
const char *out5 = fossil_jellyfish_reason_chain(&chain, "z", 2);
201+
ASSUME_ITS_EQUAL_CSTR(out5, "Unknown");
202+
}
203+
204+
FOSSIL_TEST_CASE(c_test_jellyfish_decay_confidence) {
205+
fossil_jellyfish_chain chain;
206+
fossil_jellyfish_init(&chain);
207+
208+
fossil_jellyfish_learn(&chain, "x", "y");
209+
fossil_jellyfish_learn(&chain, "foo", "bar");
210+
211+
// Set confidence to a known value
212+
chain.memory[0].confidence = 0.5f;
213+
chain.memory[1].confidence = 0.1f;
214+
215+
fossil_jellyfish_decay_confidence(&chain, 0.2f);
216+
217+
// First block should have confidence 0.3
218+
ASSUME_ITS_TRUE(chain.memory[0].confidence > 0.29f && chain.memory[0].confidence < 0.31f);
219+
// Second block should be marked invalid (confidence < 0.05)
220+
ASSUME_ITS_TRUE(chain.memory[1].valid == 0);
221+
222+
// After cleanup, only valid blocks remain
223+
fossil_jellyfish_cleanup(&chain);
224+
ASSUME_ITS_EQUAL_SIZE(chain.count, 1);
225+
ASSUME_ITS_EQUAL_CSTR(chain.memory[0].input, "x");
226+
}
227+
171228
// * * * * * * * * * * * * * * * * * * * * * * * *
172229
// * Fossil Logic Test Pool
173230
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -182,6 +239,8 @@ FOSSIL_TEST_GROUP(c_jellyfish_tests) {
182239
FOSSIL_TEST_ADD(c_jellyfish_fixture, c_test_jellyfish_chain_save_fail);
183240
FOSSIL_TEST_ADD(c_jellyfish_fixture, c_test_jellyfish_chain_load_fail);
184241
FOSSIL_TEST_ADD(c_jellyfish_fixture, c_test_jellyfish_reason_fuzzy);
242+
FOSSIL_TEST_ADD(c_jellyfish_fixture, c_test_jellyfish_reason_chain);
243+
FOSSIL_TEST_ADD(c_jellyfish_fixture, c_test_jellyfish_decay_confidence);
185244

186245
FOSSIL_TEST_REGISTER(c_jellyfish_fixture);
187246
} // end of tests

code/tests/cases/test_jellyfish.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,47 @@ FOSSIL_TEST_CASE(cpp_test_jellyfishai_load_nonexistent_file) {
152152
ASSUME_ITS_TRUE(result != 0);
153153
}
154154

155+
FOSSIL_TEST_CASE(cpp_test_jellyfishai_reason_chain_basic) {
156+
JellyfishAI ai;
157+
ai.learn("sun", "star");
158+
ai.learn("star", "celestial");
159+
160+
// Depth 0: should only show direct reasoning
161+
std::string chain0 = ai.reason_chain("sun", 0);
162+
ASSUME_ITS_TRUE(chain0.find("star") != std::string::npos);
163+
164+
// Depth 1: should show one level of reasoning
165+
std::string chain1 = ai.reason_chain("sun", 1);
166+
ASSUME_ITS_TRUE(chain1.find("star") != std::string::npos);
167+
ASSUME_ITS_TRUE(chain1.find("celestial") != std::string::npos);
168+
169+
// Unknown input
170+
std::string chain_unknown = ai.reason_chain("moon", 1);
171+
ASSUME_ITS_EQUAL_CSTR(chain_unknown.c_str(), "Unknown");
172+
}
173+
174+
FOSSIL_TEST_CASE(cpp_test_jellyfishai_decay_confidence) {
175+
JellyfishAI ai;
176+
ai.learn("alpha", "beta");
177+
ai.learn("gamma", "delta");
178+
179+
// Optionally, get confidence before decay if API allows
180+
// For now, just call decay and check chain is still valid
181+
ai.decay_confidence(0.5f);
182+
183+
// After decay, chain should still have same count
184+
ASSUME_ITS_EQUAL_SIZE(ai.get_chain().count, 2);
185+
186+
// Decay with 0.0 (no decay)
187+
ai.decay_confidence(0.0f);
188+
ASSUME_ITS_EQUAL_SIZE(ai.get_chain().count, 2);
189+
190+
// Decay with 1.0 (full decay)
191+
ai.decay_confidence(1.0f);
192+
// Chain should still exist, but confidence values would be 0 if accessible
193+
ASSUME_ITS_EQUAL_SIZE(ai.get_chain().count, 2);
194+
}
195+
155196
// * * * * * * * * * * * * * * * * * * * * * * * *
156197
// * Fossil Logic Test Pool
157198
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -165,6 +206,8 @@ FOSSIL_TEST_GROUP(cpp_jellyfish_tests) {
165206
FOSSIL_TEST_ADD(cpp_jellyfish_fixture, cpp_test_jellyfishai_save_and_load);
166207
FOSSIL_TEST_ADD(cpp_jellyfish_fixture, cpp_test_jellyfishai_load_nonexistent_file);
167208
FOSSIL_TEST_ADD(cpp_jellyfish_fixture, cpp_test_jellyfishai_reason_fuzzy_exact_and_fuzzy);
209+
FOSSIL_TEST_ADD(cpp_jellyfish_fixture, cpp_test_jellyfishai_reason_chain_basic);
210+
FOSSIL_TEST_ADD(cpp_jellyfish_fixture, cpp_test_jellyfishai_decay_confidence);
168211

169212
FOSSIL_TEST_REGISTER(cpp_jellyfish_fixture);
170213
} // end of tests

0 commit comments

Comments
 (0)