@@ -202,6 +202,7 @@ async def execute(
202202 """执行测试数据生成。"""
203203 # 验证 constraints 参数
204204 if constraints :
205+ # 验证 n_max 和 n_min
205206 n_max = constraints .get ("n_max" )
206207 if n_max is not None and n_max <= 0 :
207208 return ToolResult .fail ("n_max must be positive" )
@@ -211,6 +212,45 @@ async def execute(
211212 if n_max is not None and n_min is not None and n_min > n_max :
212213 return ToolResult .fail ("n_min cannot be greater than n_max" )
213214
215+ # 验证 t_max
216+ t_max = constraints .get ("t_max" )
217+ if t_max is not None and t_max <= 0 :
218+ return ToolResult .fail ("t_max must be positive" )
219+
220+ # 验证 sum_n_max
221+ sum_n_max = constraints .get ("sum_n_max" )
222+ if sum_n_max is not None and sum_n_max <= 0 :
223+ return ToolResult .fail ("sum_n_max must be positive" )
224+
225+ # 验证约束之间的关系
226+ if n_max is not None and sum_n_max is not None and n_max > sum_n_max :
227+ return ToolResult .fail ("n_max cannot be greater than sum_n_max" )
228+ if t_max is not None and sum_n_max is not None and t_max > sum_n_max :
229+ return ToolResult .fail ("t_max cannot be greater than sum_n_max" )
230+
231+ # 验证 test_configs 参数
232+ if test_configs :
233+ for i , config in enumerate (test_configs ):
234+ # 验证 type 字段
235+ if "type" not in config :
236+ return ToolResult .fail (f"test_configs[{ i } ]: 'type' is required" )
237+ if config ["type" ] not in ("1" , "2" , "3" , "4" ):
238+ return ToolResult .fail (f"test_configs[{ i } ]: 'type' must be one of '1', '2', '3', '4'" )
239+
240+ # 验证 n_min, n_max, t_min, t_max
241+ for field in ["n_min" , "n_max" , "t_min" , "t_max" ]:
242+ if field not in config :
243+ return ToolResult .fail (f"test_configs[{ i } ]: '{ field } ' is required" )
244+ val = config [field ]
245+ if not isinstance (val , int ) or val < 0 :
246+ return ToolResult .fail (f"test_configs[{ i } ]: '{ field } ' must be a non-negative integer" )
247+
248+ # 验证范围关系
249+ if config ["n_min" ] > config ["n_max" ]:
250+ return ToolResult .fail (f"test_configs[{ i } ]: n_min cannot be greater than n_max" )
251+ if config ["t_min" ] > config ["t_max" ]:
252+ return ToolResult .fail (f"test_configs[{ i } ]: t_min cannot be greater than t_max" )
253+
214254 exe_ext = get_exe_extension ()
215255
216256 # 检查必要文件
@@ -238,6 +278,7 @@ async def execute(
238278 errors = []
239279
240280 # 获取测试配置
281+ test_configs_list : list [tuple [str , str , str , str , str , str ]]
241282 if test_configs :
242283 test_configs_list = [
243284 (
@@ -253,11 +294,11 @@ async def execute(
253294 else :
254295 test_configs_list = self ._get_default_configs (constraints )
255296
256- for i , config in enumerate (test_configs_list [:test_count ], 1 ):
297+ for i , test_cfg in enumerate (test_configs_list [:test_count ], 1 ):
257298 test_file = os .path .join (tests_dir , f"{ i :02d} .in" )
258299 ans_file = os .path .join (tests_dir , f"{ i :02d} .ans" )
259300
260- seed_offset , type_param , n_min , n_max , t_min , t_max = config
301+ seed_offset , type_param , n_min , n_max , t_min , t_max = test_cfg
261302 cmd_args = [
262303 str (i + int (seed_offset )),
263304 type_param ,
0 commit comments