#include "fiko/parametre/depo.hpp" #include "fiko_test.hpp" using namespace fiko; using namespace fiko::parametre; FIKO_TEST(depo_temel_cozum) { ParametreDeposu d; d.ayarla("a", "10"); d.ayarla("b", "a * 2"); d.ayarla("c", "a + b"); // 10 + 20 = 30 FIKO_KONTROL(d.cozumle()); f64 v = 0; FIKO_KONTROL(d.deger("a", v) && v == 10.0); FIKO_KONTROL(d.deger("b", v) && v == 20.0); FIKO_KONTROL(d.deger("c", v) && v == 30.0); } FIKO_TEST(depo_sira_bagimsiz) { // Bağımlı parametre bağımlılığından ÖNCE tanımlansa da topolojik çözülür. ParametreDeposu d; d.ayarla("alan", "genislik * yukseklik"); // önce d.ayarla("genislik", "100"); d.ayarla("yukseklik", "alan_orani * genislik"); d.ayarla("alan_orani", "0.5"); FIKO_KONTROL(d.cozumle()); f64 v = 0; FIKO_KONTROL(d.deger("genislik", v) && v == 100.0); FIKO_KONTROL(d.deger("yukseklik", v) && v == 50.0); FIKO_KONTROL(d.deger("alan", v) && v == 5000.0); } FIKO_TEST(depo_dongu_tespiti) { ParametreDeposu d; d.ayarla("a", "b + 1"); d.ayarla("b", "a + 1"); // döngü FIKO_KONTROL(!d.cozumle()); FIKO_KONTROL(!d.bul("a")->cozuldu && !d.bul("a")->hata.empty()); FIKO_KONTROL(!d.bul("b")->cozuldu && !d.bul("b")->hata.empty()); } FIKO_TEST(depo_bilinmeyen_referans) { ParametreDeposu d; d.ayarla("a", "yok_boyle + 1"); FIKO_KONTROL(!d.cozumle()); FIKO_KONTROL(!d.bul("a")->cozuldu); FIKO_KONTROL(d.bul("a")->hata.find("bilinmeyen") != std::string::npos); } FIKO_TEST(depo_guncelle_ve_yeniden_coz) { ParametreDeposu d; d.ayarla("a", "10"); d.ayarla("b", "a * 3"); FIKO_KONTROL(d.cozumle()); f64 v = 0; FIKO_KONTROL(d.deger("b", v) && v == 30.0); // a güncellenince b yeniden çözülünce değişir. d.ayarla("a", "20"); FIKO_KONTROL(d.cozumle()); FIKO_KONTROL(d.deger("b", v) && v == 60.0); // sil d.sil("b"); FIKO_KONTROL(d.sayi() == 1); FIKO_KONTROL(!d.deger("b", v)); // artık yok } FIKO_TEST(depo_birimle_deger) { ParametreDeposu d; d.ayarla("genislik", "25.4", "mm"); d.ayarla("aci", "180", "deg"); FIKO_KONTROL(d.cozumle()); f64 v = 0; // mm parametresi → inch FIKO_KONTROL(d.degerBirimle("genislik", "in", v)); FIKO_YAKIN(v, 1.0, 1e-9); // aynı birim → kimlik FIKO_KONTROL(d.degerBirimle("genislik", "mm", v) && v == 25.4); // deg → rad FIKO_KONTROL(d.degerBirimle("aci", "rad", v)); FIKO_YAKIN(v, 3.14159265358979, 1e-9); // boyut uyumsuz (mm → deg) → false FIKO_KONTROL(!d.degerBirimle("genislik", "deg", v)); // çözülmemiş/yok → false FIKO_KONTROL(!d.degerBirimle("yok", "mm", v)); } FIKO_TEST(depo_fonksiyon_ve_sabit) { ParametreDeposu d; d.ayarla("yaricap", "5"); d.ayarla("cevre", "2 * pi * yaricap"); d.ayarla("alan", "pi * yaricap^2"); FIKO_KONTROL(d.cozumle()); f64 v = 0; FIKO_KONTROL(d.deger("cevre", v)); FIKO_YAKIN(v, 2 * 3.14159265358979 * 5, 1e-6); FIKO_KONTROL(d.deger("alan", v)); FIKO_YAKIN(v, 3.14159265358979 * 25, 1e-6); }