#include #include "csp/db/sqlite_db.h" #include "csp/services/problem_service.h" TEST_CASE("problem service list/get") { auto db = csp::db::SqliteDb::OpenMemory(); csp::db::ApplyMigrations(db); csp::db::SeedDemoData(db); db.Exec( "INSERT INTO problems(slug,title,statement_md,difficulty,source,statement_url,llm_profile_json," "sample_input,sample_output,created_at)" "VALUES('luogu-p1000','P1000','x',2,'luogu:P1000','https://www.luogu.com.cn/problem/P1000','{}','','',100);"); db.Exec( "INSERT INTO problems(slug,title,statement_md,difficulty,source,statement_url,llm_profile_json," "sample_input,sample_output,created_at)" "VALUES('luogu-p1001','P1001','x',3,'luogu:P1001','https://www.luogu.com.cn/problem/P1001','{}','','',100);"); db.Exec("INSERT INTO problem_tags(problem_id,tag) VALUES((SELECT id FROM problems WHERE slug='luogu-p1000'),'csp-j');"); db.Exec("INSERT INTO problem_tags(problem_id,tag) VALUES((SELECT id FROM problems WHERE slug='luogu-p1001'),'csp-s');"); csp::services::ProblemService svc(db); csp::services::ProblemQuery q_all; const auto all = svc.List(q_all); REQUIRE(all.total_count >= 5); REQUIRE(all.items.size() >= 5); csp::services::ProblemQuery q_dp; q_dp.tag = "dp"; const auto dp = svc.List(q_dp); REQUIRE(dp.total_count >= 1); REQUIRE(dp.items.size() >= 1); csp::services::ProblemQuery q_source; q_source.source_prefix = "luogu:"; const auto luogu = svc.List(q_source); REQUIRE(luogu.total_count == 2); REQUIRE(luogu.items.size() == 2); csp::services::ProblemQuery q_tags; q_tags.tags = {"csp-j", "csp-s"}; const auto csp = svc.List(q_tags); REQUIRE(csp.total_count == 2); REQUIRE(csp.items.size() == 2); const auto one = svc.GetById(all.items.front().id); REQUIRE(one.has_value()); REQUIRE(one->id == all.items.front().id); }