online-judge-tools / verification-helper

a testing framework for snippet libraries used in competitive programming
MIT License
207 stars 53 forks source link

ストレステストに対応して欲しい #435

Open tatyam-prime opened 4 months ago

tatyam-prime commented 4 months ago

Description / 説明

現在の verify には特定のサイト上の問題が必要だと思うのですが、手元でランダムケースを生成してテストしたいです。

入出力が 1 個だけのダミーの問題があればいいんですが…

Other notes / その他

kzrnm commented 4 months ago

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A は1ケースしかないのでこれを使う想定らしいです。

https://github.com/online-judge-tools/verification-helper/issues/74#issuecomment-622962608

現状でも http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A を指定して hoge.test.cpp の中でランダムケースを生成することでだいたい同じことができ、こちらの方が圧倒的に楽

tatyam-prime commented 4 months ago

Hello World を書くのは変な感じするし、ストレステストは大量のケースでテストできるというメリットがあるので、ストレステストができる機能はあるべきだと思います。

kzrnm commented 4 months ago

verification-helper を使わない解決策

フォークの competitive-verifier では PROBLEM を使わない実行にも対応したので、移行しても良いなら使ってみてください。

https://competitive-verifier.github.io/competitive-verifier/document.ja.html#%E3%83%A6%E3%83%8B%E3%83%83%E3%83%88%E3%83%86%E3%82%B9%E3%83%88%E3%81%AE%E8%A8%AD%E5%AE%9A

verification-helper での解決策

https://github.com/online-judge-tools/verification-helper/blob/c42032627b21f4b1d45a8f42cb9d00dd0fa70668/onlinejudge_verify/verify.py#L103-L115

oj test コマンドでテストされるのでダミー用の problem を返してあげれば動くはずです。

ダミーURLを決める

たとえば 「 PROBLEM=http://example.com/nothing のときにダミーの問題を使う」と定義する。

ダミーの problem を返す

https://github.com/online-judge-tools/verification-helper/blob/c42032627b21f4b1d45a8f42cb9d00dd0fa70668/onlinejudge_verify/verify.py#L72

onlinejudge.dispatch.problem_from_url を書き換えてダミーを返す。

problem_from_url_orig = onlinejudge.dispatch.problem_from_url

def problem_from_url(url: str) -> Optional[Problem]:
    if url == 'http://example.com/nothing':
        return DummyProblem()
    return problem_from_url_orig(url)

onlinejudge.dispatch.problem_from_url =problem_from_url