judge: fix testlib compile

This commit is contained in:
undefined committed 2021-03-04 22:07:41 +08:00
1 parent e3355aa43c
commit f1f383c572
3 files changed
+75 -70

No files matched your search

+9 -1
View File
@@ -20,12 +20,20 @@ Hydro 开发群:709572015
Hydro 用户群:1085853538 Hydro 用户群:1085853538
Telegram [@webpack_exports_undefined](https://t.me/webpack_exports_undefined) Telegram [@webpack_exports_undefined](https://t.me/webpack_exports_undefined)
## 附加条款 ## 开源许可
本项目基于 AGPL v3 开源,同时添加部分附加条款。
非营利性组织可直接使用 Hydro。 非营利性组织可直接使用 Hydro。
营利性组织(培训机构等)需要支付少量授权费。详细信息请通过上方方式与开发者联系。 营利性组织(培训机构等)需要支付少量授权费。详细信息请通过上方方式与开发者联系。
对于小规模个人/学校用户,可提供免费评测服务(您无需本地安装评测机),详情请 [联系我们](#联系我们) 对于小规模个人/学校用户,可提供免费评测服务(您无需本地安装评测机),详情请 [联系我们](#联系我们)
在您部署 Hydro 时,需要保留底部的 `Powered by Hydro` 字样,其中的 `Hydro` 字样需指向 `hydro.js.org/本仓库/fork` 之一的链接。
若您对源码做出修改,同样需要以 AGPL v3 开源,您可以以 `Powered by Hydro, Modified by xxx` 格式在页脚注明。
此限制对以下模块仍然有效:
- Hydro 插件;
- 包括但不限于使用 http 协议与 Hydro 进行交互的组件;
若您需要对这些模块闭源处理,请考虑联系我们以购买商业许可。
鉴于 Mirai 处的 [不和谐事件](https://github.com/mamoe/mirai/issues/850) 对此项目做如下声明: 鉴于 Mirai 处的 [不和谐事件](https://github.com/mamoe/mirai/issues/850) 对此项目做如下声明:
- 项目开源不代表开发者有义务为您提供服务。 - 项目开源不代表开发者有义务为您提供服务。
+65 -68
View File
@@ -1,3 +1,4 @@
// https://github.com/MikeMirzayanov/testlib/blob/master/testlib.h
#ifndef _TESTLIB_H_ #ifndef _TESTLIB_H_
#define _TESTLIB_H_ #define _TESTLIB_H_
#define VERSION "0.9.24-SNAPSHOT" #define VERSION "0.9.24-SNAPSHOT"
@@ -174,7 +175,8 @@ static bool __testlib_prelimIsNaN(double r) {
volatile double ra = r; volatile double ra = r;
#ifndef __BORLANDC__ #ifndef __BORLANDC__
return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false); return ((ra != ra) == true) && ((ra == ra) == false) && ((1.0 > ra) == false) && ((1.0 < ra) == false);
#else return std::_isnan(ra); #else
return std::_isnan(ra);
#endif #endif
} }
static std::string removeDoubleTrailingZeroes(std::string value) { static std::string removeDoubleTrailingZeroes(std::string value) {
@@ -211,7 +213,8 @@ static double __testlib_nan() {
double nan; double nan;
std::memcpy(&nan, &llnan, sizeof(double)); std::memcpy(&nan, &llnan, sizeof(double));
return nan; return nan;
#else return NAN; #else
return NAN;
#endif #endif
} }
static bool __testlib_isInfinite(double r) { static bool __testlib_isInfinite(double r) {
@@ -273,7 +276,8 @@ static void __testlib_set_binary(std::FILE* file)
if (NULL != file) { if (NULL != file) {
#ifndef __BORLANDC__ #ifndef __BORLANDC__
_setmode(_fileno(file), O_BINARY); _setmode(_fileno(file), O_BINARY);
#else setmode(fileno(file), O_BINARY); #else
setmode(fileno(file), O_BINARY);
#endif #endif
} }
#endif #endif
@@ -316,8 +320,7 @@ private:
public: public:
static int version; static int version;
random_t(): seed(3905348978240129619LL) { random_t() : seed(3905348978240129619LL) {}
}
void setSeed(int argc, char* argv[]) { void setSeed(int argc, char* argv[]) {
random_t p; random_t p;
seed = 3905348978240129619LL; seed = 3905348978240129619LL;
@@ -333,7 +336,6 @@ public:
seed = _seed; seed = _seed;
} }
#ifndef __BORLANDC__ #ifndef __BORLANDC__
std::string next(const std::string& ptrn) { std::string next(const std::string& ptrn) {
pattern p(ptrn); pattern p(ptrn);
return p.next(*this); return p.next(*this);
@@ -345,7 +347,6 @@ public:
return p.next(*this); return p.next(*this);
} }
#endif #endif
int next(int n) { int next(int n) {
if (n <= 0)__testlib_fail("random_t::next(int n): n must be positive"); if (n <= 0)__testlib_fail("random_t::next(int n): n must be positive");
if ((n & -n) == n)return (int)((n * (long long)nextBits(31)) >> 31); if ((n & -n) == n)return (int)((n * (long long)nextBits(31)) >> 31);
@@ -805,7 +806,8 @@ const std::string outcomes[] = {
"fail", "fail",
#ifndef PCMS2 #ifndef PCMS2
"points", "points",
#else "relative-scoring", #else
"relative-scoring",
#endif #endif
"reserved", "reserved",
"reserved", "reserved",
@@ -831,16 +833,14 @@ public:
virtual int getLine() = 0; virtual int getLine() = 0;
virtual ~InputStreamReader() = 0; virtual ~InputStreamReader() = 0;
}; };
InputStreamReader::~InputStreamReader() { InputStreamReader::~InputStreamReader() {}
}
class StringInputStreamReader : public InputStreamReader { class StringInputStreamReader : public InputStreamReader {
private: private:
std::string s; std::string s;
size_t pos; size_t pos;
public: public:
StringInputStreamReader(const std::string& content): s(content), pos(0) { StringInputStreamReader(const std::string& content) : s(content), pos(0) {}
}
int curChar() { int curChar() {
if (pos >= s.length())return EOFC; if (pos >= s.length())return EOFC;
else return s[pos]; else return s[pos];
@@ -868,8 +868,7 @@ public:
bool eof() { bool eof() {
return pos >= s.length(); return pos >= s.length();
} }
void close() { void close() {}
}
}; };
class FileInputStreamReader : public InputStreamReader { class FileInputStreamReader : public InputStreamReader {
private: private:
@@ -898,8 +897,7 @@ private:
} }
public: public:
FileInputStreamReader(std::FILE* file, const std::string& name): file(file), name(name), line(1) { FileInputStreamReader(std::FILE* file, const std::string& name) : file(file), name(name), line(1) {}
}
int curChar() { int curChar() {
if (feof(file))return EOFC; if (feof(file))return EOFC;
else { else {
@@ -1201,8 +1199,7 @@ private:
} }
public: public:
Validator(): _testset("tests"), _group() { Validator() : _testset("tests"), _group() {}
}
std::string testset() const { std::string testset() const {
return _testset; return _testset;
} }
@@ -1274,8 +1271,7 @@ public:
struct TestlibFinalizeGuard { struct TestlibFinalizeGuard {
static bool alive; static bool alive;
int quitCount, readEofCount; int quitCount, readEofCount;
TestlibFinalizeGuard(): quitCount(0), readEofCount(0) { TestlibFinalizeGuard() : quitCount(0), readEofCount(0) {}
}
~TestlibFinalizeGuard() { ~TestlibFinalizeGuard() {
bool _alive = alive; bool _alive = alive;
alive = false; alive = false;
@@ -1386,7 +1382,8 @@ resultExitCode(TResult r) {
if (r == _unexpected_eof) if (r == _unexpected_eof)
#ifdef ENABLE_UNEXPECTED_EOF #ifdef ENABLE_UNEXPECTED_EOF
return UNEXPECTED_EOF_EXIT_CODE; return UNEXPECTED_EOF_EXIT_CODE;
#else return PE_EXIT_CODE; #else
return PE_EXIT_CODE;
#endif #endif
if (r >= _partially)return PC_BASE_EXIT_CODE + (r - _partially); if (r >= _partially)return PC_BASE_EXIT_CODE + (r - _partially);
return FAIL_EXIT_CODE; return FAIL_EXIT_CODE;
@@ -1398,7 +1395,8 @@ void InStream::textColor(
#if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); #if defined(ON_WINDOWS) && (!defined(_MSC_VER) || _MSC_VER > 1400)HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, color); SetConsoleTextAttribute(handle, color);
#endif #endif
#if !defined(ON_WINDOWS) && defined(__GNUC__)if (isatty(2)) { #if !defined(ON_WINDOWS) && defined(__GNUC__)
if (isatty(2)) {
switch (color) { switch (color) {
case LightRed: case LightRed:
fprintf(stderr, "\033[1;31m"); fprintf(stderr, "\033[1;31m");
@@ -1978,7 +1976,8 @@ long long InStream::readLong(long long minv, long long maxv, const std::string&
} }
std::vector<long long> InStream::readLongs(int size, long long minv, long long maxv, const std::string& variablesName, int indexBase) { std::vector<long long> InStream::readLongs(int size, long long minv, long long maxv, const std::string& variablesName, int indexBase) {
__testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true) __testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true)
} std::vector<long long> InStream::readLongs(int size, int indexBase) { }
std::vector<long long> InStream::readLongs(int size, int indexBase) {
__testlib_readMany(readLongs, readLong(), long long, true) __testlib_readMany(readLongs, readLong(), long long, true)
} }
unsigned long long InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string& variableName) { unsigned long long InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, const std::string& variableName) {
@@ -1997,7 +1996,8 @@ unsigned long long InStream::readUnsignedLong(unsigned long long minv, unsigned
} }
std::vector<unsigned long long> InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string& variablesName, int indexBase) { std::vector<unsigned long long> InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv, const std::string& variablesName, int indexBase) {
__testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true) __testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true)
} std::vector<unsigned long long> InStream::readUnsignedLongs(int size, int indexBase) { }
std::vector<unsigned long long> InStream::readUnsignedLongs(int size, int indexBase) {
__testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true) __testlib_readMany(readUnsignedLongs, readUnsignedLong(), unsigned long long, true)
} }
unsigned long long InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string& variableName) { unsigned long long InStream::readLong(unsigned long long minv, unsigned long long maxv, const std::string& variableName) {
@@ -2025,11 +2025,14 @@ int InStream::readInteger(int minv, int maxv, const std::string& variableName) {
} }
std::vector<int> InStream::readInts(int size, int minv, int maxv, const std::string& variablesName, int indexBase) { std::vector<int> InStream::readInts(int size, int minv, int maxv, const std::string& variablesName, int indexBase) {
__testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true) __testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true)
} std::vector<int> InStream::readInts(int size, int indexBase) { }
std::vector<int> InStream::readInts(int size, int indexBase) {
__testlib_readMany(readInts, readInt(), int, true) __testlib_readMany(readInts, readInt(), int, true)
} std::vector<int> InStream::readIntegers(int size, int minv, int maxv, const std::string& variablesName, int indexBase) { }
std::vector<int> InStream::readIntegers(int size, int minv, int maxv, const std::string& variablesName, int indexBase) {
__testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true) __testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true)
} std::vector<int> InStream::readIntegers(int size, int indexBase) { }
std::vector<int> InStream::readIntegers(int size, int indexBase) {
__testlib_readMany(readIntegers, readInt(), int, true) __testlib_readMany(readIntegers, readInt(), int, true)
} }
double InStream::readReal() { double InStream::readReal() {
@@ -2055,7 +2058,8 @@ double InStream::readReal(double minv, double maxv, const std::string& variableN
} }
std::vector<double> InStream::readReals(int size, double minv, double maxv, const std::string& variablesName, int indexBase) { std::vector<double> InStream::readReals(int size, double minv, double maxv, const std::string& variablesName, int indexBase) {
__testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true) __testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true)
} std::vector<double> InStream::readReals(int size, int indexBase) { }
std::vector<double> InStream::readReals(int size, int indexBase) {
__testlib_readMany(readReals, readReal(), double, true) __testlib_readMany(readReals, readReal(), double, true)
} }
double InStream::readDouble(double minv, double maxv, const std::string& variableName) { double InStream::readDouble(double minv, double maxv, const std::string& variableName) {
@@ -2063,7 +2067,8 @@ double InStream::readDouble(double minv, double maxv, const std::string& variabl
} }
std::vector<double> InStream::readDoubles(int size, double minv, double maxv, const std::string& variablesName, int indexBase) { std::vector<double> InStream::readDoubles(int size, double minv, double maxv, const std::string& variablesName, int indexBase) {
__testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true) __testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true)
} std::vector<double> InStream::readDoubles(int size, int indexBase) { }
std::vector<double> InStream::readDoubles(int size, int indexBase) {
__testlib_readMany(readDoubles, readDouble(), double, true) __testlib_readMany(readDoubles, readDouble(), double, true)
} }
double InStream::readStrictReal(double minv, double maxv, double InStream::readStrictReal(double minv, double maxv,
@@ -2128,7 +2133,8 @@ bool InStream::eoln() {
return false; return false;
} else { } else {
bool returnCr = false; bool returnCr = false;
#if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS)if (c != CR) { #if (defined(ON_WINDOWS) && !defined(FOR_LINUX)) || defined(FOR_WINDOWS)
if (c != CR) {
reader->unreadChar(c); reader->unreadChar(c);
return false; return false;
} else { } else {
@@ -2212,7 +2218,8 @@ std::string InStream::readString(const pattern& p, const std::string& variableNa
} }
std::vector<std::string> InStream::readStrings(int size, const pattern& p, const std::string& variablesName, int indexBase) { std::vector<std::string> InStream::readStrings(int size, const pattern& p, const std::string& variablesName, int indexBase) {
__testlib_readMany(readStrings, readString(p, variablesName), std::string, false) __testlib_readMany(readStrings, readString(p, variablesName), std::string, false)
} std::string InStream::readString(const std::string& ptrn, const std::string& variableName) { }
std::string InStream::readString(const std::string& ptrn, const std::string& variableName) {
readStringTo(_tmpReadToken, ptrn, variableName); readStringTo(_tmpReadToken, ptrn, variableName);
return _tmpReadToken; return _tmpReadToken;
} }
@@ -2240,7 +2247,8 @@ std::string InStream::readLine(const pattern& p, const std::string& variableName
} }
std::vector<std::string> InStream::readLines(int size, const pattern& p, const std::string& variablesName, int indexBase) { std::vector<std::string> InStream::readLines(int size, const pattern& p, const std::string& variablesName, int indexBase) {
__testlib_readMany(readLines, readString(p, variablesName), std::string, false) __testlib_readMany(readLines, readString(p, variablesName), std::string, false)
} std::string InStream::readLine(const std::string& ptrn, const std::string& variableName) { }
std::string InStream::readLine(const std::string& ptrn, const std::string& variableName) {
return readString(ptrn, variableName); return readString(ptrn, variableName);
} }
std::vector<std::string> InStream::readLines(int size, const std::string& ptrn, const std::string& variablesName, int indexBase) { std::vector<std::string> InStream::readLines(int size, const std::string& ptrn, const std::string& variablesName, int indexBase) {
@@ -2250,8 +2258,7 @@ std::vector<std::string> InStream::readLines(int size, const std::string& ptrn,
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 3, 4))) __attribute__((format(printf, 3, 4)))
#endif #endif
void void InStream::ensuref(bool cond, const char* format, ...) {
InStream::ensuref(bool cond, const char* format, ...) {
if (!cond) { if (!cond) {
FMT_TO_RESULT(format, format, message); FMT_TO_RESULT(format, format, message);
this->__testlib_ensure(cond, message); this->__testlib_ensure(cond, message);
@@ -2306,24 +2313,21 @@ template <typename F>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 2, 3))) __attribute__((format(printf, 2, 3)))
#endif #endif
NORETURN void NORETURN void quitp(F points, const char* format, ...) {
quitp(F points, const char* format, ...) {
FMT_TO_RESULT(format, format, message); FMT_TO_RESULT(format, format, message);
quitp(points, message); quitp(points, message);
} }
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 2, 3))) __attribute__((format(printf, 2, 3)))
#endif #endif
NORETURN void NORETURN void quitf(TResult result, const char* format, ...) {
quitf(TResult result, const char* format, ...) {
FMT_TO_RESULT(format, format, message); FMT_TO_RESULT(format, format, message);
quit(result, message); quit(result, message);
} }
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 3, 4))) __attribute__((format(printf, 3, 4)))
#endif #endif
void void quitif(bool condition, TResult result, const char* format, ...) {
quitif(bool condition, TResult result, const char* format, ...) {
if (condition) { if (condition) {
FMT_TO_RESULT(format, format, message); FMT_TO_RESULT(format, format, message);
quit(result, message); quit(result, message);
@@ -2438,7 +2442,6 @@ void registerTestlibCmd(int argc, char* argv[]) {
__testlib_ensuresPreconditions(); __testlib_ensuresPreconditions();
testlibMode = _checker; testlibMode = _checker;
__testlib_set_binary(stdin); __testlib_set_binary(stdin);
if (argc > 1 && !strcmp("--help", argv[1]))__testlib_help();
if (argc < 4 || argc > 6) { if (argc < 4 || argc > 6) {
quit(_fail, std::string("Program must be run with the following arguments: ") + std::string("<input-file> <output-file> <answer-file> [<report-file> [<-appes>]]") + "\nUse \"--help\" to get help information"); quit(_fail, std::string("Program must be run with the following arguments: ") + std::string("<input-file> <output-file> <answer-file> [<report-file> [<-appes>]]") + "\nUse \"--help\" to get help information");
} }
@@ -2481,16 +2484,14 @@ static inline void __testlib_ensure(bool cond, const std::string& msg) {
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((unused)) __attribute__((unused))
#endif #endif
static inline void static inline void __testlib_ensure(bool cond, const char* msg) {
__testlib_ensure(bool cond, const char* msg) {
if (!cond)quit(_fail, msg); if (!cond)quit(_fail, msg);
} }
#define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"") #define ensure(cond) __testlib_ensure(cond, "Condition failed: \"" #cond "\"")
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 2, 3))) __attribute__((format(printf, 2, 3)))
#endif #endif
inline void inline void ensuref(bool cond, const char* format, ...) {
ensuref(bool cond, const char* format, ...) {
if (!cond) { if (!cond) {
FMT_TO_RESULT(format, format, message); FMT_TO_RESULT(format, format, message);
__testlib_ensure(cond, message); __testlib_ensure(cond, message);
@@ -2502,8 +2503,7 @@ NORETURN static void __testlib_fail(const std::string& message) {
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 1, 2))) __attribute__((format(printf, 1, 2)))
#endif #endif
void void setName(const char* format, ...) {
setName(const char* format, ...) {
FMT_TO_RESULT(format, format, name); FMT_TO_RESULT(format, format, name);
checkerName = name; checkerName = name;
} }
@@ -2516,8 +2516,7 @@ template <typename _RandomAccessIter>
#if defined(__GNUC__) && !defined(__clang__) #if defined(__GNUC__) && !defined(__clang__)
__attribute__((error("Don't use random_shuffle(), use shuffle() instead"))) __attribute__((error("Don't use random_shuffle(), use shuffle() instead")))
#endif #endif
void void random_shuffle(_RandomAccessIter, _RandomAccessIter) {
random_shuffle(_RandomAccessIter, _RandomAccessIter) {
quitf(_fail, "Don't use random_shuffle(), use shuffle() instead"); quitf(_fail, "Don't use random_shuffle(), use shuffle() instead");
} }
#ifdef __GLIBC__ #ifdef __GLIBC__
@@ -2531,8 +2530,7 @@ __attribute__((error("Don't use rand(), use rnd.next() instead")))
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable : 4273) #pragma warning(disable : 4273)
#endif #endif
int int rand() RAND_THROW_STATEMENT {
rand() RAND_THROW_STATEMENT {
quitf(_fail, "Don't use rand(), use rnd.next() instead"); quitf(_fail, "Don't use rand(), use rnd.next() instead");
} }
#if defined(__GNUC__) && !defined(__clang__) #if defined(__GNUC__) && !defined(__clang__)
@@ -2544,8 +2542,7 @@ __attribute__((error("Don't use srand(), you should use "
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable : 4273) #pragma warning(disable : 4273)
#endif #endif
void void srand(unsigned int seed) RAND_THROW_STATEMENT {
srand(unsigned int seed) RAND_THROW_STATEMENT {
quitf(_fail, "Don't use srand(), you should use " quitf(_fail, "Don't use srand(), you should use "
"'registerGen(argc, argv, 1);' to initialize generator seed " "'registerGen(argc, argv, 1);' to initialize generator seed "
"by hash code of the command line params. The third parameter " "by hash code of the command line params. The third parameter "
@@ -2601,10 +2598,12 @@ std::string join(const _Collection& collection) {
std::vector<std::string> split(const std::string& s, char separator) { std::vector<std::string> split(const std::string& s, char separator) {
std::vector<std::string> result; std::vector<std::string> result;
std::string item; std::string item;
for (size_t i = 0; i < s.length(); i++)if (s[i] == separator) { for (size_t i = 0; i < s.length(); i++) {
if (s[i] == separator) {
result.push_back(item); result.push_back(item);
item = ""; item = "";
} else item += s[i]; } else item += s[i];
}
result.push_back(item); result.push_back(item);
return result; return result;
} }
@@ -2614,10 +2613,12 @@ std::vector<std::string> split(const std::string& s, const std::string& separato
for (size_t i = 0; i < separators.size(); i++)isSeparator[(unsigned char)(separators[i])] = true; for (size_t i = 0; i < separators.size(); i++)isSeparator[(unsigned char)(separators[i])] = true;
std::vector<std::string> result; std::vector<std::string> result;
std::string item; std::string item;
for (size_t i = 0; i < s.length(); i++)if (isSeparator[(unsigned char)(s[i])]) { for (size_t i = 0; i < s.length(); i++) {
if (isSeparator[(unsigned char)(s[i])]) {
result.push_back(item); result.push_back(item);
item = ""; item = "";
} else item += s[i]; } else item += s[i];
}
result.push_back(item); result.push_back(item);
return result; return result;
} }
@@ -2637,10 +2638,12 @@ std::vector<std::string> tokenize(const std::string& s, const std::string& separ
for (size_t i = 0; i < separators.size(); i++) isSeparator[(unsigned char)(separators[i])] = true; for (size_t i = 0; i < separators.size(); i++) isSeparator[(unsigned char)(separators[i])] = true;
std::vector<std::string> result; std::vector<std::string> result;
std::string item; std::string item;
for (size_t i = 0; i < s.length(); i++)if (isSeparator[(unsigned char)(s[i])]) { for (size_t i = 0; i < s.length(); i++) {
if (isSeparator[(unsigned char)(s[i])]) {
if (!item.empty())result.push_back(item); if (!item.empty())result.push_back(item);
item = ""; item = "";
} else item += s[i]; } else item += s[i];
}
if (!item.empty())result.push_back(item); if (!item.empty())result.push_back(item);
return result; return result;
} }
@@ -2661,8 +2664,7 @@ template <typename T>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 4, 5))) __attribute__((format(printf, 4, 5)))
#endif #endif
NORETURN void NORETURN void expectedButFound(TResult result, T expected, T found, const char* prependFormat = "", ...) {
expectedButFound(TResult result, T expected, T found, const char* prependFormat = "", ...) {
FMT_TO_RESULT(prependFormat, prependFormat, prepend); FMT_TO_RESULT(prependFormat, prependFormat, prepend);
std::string expectedString = vtos(expected); std::string expectedString = vtos(expected);
std::string foundString = vtos(found); std::string foundString = vtos(found);
@@ -2672,8 +2674,7 @@ template <>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 4, 5))) __attribute__((format(printf, 4, 5)))
#endif #endif
NORETURN void NORETURN void expectedButFound<std::string>(TResult result, std::string expected, std::string found, const char* prependFormat, ...) {
expectedButFound<std::string>(TResult result, std::string expected, std::string found, const char* prependFormat, ...) {
FMT_TO_RESULT(prependFormat, prependFormat, prepend); FMT_TO_RESULT(prependFormat, prependFormat, prepend);
__testlib_expectedButFound(result, expected, found, prepend.c_str()); __testlib_expectedButFound(result, expected, found, prepend.c_str());
} }
@@ -2681,8 +2682,7 @@ template <>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 4, 5))) __attribute__((format(printf, 4, 5)))
#endif #endif
NORETURN void NORETURN void expectedButFound<double>(TResult result, double expected, double found, const char* prependFormat, ...) {
expectedButFound<double>(TResult result, double expected, double found, const char* prependFormat, ...) {
FMT_TO_RESULT(prependFormat, prependFormat, prepend); FMT_TO_RESULT(prependFormat, prependFormat, prepend);
std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected)); std::string expectedString = removeDoubleTrailingZeroes(format("%.12f", expected));
std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found)); std::string foundString = removeDoubleTrailingZeroes(format("%.12f", found));
@@ -2692,8 +2692,7 @@ template <>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 4, 5))) __attribute__((format(printf, 4, 5)))
#endif #endif
NORETURN void NORETURN void expectedButFound<const char*>(TResult result, const char* expected, const char* found, const char* prependFormat, ...) {
expectedButFound<const char*>(TResult result, const char* expected, const char* found, const char* prependFormat, ...) {
FMT_TO_RESULT(prependFormat, prependFormat, prepend); FMT_TO_RESULT(prependFormat, prependFormat, prepend);
__testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str()); __testlib_expectedButFound(result, std::string(expected), std::string(found), prepend.c_str());
} }
@@ -2701,8 +2700,7 @@ template <>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 4, 5))) __attribute__((format(printf, 4, 5)))
#endif #endif
NORETURN void NORETURN void expectedButFound<float>(TResult result, float expected, float found, const char* prependFormat, ...) {
expectedButFound<float>(TResult result, float expected, float found, const char* prependFormat, ...) {
FMT_TO_RESULT(prependFormat, prependFormat, prepend); FMT_TO_RESULT(prependFormat, prependFormat, prepend);
__testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str());
} }
@@ -2710,8 +2708,7 @@ template <>
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 4, 5))) __attribute__((format(printf, 4, 5)))
#endif #endif
NORETURN void NORETURN void expectedButFound<long double>(TResult result, long double expected, long double found, const char* prependFormat, ...) {
expectedButFound<long double>(TResult result, long double expected, long double found, const char* prependFormat, ...) {
FMT_TO_RESULT(prependFormat, prependFormat, prepend); FMT_TO_RESULT(prependFormat, prependFormat, prepend);
__testlib_expectedButFound(result, double(expected), double(found), prepend.c_str()); __testlib_expectedButFound(result, double(expected), double(found), prepend.c_str());
} }
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.4.4", "version": "2.4.5",
"os": [ "os": [
"linux" "linux"
], ],