feat: rebuild CSP practice workflow, UX and automation
这个提交包含在:
@@ -0,0 +1,86 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "csp/db/sqlite_db.h"
|
||||
#include "csp/domain/enum_strings.h"
|
||||
#include "csp/services/auth_service.h"
|
||||
#include "csp/services/problem_service.h"
|
||||
#include "csp/services/submission_service.h"
|
||||
#include "csp/services/wrong_book_service.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const char* kAcCode = R"CPP(#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int main() {
|
||||
long long a, b;
|
||||
if (!(cin >> a >> b)) return 0;
|
||||
cout << (a + b) << "\n";
|
||||
return 0;
|
||||
}
|
||||
)CPP";
|
||||
|
||||
const char* kWaCode = R"CPP(#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int main() {
|
||||
cout << 0 << "\n";
|
||||
return 0;
|
||||
}
|
||||
)CPP";
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("submission service judge and wrong-book flow") {
|
||||
auto db = csp::db::SqliteDb::OpenMemory();
|
||||
csp::db::ApplyMigrations(db);
|
||||
csp::db::SeedDemoData(db);
|
||||
|
||||
csp::services::AuthService auth(db);
|
||||
const auto user = auth.Register("submit_user", "password123");
|
||||
|
||||
csp::services::ProblemService problems(db);
|
||||
csp::services::ProblemQuery q;
|
||||
const auto list = problems.List(q);
|
||||
REQUIRE_FALSE(list.items.empty());
|
||||
const int64_t problem_id = list.items.front().id;
|
||||
|
||||
csp::services::SubmissionService submissions(db);
|
||||
csp::services::WrongBookService wrong_book(db);
|
||||
|
||||
csp::services::SubmissionCreateRequest bad;
|
||||
bad.user_id = user.user_id;
|
||||
bad.problem_id = problem_id;
|
||||
bad.language = "cpp";
|
||||
bad.code = kWaCode;
|
||||
|
||||
const auto bad_result = submissions.CreateAndJudge(bad);
|
||||
REQUIRE(bad_result.status == csp::domain::SubmissionStatus::WA);
|
||||
|
||||
const auto wb_after_bad = wrong_book.ListByUser(user.user_id);
|
||||
REQUIRE_FALSE(wb_after_bad.empty());
|
||||
|
||||
csp::services::SubmissionCreateRequest good;
|
||||
good.user_id = user.user_id;
|
||||
good.problem_id = problem_id;
|
||||
good.language = "cpp";
|
||||
good.code = kAcCode;
|
||||
|
||||
const auto good_result = submissions.CreateAndJudge(good);
|
||||
REQUIRE(good_result.status == csp::domain::SubmissionStatus::AC);
|
||||
|
||||
bool still_in_wrong_book = false;
|
||||
for (const auto& row : wrong_book.ListByUser(user.user_id)) {
|
||||
if (row.item.problem_id == problem_id) {
|
||||
still_in_wrong_book = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
REQUIRE_FALSE(still_in_wrong_book);
|
||||
|
||||
const auto run_only =
|
||||
submissions.RunOnlyCpp(R"CPP(#include <iostream>
|
||||
int main(){std::cout<<42<<"\n";}
|
||||
)CPP",
|
||||
"");
|
||||
REQUIRE(run_only.status == csp::domain::SubmissionStatus::Running);
|
||||
REQUIRE(run_only.stdout_text == "42\n");
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户