Skip to content

Commit

Permalink
fix(ccf_parser): 错误的CKPT参数将会被自动修正
Browse files Browse the repository at this point in the history
即input_type为STDIN时,input_file自动修正为None
output同理
  • Loading branch information
XYCode-Kerman committed Apr 12, 2024
1 parent f8312bf commit e6979a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ccf_parser/problems.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pathlib
from typing import List, Literal, Optional
from typing import Any, List, Literal, Optional

from pydantic import BaseModel
from pydantic import BaseModel, model_validator


class CheckPoint(BaseModel):
Expand All @@ -17,6 +17,16 @@ class CheckPoint(BaseModel):
# 仅 output_type == FILE 时设置
output_file: Optional[pathlib.Path] = None

@model_validator(mode='after')
def check_if_of(self):
if self.input_type == 'STDIN':
self.input_file = None

if self.output_type == 'STDOUT':
self.output_file = None

return self

def compare(self, output: str) -> bool:
# CRLF转换到LF
self.answer = self.answer.replace('\r\n', '\n')
Expand Down
29 changes: 29 additions & 0 deletions tests/test_ccf_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import pathlib

import pydantic
import pytest

from ccf_parser import *

data = json.load(pathlib.Path('./tests/environment/ccf.json').open())
Expand All @@ -12,3 +15,29 @@ def test_ccf():
'114514') == False
assert ccf.contest.problems[0].judge_config.checkpoints[0].compare(
'114514 114514') == True


def test_checkpoint():
ckpt = CheckPoint(
input='good',
answer='good good',
input_type='STDIN',
output_type='STDOUT'
)

assert ckpt.compare(' good good ') == True
assert ckpt.compare('good good\n') == True
assert ckpt.compare('good good') == True
assert ckpt.compare('good') == False

ckpt = CheckPoint(
input='good',
answer='good good',
input_type='STDIN',
output_type='STDOUT',
input_file=pathlib.Path('hello'),
output_file=pathlib.Path('hello')
)

assert ckpt.input_file is None
assert ckpt.output_file is None

0 comments on commit e6979a7

Please sign in to comment.