at_coder_friends 0.6.2 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -2
  3. data/.travis.yml +2 -2
  4. data/CHANGELOG.md +53 -0
  5. data/Gemfile.lock +32 -36
  6. data/README.md +1 -1
  7. data/at_coder_friends.gemspec +5 -7
  8. data/config/default.yml +146 -72
  9. data/docs/CONFIGURATION.md +224 -140
  10. data/lib/at_coder_friends.rb +3 -0
  11. data/lib/at_coder_friends/cli.rb +8 -0
  12. data/lib/at_coder_friends/config_loader.rb +11 -3
  13. data/lib/at_coder_friends/context.rb +10 -6
  14. data/lib/at_coder_friends/emitter.rb +2 -2
  15. data/lib/at_coder_friends/generator/base.rb +42 -0
  16. data/lib/at_coder_friends/generator/cxx_builtin.rb +196 -143
  17. data/lib/at_coder_friends/generator/main.rb +8 -2
  18. data/lib/at_coder_friends/generator/ruby_builtin.rb +97 -51
  19. data/lib/at_coder_friends/parser/constraints.rb +1 -0
  20. data/lib/at_coder_friends/parser/input_format.rb +389 -188
  21. data/lib/at_coder_friends/parser/input_type.rb +92 -0
  22. data/lib/at_coder_friends/parser/main.rb +1 -0
  23. data/lib/at_coder_friends/parser/modulo.rb +1 -1
  24. data/lib/at_coder_friends/parser/sections.rb +3 -3
  25. data/lib/at_coder_friends/path_info.rb +51 -0
  26. data/lib/at_coder_friends/path_util.rb +0 -31
  27. data/lib/at_coder_friends/problem.rb +81 -6
  28. data/lib/at_coder_friends/scraping/agent.rb +11 -2
  29. data/lib/at_coder_friends/scraping/custom_test.rb +5 -6
  30. data/lib/at_coder_friends/scraping/submission.rb +6 -7
  31. data/lib/at_coder_friends/scraping/tasks.rb +8 -3
  32. data/lib/at_coder_friends/test_runner/base.rb +17 -4
  33. data/lib/at_coder_friends/test_runner/judge.rb +7 -9
  34. data/lib/at_coder_friends/test_runner/sample.rb +2 -4
  35. data/lib/at_coder_friends/verifier.rb +2 -3
  36. data/lib/at_coder_friends/version.rb +1 -1
  37. data/templates/{cxx_builtin_interactive.cxx → cxx_builtin.cxx.erb} +26 -4
  38. data/templates/{ruby_builtin_interactive.rb → ruby_builtin.rb.erb} +17 -3
  39. metadata +11 -17
  40. data/tasks/regression/check_const.rake +0 -136
  41. data/tasks/regression/check_diff.rake +0 -30
  42. data/tasks/regression/check_fmt.rake +0 -42
  43. data/tasks/regression/check_parse.rake +0 -70
  44. data/tasks/regression/regression.rb +0 -72
  45. data/tasks/regression/section_list.rake +0 -53
  46. data/tasks/regression/setup.rake +0 -48
  47. data/templates/cxx_builtin_default.cxx +0 -26
  48. data/templates/ruby_builtin_default.rb +0 -7
@@ -8,6 +8,7 @@ module AtCoderFriends
8
8
  # run tests for the specified program.
9
9
  class Base
10
10
  include PathUtil
