凯斯特CS453 2019春季7队项目
cotegen的Python项目详细描述
编码测试输入生成器
cotegen从底层自动生成典型编码测试问题的测试套件。首先,可以以最小的成本构建初始测试套件。其次,基于搜索的变异适应度输入生成补充了初始测试集。使用变异参考解作为错误答案的简化形式,我们的目标是杀死尽可能多的变异。因此,作为互补结果提供突变覆盖。
学术报告:Dropbox
添加新的对照溶液
在安装了我们的cotegen
包之后,您可以编写一个新的引用解决方案作为一个简单的python文件来生成相应的测试用例。
请在examples/tasks
目录中找到引用解决方案文件,以利用命令行执行。
您应该定义一个新的类继承cotegen.Task
,并使用与filename相同的方法。
input_parameters
、solve
(参比溶液)、compare
和convert_input_to_string
是必须重写的方法。
请参考示例:
importcotegen# http://codeforces.com/problemset/problem/1/AclassCF1A(cotegen.Task):input_parameters= \ {'n':cotegen.types.Integer(1,10**9),'m':cotegen.types.Integer(1,10**9),'a':cotegen.types.Integer(1,10**9),}defsolve(n:int,m:int,a:int)->int:# 1 <= n, m, a <= 10**9return((n+(a-1))//a)*((m+(a-1))//a)@staticmethoddefcompare(user_answer:int,jury_answer:int)->bool:returnuser_answer==jury_answer@staticmethoddefconvert_input_to_string(n:int,m:int,a:int):return"%d%d%d\n"%(n,m,a)if__name__=='__main__':importosCF1A.generate_test_files(os.path.expanduser("~/Downloads/CS453/CF1A"))
定义输入参数
将输入参数的类型和每个参数的范围预定义为字典格式。
目前,CoTeGen
支持以下类型:
cotegen.types.Integercotegen.types.IntegerSequencecotegen.types.NonIncreasingIntegerSequencecotegen.types.FixedVariableLengthIntegerSequencecotegen.types.IntegerPermutation
定义约束
如果需要,将输入参数之间的约束定义为列表。
constraints=[cotegen.constraints.Leq('M','N')]
您可以利用这些预定义的约束:
cotegen.constraints.Leq(Lessthanorequal)cotegen.constraints.ListLengthLeqIntegercotegen.constraints.ListLengthReqInteger
或者,使用自定义约束提供自定义函数(它接收参数字典并返回true/false)作为参数
cotegen.constraints.CustomConstraint(lambdatest:'d1'notintestor'd2'notintestortest['d1']!=test['d2'])
命令行用法
python -m cotegen run random --filename <filename>
python -m cotegen run mutation --filename <filename> --show-survived <true or false>
python -m cotegen run kill --filename <filename> --save <directory path> --mutation-fitness <true or false>
例如:
python -m cotegen run random --filename CF158A
python -m cotegen run mutation --filename CF158A
python -m cotegen run kill --filename CF158A --save ~/Downloads --mutation-fitness true