feat: rebuild CSP practice workflow, UX and automation
这个提交包含在:
@@ -0,0 +1,75 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "csp/db/sqlite_db.h"
|
||||
#include "csp/services/auth_service.h"
|
||||
#include "csp/services/contest_service.h"
|
||||
#include "csp/services/submission_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("contest service leaderboard") {
|
||||
auto db = csp::db::SqliteDb::OpenMemory();
|
||||
csp::db::ApplyMigrations(db);
|
||||
csp::db::SeedDemoData(db);
|
||||
|
||||
csp::services::AuthService auth(db);
|
||||
const auto u1 = auth.Register("contest_user_1", "password123");
|
||||
const auto u2 = auth.Register("contest_user_2", "password123");
|
||||
|
||||
csp::services::ContestService contest(db);
|
||||
const auto contests = contest.ListContests();
|
||||
REQUIRE_FALSE(contests.empty());
|
||||
|
||||
const int64_t contest_id = contests.front().id;
|
||||
contest.Register(contest_id, u1.user_id);
|
||||
contest.Register(contest_id, u2.user_id);
|
||||
|
||||
const auto problems = contest.ListContestProblems(contest_id);
|
||||
REQUIRE_FALSE(problems.empty());
|
||||
const int64_t problem_id = problems.front().id;
|
||||
|
||||
csp::services::SubmissionService submissions(db);
|
||||
|
||||
csp::services::SubmissionCreateRequest r1;
|
||||
r1.user_id = u1.user_id;
|
||||
r1.problem_id = problem_id;
|
||||
r1.contest_id = contest_id;
|
||||
r1.language = "cpp";
|
||||
r1.code = kAcCode;
|
||||
const auto s1 = submissions.CreateAndJudge(r1);
|
||||
REQUIRE(s1.status == csp::domain::SubmissionStatus::AC);
|
||||
|
||||
csp::services::SubmissionCreateRequest r2;
|
||||
r2.user_id = u2.user_id;
|
||||
r2.problem_id = problem_id;
|
||||
r2.contest_id = contest_id;
|
||||
r2.language = "cpp";
|
||||
r2.code = kWaCode;
|
||||
const auto s2 = submissions.CreateAndJudge(r2);
|
||||
REQUIRE(s2.status == csp::domain::SubmissionStatus::WA);
|
||||
|
||||
const auto board = contest.Leaderboard(contest_id);
|
||||
REQUIRE(board.size() >= 2);
|
||||
REQUIRE(board.front().user_id == u1.user_id);
|
||||
REQUIRE(board.front().solved >= 1);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户