feature(core): Judge 部分设计思路
himself65 opened this issue · comments
Alex Yang commented
judge
程序检查部分,可以通过读取.out
类型文件直接进行比较,或者直接通过手动写判断来进行结果比对
// foo.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Yes" << endl;
cout << "No" << endl;
return 0;
}
Judge('./foo.cpp')
.line(1).toBe('Yes')
.line(2).toBe('False')
.maxline().toBe(2)
.exec() // 开始运行
.line(2).toBe("False")
^^^^^^
error on "line 2", expect "False" but got "No"
Alex Yang commented
部分接口大致思路
// 非标准typescript代码,保证语法不正确
interface IDataable: string | number | string[] | number[];
interface IJudgeWrapper{
constructor(val: IJudgeWrapper | IJudge)
toBe(val: IDataable) => this
line: (val: string, number, (number, string)[]) => IJudgeWrapper(this)
maxline: (val: IDataable) => IJudgeWrapper(this)
}
interface IJudge {
line: (val: IDataable) => IJudgeWrapper(this)
maxline: (val: Number) => IJudgeWrapper(this)
exec: () => this
}
Alex Yang commented
JudgeWrapper
包装Judge类,使其可以有toBe()
、notToBe()
等判断函数来测试程序输出文件
返回 Judge
Alex Yang commented
Judge.prototype
Of(val)
返回一个新的Judge
file(val: file | file[] | string | string[] | null)
输入参数则直接进行测评
如果没有任何参数,则可以根据返回的fileManagerWrapper
来针对每个文件的输出进行判断
exec()
运行代码
Judge Function 测评函数
以下函数都返回Judge.Of(this)
line()
针对某行进行判断
maxline()
最大行数
minline()
最小行数
Wenzhuo Liu commented
实际上可以直接用coreutils里的diff来比对输出
(我也不太清楚我有没有理解到您的意思qwq)
Alex Yang commented
实际上可以直接用coreutils里的diff来比对输出
(我也不太清楚我有没有理解到您的意思qwq)
util里的只有strictEqual
而我要实现的是竞赛上的一种自定义相等
比如
equal([1, 2, 3], "1 2 3") === true
equal(1, "1") === true
Wenzhuo Liu commented
Alex Yang commented
Alex Yang commented
暂时发现这些是错误的实现,之后重新设计