#include "mind_strategy.hpp"
#include "text_feature.hpp"
#include <cstdio>
#include <string>
#include <cstdlib>
using namespace quant;
static int checks = 0, fails = 0;
static void check(const char* name, bool ok, const char* detail = "") {
++checks;
if (!ok) ++fails;
std::printf("[%s] %s %s\n", ok ? "PASS" : "FAIL", name, detail);
}
int main() {
std::string path = "/tmp/test_mind_model.json";
MindStrategy s1;
check("cold start load missing", !s1.load_model("/tmp/nonexistent.json"));
Bar bar{};
bar.volume = 1500.0;
Indicators ind{};
ind.rsi = 65.2;
ind.trend_score = 0.8;
ind.atr = 2.3;
Position pos{};
pos.unrealized_pnl = 120.5;
std::string a = s1.on_bar(bar, ind, pos);
bool action_valid = (a == "buy" || a == "sell" || a == "hold");
check("decide returns valid action", action_valid, a.c_str());
size_t mem_before = s1.mind().memories().size();
s1.on_filled(120.5);
size_t mem_after = s1.mind().memories().size();
check("learn grows memory", mem_after == mem_before + 1);
s1.save_model(path);
check("save model", std::ifstream(path).is_open());
MindStrategy s2;
check("reload model", s2.load_model(path));
check("reload restores memory", s2.mind().memories().size() == mem_after);
s1.evolve();
check("evolve ok", true);
std::string a2 = s1.on_bar(bar, ind, pos);
check("second decide valid", a2 == "buy" || a2 == "sell" || a2 == "hold", a2.c_str());
MindStrategy s3;
s3.on_bar(bar, ind, pos, "Bitcoin crashes! Regulators crackdown on exchange! Sell!");
std::string a3 = s3.on_bar(bar, ind, pos, "暴跌 恐慌 监管打压 黑客攻击");
check("text-driven decide valid", a3 == "buy" || a3 == "sell" || a3 == "hold", a3.c_str());
TextFeature tf;
auto feat = tf.extract("Bitcoin crashes! Regulators crackdown! Sell!");
check("text sentiment negative", feat.sentiment < 0.0);
check("text bearish ratio > 0", feat.bearish_ratio > 0.0);
std::remove(path.c_str());
std::printf("\n==== %d checks, %d fails ====\n", checks, fails);
return fails ? 1 : 0;
}