atcoder_greedy 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -10
- data/lib/atcoder_greedy/command/config.rb +34 -0
- data/lib/atcoder_greedy/command/create.rb +2 -80
- data/lib/atcoder_greedy/command/destroy.rb +20 -0
- data/lib/atcoder_greedy/command/test.rb +4 -74
- data/lib/atcoder_greedy/command.rb +2 -0
- data/lib/atcoder_greedy/lib/contest.rb +79 -0
- data/lib/atcoder_greedy/lib/languages.rb +35 -0
- data/lib/atcoder_greedy/lib/test_case.rb +99 -0
- data/lib/atcoder_greedy/settings.yml +3 -0
- data/lib/atcoder_greedy/templates/cpp/solve.cpp +17 -0
- data/lib/atcoder_greedy/templates/rb/solve.rb +3 -0
- data/lib/atcoder_greedy/version.rb +1 -1
- data/lib/atcoder_greedy.rb +52 -0
- metadata +9 -2
- data/lib/atcoder_greedy/templates/ruby/solve.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d42b0f9fe076b3670cff6cdfad10dfba4616024d
|
4
|
+
data.tar.gz: ed0416f152662e1090ffb8afebe4e9132c9b6fa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d94fb94d0aa72a7a62df97872b83ebebc080984b2876a1e5356d5a3940f4360e5b1d5ad6d21325dcc0c84e47cc13ea5d65f8828b3226f581e9b8ceaef037028
|
7
|
+
data.tar.gz: 78f2729640bcbd2ba18e9abbc9d5e006a68b81d7a0e87a2b4e9b12692cd2ca0b3e71bebf780f6da8aad4cc372b93ace0765de88c2e9b527002b81f9045c6e5fe
|
data/README.md
CHANGED
@@ -1,22 +1,33 @@
|
|
1
1
|
# AtcoderGreedy
|
2
|
-
楽にatcoder
|
2
|
+
楽にatcoderを使いたい.
|
3
|
+
毎回サンプルインプットをコピペするのめんどくさくないですか?
|
3
4
|
|
4
5
|
## Installation
|
5
6
|
|
6
7
|
$ gem install atcoder_greedy
|
7
8
|
|
9
|
+
## 初期設定
|
10
|
+
|
11
|
+
configコマンドを使用してデフォルト言語の設定をしてください。
|
12
|
+
```
|
13
|
+
$ atcoder_greedy config
|
14
|
+
Choose default language from: ["rb", "cpp"]
|
15
|
+
Input languages: cpp
|
16
|
+
Update Your default language to [cpp].
|
17
|
+
$
|
18
|
+
```
|
19
|
+
|
8
20
|
## Usage
|
9
21
|
|
10
22
|
### テンプレートファイルの作成
|
11
23
|
```
|
12
|
-
# create contest templates
|
13
24
|
$ atcoder_greedy create CONTESTNAME
|
14
25
|
```
|
15
26
|
|
16
27
|
### テストの実行
|
17
28
|
```
|
18
29
|
$ cd CONTESTNAME
|
19
|
-
$ atcoder_greedy test
|
30
|
+
$ atcoder_greedy test PROBLEM_FILE_NAME
|
20
31
|
```
|
21
32
|
|
22
33
|
## 使用例
|
@@ -52,16 +63,22 @@ $ atcoder_greedy test A.rb
|
|
52
63
|
とすると、以下のようにテスト結果が表示される。
|
53
64
|
|
54
65
|
```
|
55
|
-
Running a test for problem A...
|
56
|
-
|
57
|
-
Testcase #
|
66
|
+
Running a test for problem A.rb...
|
67
|
+
-------------------- Compile Done --------------------
|
68
|
+
-------------------- Testcase #0 -------------------- FAILED! Time: 0.00727s
|
58
69
|
Your Output:
|
59
|
-
|
70
|
+
5
|
71
|
+
Correct Answer:
|
72
|
+
1
|
73
|
+
|
74
|
+
-------------------- Testcase #1 -------------------- PASSED! Time: 0.04882s
|
60
75
|
|
76
|
+
-------------------- Testcase #2 -------------------- FAILED! Time: 0.00614s
|
77
|
+
Your Output:
|
78
|
+
3
|
61
79
|
Correct Answer:
|
62
|
-
|
80
|
+
1
|
63
81
|
|
64
|
-
Testcase #2 ... PASSED! Time: 0.05054747499525547s
|
65
82
|
Test done.
|
66
83
|
```
|
67
84
|
|
@@ -69,12 +86,13 @@ Test done.
|
|
69
86
|
- 解答ファイルのテンプレート生成
|
70
87
|
- サンプルインプット、アウトプットを用いたテストファイルの生成
|
71
88
|
- テスト実行コマンド
|
89
|
+
- ruby, c++ に対応
|
72
90
|
|
73
91
|
|
74
92
|
## TODO,実装したい機能
|
75
93
|
- 問題を指定してその問題のみ生成
|
76
94
|
- 提出機能
|
77
|
-
-
|
95
|
+
- 言語対応の拡大
|
78
96
|
|
79
97
|
## Development
|
80
98
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'atcoder_greedy'
|
2
|
+
require 'atcoder_greedy/command'
|
3
|
+
require 'atcoder_greedy/lib/languages'
|
4
|
+
module AtcoderGreedy
|
5
|
+
class Command < Thor
|
6
|
+
desc 'config', 'change settings'
|
7
|
+
|
8
|
+
def config
|
9
|
+
languages = Languages::ALL_LANGUAGES
|
10
|
+
config_path = Dir.home + '/.atcoder_greedy'
|
11
|
+
if Dir.exists?(config_path)
|
12
|
+
puts "Your current language is [#{AtcoderGreedy.config[:language]}]."
|
13
|
+
else
|
14
|
+
Dir.mkdir(config_path)
|
15
|
+
File.new(config_path + '/settings.yml', 'w')
|
16
|
+
end
|
17
|
+
puts "Choose default language from: #{languages}"
|
18
|
+
print "Input languages: "
|
19
|
+
loop do
|
20
|
+
s = $stdin.gets.chomp!
|
21
|
+
if languages.include?(s)
|
22
|
+
AtcoderGreedy.configure(language: s)
|
23
|
+
break
|
24
|
+
elsif s.size == 0
|
25
|
+
break
|
26
|
+
elsif puts "Invalid language. please try again:"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
AtcoderGreedy.save_config
|
31
|
+
puts "Update Your default language to [#{AtcoderGreedy.config[:language]}]."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,91 +1,13 @@
|
|
1
1
|
require 'atcoder_greedy'
|
2
2
|
require 'atcoder_greedy/command'
|
3
|
+
require 'atcoder_greedy/lib/contest'
|
3
4
|
|
4
5
|
module AtcoderGreedy
|
5
6
|
class Command < Thor
|
6
|
-
desc 'create CONTESTNAME', 'create contest templates for CONTESTNAME'
|
7
|
+
desc 'create [CONTESTNAME]', 'create contest templates for [CONTESTNAME]'
|
7
8
|
|
8
9
|
def create(contest_name)
|
9
10
|
Contest.new(contest_name.downcase)
|
10
11
|
end
|
11
12
|
end
|
12
|
-
|
13
|
-
TEMPLATE_PATH = File.join(File.dirname(__dir__), '/templates')
|
14
|
-
SOLVE_TEMPLATE = open(TEMPLATE_PATH + '/ruby/solve.rb', &:read)
|
15
|
-
PROBLEM_NAMES = %w(A B C D)
|
16
|
-
|
17
|
-
class Contest
|
18
|
-
attr_accessor :name, :url
|
19
|
-
|
20
|
-
def initialize(name)
|
21
|
-
@name = name
|
22
|
-
puts "Create #{name} contest files"
|
23
|
-
@base_url = create_contest_url(name)
|
24
|
-
puts "Contest url is #{@base_url}"
|
25
|
-
@problem_urls = create_contest_problem_urls(name)
|
26
|
-
puts 'Create directories'
|
27
|
-
create_directories
|
28
|
-
create_templates
|
29
|
-
puts 'Set up done.'
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_contest_url(contest_name)
|
33
|
-
'http://' + contest_name + '.contest.atcoder.jp'
|
34
|
-
end
|
35
|
-
|
36
|
-
def create_contest_problem_urls(contest_name)
|
37
|
-
urls = []
|
38
|
-
if (contest_name.include?('abc') && contest_name[3..5].to_i > 19) ||
|
39
|
-
(contest_name.include?('arc') && contest_name[3..5].to_i > 34)
|
40
|
-
task_num = %w(a b c d)
|
41
|
-
else
|
42
|
-
task_num = %w(1 2 3 4)
|
43
|
-
end
|
44
|
-
|
45
|
-
4.times do |i|
|
46
|
-
urls.push(name: "#{PROBLEM_NAMES[i]}", path: @base_url + "/tasks/#{contest_name}_#{task_num[i]}")
|
47
|
-
end
|
48
|
-
urls
|
49
|
-
end
|
50
|
-
|
51
|
-
def create_templates
|
52
|
-
@problem_urls.each_with_index do |url, pro_i|
|
53
|
-
problem_dir = "./#{@name}"
|
54
|
-
# urlからインプット、アウトプットパラメータをとってきてファイルにしまう
|
55
|
-
charset = nil
|
56
|
-
html = open(url[:path]) do |f|
|
57
|
-
charset = f.charset
|
58
|
-
f.read
|
59
|
-
end
|
60
|
-
doc = Nokogiri::HTML.parse(html, nil, charset)
|
61
|
-
in_file = File.new(problem_dir + "/input_#{PROBLEM_NAMES[pro_i]}.txt", 'w')
|
62
|
-
|
63
|
-
params = doc.xpath('//pre')
|
64
|
-
params.shift
|
65
|
-
params.each_with_index do |p, i|
|
66
|
-
if i % 2 == 0
|
67
|
-
in_file.puts "-- Example #{i/2}"
|
68
|
-
in_file.puts "#{p.text.gsub(/\r\n?/, "\n").strip}"
|
69
|
-
else
|
70
|
-
in_file.puts "-- Answer #{(i-1)/2}"
|
71
|
-
in_file.puts "#{p.text.gsub(/\r\n?/, "\n").strip}"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
in_file.close
|
76
|
-
|
77
|
-
solve_file_content = SOLVE_TEMPLATE.clone
|
78
|
-
solve_file_content.gsub!(/CONTEST/, @name.upcase)
|
79
|
-
solve_file_content.gsub!(/PROBLEM/, url[:name].upcase)
|
80
|
-
solve_file = File.new(problem_dir + "/#{url[:name]}.rb", 'w')
|
81
|
-
solve_file.print solve_file_content
|
82
|
-
solve_file.close
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def create_directories
|
87
|
-
# コンテストディレクトリ作成
|
88
|
-
FileUtils.mkdir(@name)
|
89
|
-
end
|
90
|
-
end
|
91
13
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'atcoder_greedy'
|
2
|
+
require 'atcoder_greedy/command'
|
3
|
+
|
4
|
+
module AtcoderGreedy
|
5
|
+
class Command < Thor
|
6
|
+
desc 'destroy [CONTESTNAME]', 'destroy contest templates for [CONTESTNAME]'
|
7
|
+
|
8
|
+
def destroy(contest_name)
|
9
|
+
puts "Destroy ./#{contest_name} [y/n]?"
|
10
|
+
s = $stdin.gets
|
11
|
+
if s == 'y' || s == 'yes'
|
12
|
+
if system("rm -r ./#{contest_name}")
|
13
|
+
puts 'deleted.'
|
14
|
+
else
|
15
|
+
raise 'Runtime Error'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,84 +1,14 @@
|
|
1
1
|
require 'atcoder_greedy'
|
2
2
|
require 'atcoder_greedy/command'
|
3
|
-
require '
|
4
|
-
require 'tempfile'
|
5
|
-
require 'benchmark'
|
6
|
-
|
3
|
+
require 'atcoder_greedy/lib/test_case'
|
7
4
|
|
8
5
|
module AtcoderGreedy
|
9
6
|
class Command < Thor
|
10
|
-
desc 'test
|
7
|
+
desc 'test [PROBLEM_FILE_NAME]', 'test your solution'
|
11
8
|
|
12
9
|
def test(problem_name)
|
13
|
-
|
14
|
-
puts "Running a test for problem #{name}..."
|
15
|
-
TestCase.new(name).validate
|
16
|
-
puts "Test done."
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class TestCase
|
21
|
-
def initialize(problem_name)
|
22
|
-
@input_file = File.open("./input_#{problem_name}.txt", 'r')
|
23
|
-
@exec_file = "./#{problem_name}.rb"
|
24
|
-
get_in_out
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_in_out
|
28
|
-
i = 0
|
29
|
-
@input = []
|
30
|
-
@output = []
|
31
|
-
now = nil
|
32
|
-
while (t = @input_file.gets) != nil
|
33
|
-
example_string = "-- Example #{i}"
|
34
|
-
answer_string = "-- Answer #{i}"
|
35
|
-
|
36
|
-
if t.chomp == example_string
|
37
|
-
now.close(false) unless now.nil?
|
38
|
-
now = Tempfile.new(['in', '.txt'], './')
|
39
|
-
@input.push(now)
|
40
|
-
now.open
|
41
|
-
elsif t.chomp == answer_string
|
42
|
-
now.close(false) unless now.nil?
|
43
|
-
now = Tempfile.new(['out', '.txt'], './')
|
44
|
-
@output.push(now)
|
45
|
-
now.open
|
46
|
-
i += 1
|
47
|
-
else
|
48
|
-
now.puts t
|
49
|
-
end
|
50
|
-
end
|
51
|
-
@input[-1].close(false)
|
52
|
-
@output[-1].close(false)
|
53
|
-
end
|
54
|
-
|
55
|
-
def validate
|
56
|
-
@input.size.times do |j|
|
57
|
-
myout_file = Tempfile.new(['myout', '.txt'], './')
|
58
|
-
myout_file.open
|
59
|
-
result = Benchmark.realtime do
|
60
|
-
pid = Process.fork do
|
61
|
-
exec "ruby #{@exec_file} < #{@input[j].path} > #{myout_file.path}"
|
62
|
-
@input[j].close
|
63
|
-
myout_file.close(false)
|
64
|
-
end
|
65
|
-
Process.waitpid pid
|
66
|
-
end
|
67
|
-
|
68
|
-
myout = myout_file.open.read
|
69
|
-
myout_file.close
|
70
|
-
correct = File.open("#{@output[j].path}").read
|
71
|
-
diffs = Diff::LCS.diff(myout, correct)
|
72
|
-
if diffs.size == 0
|
73
|
-
puts "Testcase ##{j} ... PASSED! Time: #{result}s"
|
74
|
-
else
|
75
|
-
puts "Testcase ##{j} ... FAILED! Time: #{result}s"
|
76
|
-
puts "Your Output:"
|
77
|
-
puts "#{myout}\n"
|
78
|
-
puts "Correct Answer:"
|
79
|
-
puts "#{correct}\n"
|
80
|
-
end
|
81
|
-
end
|
10
|
+
TestCase.new(problem_name).validate
|
82
11
|
end
|
83
12
|
end
|
84
13
|
end
|
14
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Contest
|
2
|
+
attr_accessor :name, :url
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
@language = AtcoderGreedy.config[:language]
|
6
|
+
template_path = File.join(File.dirname(__dir__), '/templates')
|
7
|
+
@solve_template = open(template_path + "/#{@language}/solve.#{@language}", &:read)
|
8
|
+
@problem_names = %w(A B C D)
|
9
|
+
@name = name
|
10
|
+
puts "Create #{name} contest files"
|
11
|
+
@base_url = create_contest_url(name)
|
12
|
+
puts "Contest url is #{@base_url}"
|
13
|
+
@problem_urls = create_contest_problem_urls(name)
|
14
|
+
puts 'Create directories'
|
15
|
+
create_directories
|
16
|
+
create_templates
|
17
|
+
puts 'Set up done.'
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_contest_url(contest_name)
|
21
|
+
'http://' + contest_name + '.contest.atcoder.jp'
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_contest_problem_urls(contest_name)
|
25
|
+
urls = []
|
26
|
+
if (contest_name.include?('abc') && contest_name[3..5].to_i > 19) ||
|
27
|
+
(contest_name.include?('arc') && contest_name[3..5].to_i > 34)
|
28
|
+
task_num = %w(a b c d)
|
29
|
+
else
|
30
|
+
task_num = %w(1 2 3 4)
|
31
|
+
end
|
32
|
+
|
33
|
+
4.times do |i|
|
34
|
+
urls.push(name: "#{@problem_names[i]}", path: @base_url + "/tasks/#{contest_name}_#{task_num[i]}")
|
35
|
+
end
|
36
|
+
urls
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_templates
|
40
|
+
@problem_urls.each_with_index do |url, pro_i|
|
41
|
+
problem_dir = "./#{@name}"
|
42
|
+
# urlからインプット、アウトプットパラメータをとってきてファイルにしまう
|
43
|
+
charset = nil
|
44
|
+
html = open(url[:path]) do |f|
|
45
|
+
charset = f.charset
|
46
|
+
f.read
|
47
|
+
end
|
48
|
+
doc = Nokogiri::HTML.parse(html, nil, charset)
|
49
|
+
in_file = File.new(problem_dir + "/input_#{@problem_names[pro_i]}.txt", 'w')
|
50
|
+
|
51
|
+
params = doc.xpath('//pre')
|
52
|
+
params.shift
|
53
|
+
params.each_with_index do |p, i|
|
54
|
+
if i % 2 == 0
|
55
|
+
in_file.puts "-- Example #{i/2}"
|
56
|
+
in_file.puts "#{p.text.gsub(/\r\n?/, "\n").strip}"
|
57
|
+
else
|
58
|
+
in_file.puts "-- Answer #{(i-1)/2}"
|
59
|
+
in_file.puts "#{p.text.gsub(/\r\n?/, "\n").strip}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
in_file.close
|
64
|
+
|
65
|
+
solve_file_content = @solve_template.clone
|
66
|
+
solve_file_content.gsub!(/DATE/, Time.now.strftime('%F'))
|
67
|
+
solve_file_content.gsub!(/CONTEST/, @name.upcase)
|
68
|
+
solve_file_content.gsub!(/PROBLEM/, url[:name].upcase)
|
69
|
+
solve_file = File.new(problem_dir + "/#{url[:name]}.#{@language}", 'w')
|
70
|
+
solve_file.print solve_file_content
|
71
|
+
solve_file.close
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def create_directories
|
76
|
+
# コンテストディレクトリ作成
|
77
|
+
FileUtils.mkdir(@name)
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Languages
|
2
|
+
ALL_LANGUAGES = %w(rb cpp)
|
3
|
+
def initialize(solve_file)
|
4
|
+
@solve_file = solve_file
|
5
|
+
end
|
6
|
+
|
7
|
+
def compile(problem_name)
|
8
|
+
raise 'Error: Not Implemented'
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(input_path, output_path)
|
12
|
+
raise 'Error: Not Implemented'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Rb < Languages
|
17
|
+
def compile(problem_name)
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute(input_path, output_path)
|
22
|
+
system "ruby #{@solve_file} < #{input_path} > #{output_path}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Cpp < Languages
|
27
|
+
def compile(problem_name)
|
28
|
+
@exec_file = "#{problem_name}.out"
|
29
|
+
system "g++ #{@solve_file} -o #{problem_name}.out"
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute(input_path, output_path)
|
33
|
+
system "./#{@exec_file} < #{input_path} > #{output_path}"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'diff/lcs'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'benchmark'
|
4
|
+
require 'atcoder_greedy/lib/languages'
|
5
|
+
class TestCase
|
6
|
+
def initialize(problem_name)
|
7
|
+
language = File.extname(problem_name)
|
8
|
+
if language.size == 0
|
9
|
+
language = '.' + AtcoderGreedy.config[:language]
|
10
|
+
problem_name = problem_name + language
|
11
|
+
end
|
12
|
+
puts "Running a test for problem #{problem_name}..."
|
13
|
+
|
14
|
+
@problem_name = File.basename(problem_name, '.*')
|
15
|
+
@input_file = File.open("./input_#{@problem_name}.txt", 'r')
|
16
|
+
@exec_file = "./#{@problem_name}#{language}"
|
17
|
+
get_in_out
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_in_out
|
21
|
+
i = 0
|
22
|
+
@input = []
|
23
|
+
@output = []
|
24
|
+
now = nil
|
25
|
+
while (t = @input_file.gets) != nil
|
26
|
+
example_string = "-- Example #{i}"
|
27
|
+
answer_string = "-- Answer #{i}"
|
28
|
+
|
29
|
+
if t.chomp == example_string
|
30
|
+
now.close(false) unless now.nil?
|
31
|
+
now = Tempfile.new(['in', '.txt'], './')
|
32
|
+
@input.push(now)
|
33
|
+
now.open
|
34
|
+
elsif t.chomp == answer_string
|
35
|
+
now.close(false) unless now.nil?
|
36
|
+
now = Tempfile.new(['out', '.txt'], './')
|
37
|
+
@output.push(now)
|
38
|
+
now.open
|
39
|
+
i += 1
|
40
|
+
else
|
41
|
+
now.puts t
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@input[-1].close(false)
|
45
|
+
@output[-1].close(false)
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate
|
49
|
+
my_solve = get_solve(@exec_file)
|
50
|
+
begin
|
51
|
+
if my_solve.compile(@problem_name)
|
52
|
+
puts '-------------------- Compile Done --------------------'
|
53
|
+
else
|
54
|
+
raise 'Compile Error'
|
55
|
+
end
|
56
|
+
|
57
|
+
@input.size.times do |j|
|
58
|
+
myout_file = Tempfile.new(['myout', '.txt'], './')
|
59
|
+
myout_file.open
|
60
|
+
result = Benchmark.realtime do
|
61
|
+
unless my_solve.execute(@input[j].path, myout_file.path)
|
62
|
+
raise "Runtime Error"
|
63
|
+
end
|
64
|
+
@input[j].close
|
65
|
+
myout_file.close(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
myout = myout_file.open.read
|
69
|
+
myout_file.close
|
70
|
+
correct = File.open("#{@output[j].path}").read
|
71
|
+
diffs = Diff::LCS.diff(myout, correct)
|
72
|
+
if diffs.size == 0
|
73
|
+
puts "-------------------- Testcase ##{j} -------------------- PASSED! Time: #{sprintf("%.5f", result)}s"
|
74
|
+
else
|
75
|
+
puts "-------------------- Testcase ##{j} -------------------- FAILED! Time: #{sprintf("%.5f", result)}s"
|
76
|
+
puts "Your Output:"
|
77
|
+
puts "#{myout}\n"
|
78
|
+
puts "Correct Answer:"
|
79
|
+
puts "#{correct}\n"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
puts "Test done."
|
83
|
+
rescue => e
|
84
|
+
puts e
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# HACK: move to Languages
|
89
|
+
def get_solve(solve_file)
|
90
|
+
case File.extname(solve_file)
|
91
|
+
when '.rb'
|
92
|
+
Rb.new(solve_file)
|
93
|
+
when '.cpp'
|
94
|
+
Cpp.new(solve_file)
|
95
|
+
else
|
96
|
+
raise 'Unknown Lanugage'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/lib/atcoder_greedy.rb
CHANGED
@@ -1,9 +1,61 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'fileutils'
|
4
|
+
require 'yaml'
|
5
|
+
require 'psych'
|
4
6
|
|
5
7
|
require "atcoder_greedy/version"
|
6
8
|
require 'atcoder_greedy/command'
|
7
9
|
|
8
10
|
module AtcoderGreedy
|
11
|
+
# Configuration defaults
|
12
|
+
@config = {
|
13
|
+
user_id: '',
|
14
|
+
password: '',
|
15
|
+
language: 'rb'
|
16
|
+
}
|
17
|
+
|
18
|
+
@valid_config_keys = @config.keys
|
19
|
+
|
20
|
+
# Configure through hash
|
21
|
+
def self.configure(opts = {})
|
22
|
+
opts.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Configure through yaml file
|
26
|
+
def self.configure_with(path_to_yaml_file)
|
27
|
+
begin
|
28
|
+
config = YAML::load(IO.read(path_to_yaml_file))
|
29
|
+
rescue Errno::ENOENT
|
30
|
+
puts "YAML configuration file couldn't be found. Using defaults."; return
|
31
|
+
rescue Psych::SyntaxError
|
32
|
+
puts "YAML configuration file contains invalid syntax. Using defaults."; return
|
33
|
+
end
|
34
|
+
|
35
|
+
configure(config)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_config_path
|
39
|
+
config_path = Dir.home + '/.atcoder_greedy'
|
40
|
+
if Dir.exists?(config_path)
|
41
|
+
# use user settings
|
42
|
+
config_path
|
43
|
+
else
|
44
|
+
# use default settings
|
45
|
+
File.join(File.dirname(__dir__), '/lib/atcoder_greedy')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.config
|
50
|
+
yml_path = get_config_path + '/settings.yml'
|
51
|
+
configure_with(yml_path)
|
52
|
+
@config
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.save_config
|
56
|
+
yml_path = get_config_path + '/settings.yml'
|
57
|
+
f = File.open(yml_path, 'w')
|
58
|
+
f.print(@config.to_yaml)
|
59
|
+
f.close
|
60
|
+
end
|
9
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atcoder_greedy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- keigo-brook
|
@@ -103,9 +103,16 @@ files:
|
|
103
103
|
- bin/setup
|
104
104
|
- lib/atcoder_greedy.rb
|
105
105
|
- lib/atcoder_greedy/command.rb
|
106
|
+
- lib/atcoder_greedy/command/config.rb
|
106
107
|
- lib/atcoder_greedy/command/create.rb
|
108
|
+
- lib/atcoder_greedy/command/destroy.rb
|
107
109
|
- lib/atcoder_greedy/command/test.rb
|
108
|
-
- lib/atcoder_greedy/
|
110
|
+
- lib/atcoder_greedy/lib/contest.rb
|
111
|
+
- lib/atcoder_greedy/lib/languages.rb
|
112
|
+
- lib/atcoder_greedy/lib/test_case.rb
|
113
|
+
- lib/atcoder_greedy/settings.yml
|
114
|
+
- lib/atcoder_greedy/templates/cpp/solve.cpp
|
115
|
+
- lib/atcoder_greedy/templates/rb/solve.rb
|
109
116
|
- lib/atcoder_greedy/version.rb
|
110
117
|
homepage: https://github.com/keigo-brook/atcoder_greedy
|
111
118
|
licenses:
|