11
+
11
12
  STATUS_STR = {
12
13
  OK: '<< OK >>'.green,
13
14
  WA: '!!!!! WA !!!!!'.red,
@@ -19,7 +20,7 @@ module AtCoderFriends
19
20
 
20
21
  def initialize(ctx)
21
22
  @ctx = ctx
22
- @path, @dir, @prg, @base, @ext, @q = split_prg_path(ctx.path)
23
+ @path, @dir, @prg, @base, @ext, @q = ctx.path_info.components
23
24
  @detail = true
24
25
  end
25
26
 
@@ -32,11 +33,23 @@ module AtCoderFriends
32
33
  end
33
34
 
34
35
  def test_loc
35
- test_cmd ? 'local' : 'remote'
36
+ if test_cmd
37
+ 'local'
38
+ elsif ctx.scraping_agent.respond_to?(:code_test)
39
+ 'remote'
40
+ else
41
+ raise AppError, "test_cmd for .#{ext} is not specified."
42
+ end
36
43
  end
37
44
 
38
45
  def test_mtd
39
- test_cmd ? :local_test : :remote_test
46
+ if test_cmd
47
+ :local_test
48
+ elsif ctx.scraping_agent.respond_to?(:code_test)
49
+ :remote_test
50
+ else
51
+ raise AppError, "test_cmd for .#{ext} is not specified."
52
+ end
40
53
  end
41
54
 
42
55
  def run_test(id, infile, outfile, expfile)
@@ -63,7 +76,7 @@ module AtCoderFriends
63
76
  end
64
77
 
65
78
  def local_test(infile, outfile)
66
- system("#{test_cmd} < #{infile} > #{outfile}")
79
+ system("#{test_cmd} < \"#{infile}\" > \"#{outfile}\"")
67
80
  end
68
81
 
69
82
  def remote_test(infile, outfile)
@@ -4,20 +4,18 @@ module AtCoderFriends
4
4
  module TestRunner
5
5
  # run test cases for the specified program with judge input/output.
6
6
  class Judge < Base
7
- include PathUtil
8
-
9
7
  attr_reader :data_dir, :result_dir
10
8
 
11
9
  def initialize(ctx)
12
10
  super(ctx)
13
- @data_dir = cases_dir(dir)
14
- @result_dir = cases_dir(tmp_dir(path))
11
+ @data_dir = ctx.path_info.cases_dir
12
+ @result_dir = ctx.path_info.cases_out_dir
15
13
  end
16
14
 
17
15
  def judge_all
18
16
  puts "***** judge_all #{prg} (#{test_loc}) *****"
19
- results = Dir["#{data_dir}/#{q}/in/*.txt"].sort.map do |infile|
20
- id = File.basename(infile, '.txt')
17
+ results = Dir["#{data_dir}/#{q}/in/*"].sort.map do |infile|
18
+ id = File.basename(infile)
21
19
  judge(id, false)
22
20
  end
23
21
  !results.empty? && results.all?
@@ -30,9 +28,9 @@ module AtCoderFriends
30
28
 
31
29
  def judge(id, detail = true)
32
30
  @detail = detail
33
- infile = "#{data_dir}/#{q}/in/#{id}.txt"
34
- outfile = "#{result_dir}/#{q}/result/#{id}.txt"
35
- expfile = "#{data_dir}/#{q}/out/#{id}.txt"
31
+ infile = "#{data_dir}/#{q}/in/#{id}"
32
+ outfile = "#{result_dir}/#{q}/result/#{id}"
33
+ expfile = "#{data_dir}/#{q}/out/#{id}"
36
34
  run_test(id, infile, outfile, expfile)
37
35
  end
38
36
  end
@@ -4,19 +4,17 @@ module AtCoderFriends
4
4
  module TestRunner
5
5
  # run test cases for the specified program with sample input/output.
6
6
  class Sample < Base
7
- include PathUtil
8
-
9
7
  attr_reader :data_dir
10
8
 
11
9
  def initialize(ctx)
12
10
  super(ctx)
13
- @data_dir = smp_dir(dir)
11
+ @data_dir = ctx.path_info.smp_dir
14
12
  end
15
13
 
16
14
  def test_all
17
15
  puts "***** test_all #{prg} (#{test_loc}) *****"
18
16
  results = Dir["#{data_dir}/#{q}_*.in"].sort.map do |infile|
19
- id = File.basename(infile, '.in').sub(/[^_]+_/, '')
17
+ id = File.basename(infile, '.in').sub(/\A#{q}_/, '')
20
18
  test(id)
21
19
  end
22
20
  !results.empty? && results.all?
@@ -10,9 +10,8 @@ module AtCoderFriends
10
10
  attr_reader :path, :file, :vdir, :vpath
11
11
 
12
12
  def initialize(ctx)
13
- @path = ctx.path
14
- @file = File.basename(path)
15
- @vdir = tmp_dir(path)
13
+ @path, _dir, @file = ctx.path_info.components
14
+ @vdir = ctx.path_info.tmp_dir
16
15
  @vpath = File.join(vdir, "#{file}.verified")
17
16
  end
18
17
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtCoderFriends
4
- VERSION = '0.6.2'
4
+ VERSION = '0.6.7'
5
5
  end
@@ -1,15 +1,20 @@
1
- // /*** URL ***/
1
+ // <%= pbm.url %>
2
2
 
3
3
  #include <cstdio>
4
+ <% if pbm.options.interactive -%>
4
5
  #include <vector>
5
6
  #include <string>
7
+ <% end -%>
6
8
 
7
9
  using namespace std;
8
10
 
11
+ <% if pbm.options.interactive -%>
9
12
  #define DEBUG
13
+ <% end -%>
10
14
  #define REP(i,n) for(int i=0; i<(int)(n); i++)
11
15
  #define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
12
16
 
17
+ <% if pbm.options.interactive -%>
13
18
  //------------------------------------------------------------------------------
14
19
  const int BUFSIZE = 1024;
15
20
  char req[BUFSIZE];
@@ -31,11 +36,17 @@ void query() {
31
36
  }
32
37
 
33
38
  //------------------------------------------------------------------------------
34
- /*** CONSTS ***/
39
+ <% end -%>
40
+ <% gen_consts.each do |line| -%>
41
+ <%= line %>
42
+ <% end -%>
35
43
 
36
- /*** DCLS ***/
44
+ <% gen_decls.each do |line| -%>
45
+ <%= line %>
46
+ <% end -%>
37
47
 
38
48
  void solve() {
49
+ <% if pbm.options.interactive -%>
39
50
  printf("! %s\n", ans);
40
51
  fflush(stdout);
41
52
  #ifdef DEBUG
@@ -45,13 +56,24 @@ void solve() {
45
56
  puts(responses[i].c_str());
46
57
  }
47
58
  #endif
59
+ <% elsif (vs = pbm.options.binary_values) -%>
60
+ bool cond = false;
61
+ puts(cond ? "<%= vs[0] %>" : "<%= vs[1] %>");
62
+ <% else -%>
63
+ int ans = 0;
64
+ printf("%d\n", ans);
65
+ <% end -%>
48
66
  }
49
67
 
50
68
  void input() {
51
- /*** INPUTS ***/
69
+ <% gen_inputs.each do |line| -%>
70
+ <%= line %>
71
+ <% end -%>
72
+ <% if pbm.options.interactive -%>
52
73
  #ifdef DEBUG
53
74
  scanf("%s", source);
54
75
  #endif
76
+ <% end -%>
55
77
  }
56
78
 
57
79
  int main() {
@@ -1,5 +1,6 @@
1
- # ### URL ###
1
+ # <%= pbm.url %>
2
2
 
3
+ <% if pbm.options.interactive -%>
3
4
  def query(*args)
4
5
  puts "? #{args.join(' ')}"
5
6
  STDOUT.flush
@@ -13,15 +14,23 @@ end
13
14
 
14
15
  $DEBUG = true
15
16
 
16
- ### CONSTS ###
17
+ <% end -%>
18
+ <% gen_consts.each do |line| -%>
19
+ <%= line %>
20
+ <% end -%>
17
21
 
18
- ### DCLS ###
22
+ <% gen_decls.each do |line| -%>
23
+ <%= line %>
24
+ <% end -%>
25
+ <% if pbm.options.interactive -%>
19
26
 
20
27
  if $DEBUG
21
28
  @responses = []
22
29
  @source = gets.chomp
23
30
  end
31
+ <% end -%>
24
32
 
33
+ <% if pbm.options.interactive -%>
25
34
  puts "! #{ans}"
26
35
  STDOUT.flush
27
36
 
@@ -32,3 +41,8 @@ if $DEBUG
32
41
  @responses.each { |res| puts res }
33
42
  puts "----------------------------------------"
34
43
  end
44
+ <% elsif (vs = pbm.options.binary_values) -%>
45
+ puts cond ? '<%= vs[0] %>' : '<%= vs[1] %>'
46
+ <% else -%>
47
+ puts ans
48
+ <% end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: at_coder_friends
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - nejiko96
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-17 00:00:00.000000000 Z
11
+ date: 2020-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: launchy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.4.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.4.3
41
41
  - !ruby/object:Gem::Dependency
@@ -159,12 +159,14 @@ files:
159
159
  - lib/at_coder_friends/context.rb
160
160
  - lib/at_coder_friends/emitter.rb
161
161
  - lib/at_coder_friends/errors.rb
162
+ - lib/at_coder_friends/generator/base.rb
162
163
  - lib/at_coder_friends/generator/cxx_builtin.rb
163
164
  - lib/at_coder_friends/generator/main.rb
164
165
  - lib/at_coder_friends/generator/ruby_builtin.rb
165
166
  - lib/at_coder_friends/parser/binary.rb
166
167
  - lib/at_coder_friends/parser/constraints.rb
167
168
  - lib/at_coder_friends/parser/input_format.rb
169
+ - lib/at_coder_friends/parser/input_type.rb
168
170
  - lib/at_coder_friends/parser/interactive.rb
169
171
  - lib/at_coder_friends/parser/introduction_wrapper.rb
170
172
  - lib/at_coder_friends/parser/main.rb
@@ -172,6 +174,7 @@ files:
172
174
  - lib/at_coder_friends/parser/sample_data.rb
173
175
  - lib/at_coder_friends/parser/section_wrapper.rb
174
176
  - lib/at_coder_friends/parser/sections.rb
177
+ - lib/at_coder_friends/path_info.rb
175
178
  - lib/at_coder_friends/path_util.rb
176
179
  - lib/at_coder_friends/problem.rb
177
180
  - lib/at_coder_friends/scraping/agent.rb
@@ -185,17 +188,8 @@ files:
185
188
  - lib/at_coder_friends/test_runner/sample.rb
186
189
  - lib/at_coder_friends/verifier.rb
187
190
  - lib/at_coder_friends/version.rb
188
- - tasks/regression/check_const.rake
189
- - tasks/regression/check_diff.rake
190
- - tasks/regression/check_fmt.rake
191
- - tasks/regression/check_parse.rake
192
- - tasks/regression/regression.rb
193
- - tasks/regression/section_list.rake
194
- - tasks/regression/setup.rake
195
- - templates/cxx_builtin_default.cxx
196
- - templates/cxx_builtin_interactive.cxx
197
- - templates/ruby_builtin_default.rb
198
- - templates/ruby_builtin_interactive.rb
191
+ - templates/cxx_builtin.cxx.erb
192
+ - templates/ruby_builtin.rb.erb
199
193
  homepage: https://github.com/nejiko96/at_coder_friends
200
194
  licenses:
201
195
  - MIT
@@ -211,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
205
  requirements:
212
206
  - - ">="
213
207
  - !ruby/object:Gem::Version
214
- version: 2.3.0
208
+ version: 2.4.0
215
209
  required_rubygems_version: !ruby/object:Gem::Requirement
216
210
  requirements:
217
211
  - - ">="
@@ -219,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
213
  version: '0'
220
214
  requirements: []
221
215
  rubyforge_project:
222
- rubygems_version: 2.5.2.3
216
+ rubygems_version: 2.6.14.4
223
217
  signing_key:
224
218
  specification_version: 4
225
219
  summary: AtCoder support tool
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'regression'
4
-
5
- module AtCoderFriends
6
- # tasks for regression
7
- module Regression
8
- module_function
9
-
10
- CONST_PAT = {
11
- mod: /
12
- (.{,30}(?:
13
- で割った|modulo|mod\b|divided\s+by|dividing\s+by
14
- ).{,30})
15
- /xmi,
16
- max: /
17
- (.{,30}(?:
18
- ≦|≤|\\le|&leq?;
19
- |<|\\lt|&lt;
20
- |以上.{1,25}以下の整数
21
- ).{,30})
22
- /xmi
23
- }.freeze
24
-
25
- def collect(tgt)
26
- File.open(const_log('collect', tgt), 'w') do |f|
27
- local_pbm_list.each do |contest, q, url|
28
- page = agent.get(url)
29
- body = page.body.force_encoding('utf-8')
30
- ms = body.scan(CONST_PAT[tgt.to_sym])
31
- ms.each do |m|
32
- s = m[0].delete("\r\n\t\"")
33
- f.puts [contest, q, s].join("\t")
34
- end
35
- end
36
- end
37
- end
38
-
39
- def check_mod
40
- File.open(const_log('check', 'mod'), 'w') do |f|
41
- local_pbm_list.each do |contest, q, url|
42
- pbm = scraping_agent(nil, contest).fetch_problem(q, url)
43
- Parser::Sections.process(pbm)
44
- Parser::Modulo.process(pbm)
45
- pbm.constants.each do |cnst|
46
- f.puts [contest, q, cnst.value].join("\t")
47
- end
48
- end
49
- end
50
- end
51
-
52
- def check_max
53
- File.open(const_log('check', 'max'), 'w') do |f|
54
- local_pbm_list.each do |contest, q, url|
55
- pbm = scraping_agent(nil, contest).fetch_problem(q, url)
56
- Parser::Sections.process(pbm)
57
- Parser::Constraints.process(pbm)
58
- pbm.constants.each do |cns|
59
- f.puts [contest, q, "#{cns.name}:#{cns.value}"].join("\t")
60
- end
61
- end
62
- end
63
- end
64
-
65
- def merge_list(tgt)
66
- tbl = load_merge_list(tgt)
67
- save_merge_list(tgt, tbl)
68
- end
69
-
70
- def load_merge_list(tgt)
71
- tbl = {}
72
- %w[collect check]
73
- .map { |act| const_log(act, tgt) }
74
- .each
75
- .with_index(1) do |file, n|
76
- list_from_file(file)
77
- .group_by { |contest, q, _| "#{contest}\t#{q}" }
78
- .map { |key, grp| [key, grp.map { |row| row[2] }.join("\n")] }
79
- .each do |key, txt|
80
- tbl[key] ||= { 'v1' => '', 'v2' => '' }
81
- tbl[key]["v#{n}"] = '"' + txt + '"'
82
- end
83
- end
84
- tbl
85
- end
86
-
87
- def save_merge_list(tgt, tbl)
88
- File.open(const_log('merge', tgt), 'w') do |f|
89
- tbl.sort.each do |k, h|
90
- f.puts [k, h['v1'], h['v2']].join("\t")
91
- end
92
- end
93
- end
94
-
95
- def const_log(act, tgt)
96
- log_path("#{act}_#{tgt}.txt")
97
- end
98
-
99
- def list_from_file(file)
100
- Encoding.default_external = 'utf-8'
101
- CSV.read(file, col_sep: "\t", headers: false)
102
- end
103
- end
104
- end
105
-
106
- namespace :regression do
107
- desc 'list all mod values'
108
- task :collect_mod do
109
- AtCoderFriends::Regression.collect('mod')
110
- end
111
-
112
- desc 'check extracted mod values'
113
- task :check_mod do
114
- AtCoderFriends::Regression.check_mod
115
- end
116
-
117
- desc 'merge mod values list'
118
- task :merge_mod do
119
- AtCoderFriends::Regression.merge_list('mod')
120
- end
121
-
122
- desc 'list all max values'
123
- task :collect_max do
124
- AtCoderFriends::Regression.collect('max')
125
- end
126
-
127
- desc 'check extracted max values'
128
- task :check_max do
129
- AtCoderFriends::Regression.check_max
130
- end
131
-
132
- desc 'merge max values list'
133
- task :merge_max do
134
- AtCoderFriends::Regression.merge_list('max')
135
- end
136
- end