This commit is contained in:
2025-10-30 20:30:31 +09:00
commit 4660e519d4
15 changed files with 7602 additions and 0 deletions

54
checker/checker.cpp Normal file
View File

@@ -0,0 +1,54 @@
#include "testlib.h"
using ll = long long;
const double eps = 1e-5;
double parseDouble(const std::string &s, InStream &stream) {
double result;
// 1. sscanf로 숫자 파싱 시도
if (sscanf(s.c_str(), "%lf", &result) == 1) {
return result;
}
// 2. sscanf 실패 시, 특수 값인지 문자열 비교
if (s == "inf" || s == "+inf" || s == "INF" || s == "+INF")
return std::numeric_limits<double>::infinity();
if (s == "-inf" || s == "-INF")
return -std::numeric_limits<double>::infinity();
if (s == "nan" || s == "NaN" || s == "NAN")
return std::numeric_limits<double>::quiet_NaN();
// 3. 숫자도 아니고 특수 값도 아니면 오류 종료
// 'stream'을 사용해 어느 파일이 문제인지 정확히 리포트
stream.quitf(_fail, "Expected double, but %s found", s.c_str());
return 0; // Unreachable
}
int main(int argc, char *argv[]) {
registerTestlibCmd(argc, argv);
ll n = inf.readLong(1, (ll)1e9);
for (ll line = 1; line <= n; line++) {
double j = parseDouble(ans.readToken(), ans);
double p = parseDouble(ouf.readToken(), ouf);
ans.readEoln();
ouf.readEoln();
if (!doubleCompare(j, p, eps)) {
quitf(_wa,
"%lld-th line: expected '%.7f', found '%.7f'. "
"Absolute/Relative error > %.0e",
line, j, p, eps);
}
}
if (!ans.eof())
quitf(_pe, "Expected EOF in judge output, but found more data");
if (!ouf.eof())
quitf(_pe, "Expected EOF in bsb output, but found more data");
quitf(_ok, "OK: %lld lines compared within %.0e epsilon.", n, eps);
}