競技プログラミングのテストケース実行環境を用意しようとしてハマった
これを用意しようと思った。
pip3 install oneline-judge-tools
pip3 install online-judge-tools Collecting online-judge-tools Using cached https://files.pythonhosted.org/packages/61/35/e04d089b6eaf045b0b20b6105e53f86e65d393d64430185fc43672e8f922/online-judge-tools-6.2.1.tar.gz ERROR: Complete output from command python setup.py egg_info: ERROR: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/m8/y33xsjwj1ms48m5mpbsm9n400000gn/T/pip-install-ng_ziqtr/online-judge-tools/setup.py", line 10, in <module> raise RuntimeError('setuptools>=30.3.0 is required for "setup.cfg"') RuntimeError: setuptools>=30.3.0 is required for "setup.cfg" ---------------------------------------- ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/m8/y33xsjwj1ms48m5mpbsm9n400000gn/T/pip-install-ng_ziqtr/online-judge-tools/
「Command "python setup.py egg_info" failed」
で検索したところ、日本語で一番上に出てきたものを見てみる。
なるほど。
$ pip install --upgrade pip setuptools ✘ 1 master ◼ Requirement already up-to-date: pip in /Users/yoshii/.anyenv/envs/pyenv/versions/3.6.0/lib/python3.6/site-packages (19.1.1) Collecting setuptools Downloading https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl (575kB) |████████████████████████████████| 583kB 3.9MB/s Installing collected packages: setuptools Found existing installation: setuptools 28.8.0 Uninstalling setuptools-28.8.0: Successfully uninstalled setuptools-28.8.0 Successfully installed setuptools-41.0.1
おお。
pip install online-judge-tools
→行けました!
oj download https://atcoder.jp/contests/abc128/tasks/abc128_a
一番最近のコードを持ってくる。
実行ディレクトリと同じディレクトリにtest
ディレクトリができていた。
├── a.rb └── test ├── sample-1.in ├── sample-1.out ├── sample-2.in ├── sample-2.out ├── sample-3.in └── sample-3.out
こんな感じだ。
これからどうすればいいのか。
ojのヘルプコマンドだけ見て雰囲気でやってたけどだめだったので、ここをちゃんと見たら書いてくれてた。
$ oj test -c ./a.rb [*] 3 cases found [*] sample-1 /bin/sh: ./a.rb: Permission denied [x] time: 0.005608 sec [-] RE: return code 126 [-] WA output: expected: 3 [*] sample-2 /bin/sh: ./a.rb: Permission denied [x] time: 0.005723 sec [-] RE: return code 126 [-] WA output: expected: 0 [*] sample-3 /bin/sh: ./a.rb: Permission denied [x] time: 0.006032 sec [-] RE: return code 126 [-] WA output: expected: 58 [x] slowest: 0.006032 sec (for sample-3) [-] test failed: 0 AC / 3 cases
パーミッション問題。。。
実行ファイルに実行の権限をつければいいだけだった。
chmod 755 ./*
これで実行できましたー
念のため一応補足をすると、rubyのコードで書いたので、コードの先頭に
#!/usr/bin/ruby
を書き足しました。(これは各人の実行環境に合わせて臨機応変に)
ちなみに自分が普段使っているrubyは
which ruby /Users/yoshii/.rbenv/shims/ruby
で、もはやどうやってrubyの環境構築をしたかは覚えていないのですが、たしか普通にrbenvかanyenvとかを使っていた気がする。
で、こういうパッケージ管理システムを使っているときのシバンの書き方についての正しい書き方は、
によると、
#!/usr/bin/env ruby
みたいな感じらしいので、それにならってやってみたが、うまくかけました!!
これにてテスト環境構築完了!!!