green_day 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f5b0679f10107fc35099cf83129628c78a00ae6eba65897a2220834be605a31
4
- data.tar.gz: 46a41ff725c660eccf8561048da49cfb05997ec8cbf7b24c58f9922fef87b166
3
+ metadata.gz: 847d8c7165f8f49cde2bfa74baa93dbfe5c768f3d79b5e75f62f3c06c178c029
4
+ data.tar.gz: 765aa083bcf03e74c5f3d4ce43713209bcc76bdcb857872c1d05d729ebfaa793
5
5
  SHA512:
6
- metadata.gz: ecc4dfeed26338f8bc22ad7e0e6380b82a523b86d3f0ae7352be6567027869baa1ff00f5c6694aa886145d863c9e30cc2cf816718d4ff9cb8d0516f4df1a6a28
7
- data.tar.gz: 3651746ff097ccc98e359a3fe5ee941cfe2aefede5969990171d0d7e79bf86ae2edafd3ea6a2bb46eea9673fa54cbb6db8abaa36534768bc17763689da0c2b70
6
+ metadata.gz: 5e048781f120481b08b1c51a62744f5214cee0a0bd20902d528a2f0753330894682d24e29ff1ef63672ed5b3936011a611a30a6243d26b88b1c12cbf80ce588a
7
+ data.tar.gz: e80f114af4d24f10ce607ba652097e2ed0f42dee1ba49c2baf90f3c789557397ac7ca4595058a5d7238580aeb0f5bc050eddd3457a2afd81ef4a765866db21e0
data/green_day.gemspec CHANGED
@@ -32,6 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency 'thor'
33
33
  spec.add_development_dependency 'bundler', '~> 2.0'
34
34
  spec.add_development_dependency 'dotenv'
35
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '>= 12.3.3'
36
36
  spec.add_development_dependency 'rubocop'
37
37
  end
data/lib/green_day/cli.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'thor'
4
- require 'io/console'
5
4
  require_relative 'atcoder_client'
6
5
  require_relative 'contest'
7
6
  require_relative 'test_builder'
7
+ require_relative 'snippet_builder'
8
8
 
9
9
  module GreenDay
10
10
  class Cli < Thor
@@ -25,13 +25,41 @@ module GreenDay
25
25
 
26
26
  contest.tasks.each do |task|
27
27
  task_code = task.code
28
- answer = File.open("#{contest_name}/#{task_code}.rb", 'w')
29
- test = TestBuilder.build_test(answer, task.input_output_hash)
30
28
 
31
- File.open("#{contest.name}/spec/#{task_code}_spec.rb", 'w') do |f|
32
- f.write(test)
33
- end
29
+ create_submit_file!(contest_name, task_code)
30
+ create_spec_file!(contest_name, task_code, task.input_output_hash)
34
31
  end
35
32
  end
33
+
34
+ private
35
+
36
+ def create_submit_file!(contest_name, task_code)
37
+ File.open(submit_file_path(contest_name, task_code), 'w') do |f|
38
+ f.write(SnippetBuilder.build)
39
+ end
40
+
41
+ true
42
+ end
43
+
44
+ def create_spec_file!(contest_name, task_code, input_output_hash)
45
+ test =
46
+ TestBuilder.build_test(
47
+ submit_file_path(contest_name, task_code),
48
+ input_output_hash
49
+ )
50
+ File.open(spec_file_path(contest_name, task_code), 'w') do |f|
51
+ f.write(test)
52
+ end
53
+
54
+ true
55
+ end
56
+
57
+ def submit_file_path(contest_name, task_code)
58
+ "#{contest_name}/#{task_code}.rb"
59
+ end
60
+
61
+ def spec_file_path(contest_name, task_code)
62
+ "#{contest_name}/spec/#{task_code}_spec.rb"
63
+ end
36
64
  end
37
65
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SnippetBuilder
4
+ INCREASE_STACK_SIZE_SNIPPET =
5
+ "ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)"
6
+ MULTIPLE_LINE_INPUT_SNIPPET = 'readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }'
7
+ ARRAY_INPUT_SNIPPET = 'gets.split.map(&:to_i)'
8
+
9
+ module_function
10
+
11
+ def build
12
+ [INCREASE_STACK_SIZE_SNIPPET, MULTIPLE_LINE_INPUT_SNIPPET, ARRAY_INPUT_SNIPPET]
13
+ .map { |snippet| '# ' + snippet }
14
+ .join("\n") + "\n"
15
+ end
16
+ end
@@ -4,20 +4,20 @@ module GreenDay
4
4
  module TestBuilder
5
5
  module_function
6
6
 
7
- def build_test(answer, input_output_hash)
7
+ def build_test(submit_file_path, input_output_hash)
8
8
  <<~SPEC
9
9
  require 'rspec'
10
10
 
11
11
  RSpec.describe 'test' do
12
- #{input_output_hash.map { |input, output| build_example(answer, input, output) }.join("\n")}
12
+ #{input_output_hash.map { |input, output| build_example(submit_file_path, input, output) }.join("\n")}
13
13
  end
14
14
  SPEC
15
15
  end
16
16
 
17
- def build_example(answer, input, output)
17
+ def build_example(submit_file_path, input, output)
18
18
  <<~SPEC
19
19
  #{tab}it 'test with #{unify_cr_lf(input)}' do
20
- #{tab}#{tab}io = IO.popen("ruby #{answer.path}", "w+")
20
+ #{tab}#{tab}io = IO.popen("ruby #{submit_file_path}", "w+")
21
21
  #{tab}#{tab}io.puts(#{unify_cr_lf(input)})
22
22
  #{tab}#{tab}io.close_write
23
23
  #{tab}#{tab}expect(io.readlines.join).to eq(#{unify_cr_lf(output)})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GreenDay
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - qwyng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-18 00:00:00.000000000 Z
11
+ date: 2020-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '10.0'
117
+ version: 12.3.3
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '10.0'
124
+ version: 12.3.3
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +162,7 @@ files:
162
162
  - lib/green_day/atcoder_client.rb
163
163
  - lib/green_day/cli.rb
164
164
  - lib/green_day/contest.rb
165
+ - lib/green_day/snippet_builder.rb
165
166
  - lib/green_day/task.rb
166
167
  - lib/green_day/test_builder.rb
167
168
  - lib/green_day/version.rb