green_day 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.sample +3 -0
- data/.github/workflows/ruby.yml +60 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/green_day +8 -0
- data/green_day.gemspec +37 -0
- data/lib/green_day/atcoder_client.rb +93 -0
- data/lib/green_day/cli.rb +36 -0
- data/lib/green_day/contest.rb +20 -0
- data/lib/green_day/task.rb +28 -0
- data/lib/green_day/test_builder.rb +35 -0
- data/lib/green_day/version.rb +5 -0
- data/lib/green_day.rb +8 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 11c63d51a8f35f37def1b02e9c086f8d949c533d5ab52a37fd96bcb060cff4bf
|
4
|
+
data.tar.gz: 7aa09714d46b3eb9421dc474b7e390e7164629e6963dcdaaff789fe2eccd19b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99fc8237b043f932d76424feefec441e756e4516e6dfe0d7d965db16c60045c91d0d298e382614859e4a325f505737c4759ca0646f93c8f6023e7713538e5e38
|
7
|
+
data.tar.gz: e12d333418eff9f24ad6111472bb91a57120b2a1c7c596c244ab98855ced8ab744aae953e3429aa7fd28856d2d1d86c77c8f19e8c82cba7c20adaa8274541aab
|
data/.env.sample
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ${{ matrix.runner }}
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
ruby:
|
15
|
+
- 2.3.3
|
16
|
+
- 2.7.0
|
17
|
+
include:
|
18
|
+
- ruby: 2.3.3
|
19
|
+
runner: ubuntu-16.04
|
20
|
+
- ruby: 2.7.0
|
21
|
+
runner: ubuntu-latest
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v2
|
25
|
+
|
26
|
+
- name: Set up rbenv
|
27
|
+
uses: masa-iwasaki/setup-rbenv@1.1.0
|
28
|
+
|
29
|
+
- name: Cache RBENV_ROOT
|
30
|
+
uses: actions/cache@v1
|
31
|
+
id: cache_rbenv
|
32
|
+
with:
|
33
|
+
path: ~/.rbenv/versions
|
34
|
+
key: v1-rbenv-${{ runner.os }}-${{ matrix.ruby }}
|
35
|
+
|
36
|
+
- name: Reinstall libssl-dev
|
37
|
+
run: |
|
38
|
+
set -xe
|
39
|
+
sudo apt-get remove -y libssl-dev
|
40
|
+
sudo apt-get install -y libssl-dev=1.0.2g-1ubuntu4.15
|
41
|
+
if: matrix.runner == 'ubuntu-16.04'
|
42
|
+
|
43
|
+
- name: Install Ruby
|
44
|
+
env:
|
45
|
+
RBENV_VERSION: ${{ matrix.ruby }}
|
46
|
+
run: |
|
47
|
+
set -xe
|
48
|
+
eval "$(rbenv init -)"
|
49
|
+
rbenv install -s $RBENV_VERSION
|
50
|
+
gem install bundler || true
|
51
|
+
|
52
|
+
- name: test with Rake
|
53
|
+
env:
|
54
|
+
USER_NAME: ${{ secrets.USER_NAME }}
|
55
|
+
PASSWORD: ${{ secrets.PASSWORD }}
|
56
|
+
RBENV_VERSION: ${{ matrix.ruby }}
|
57
|
+
run: |
|
58
|
+
eval "$(rbenv init -)"
|
59
|
+
bundle install --jobs 4 --retry 3
|
60
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ikusawasi@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 qwyng
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# GreenDay
|
2
|
+
Automatically create workspace and tests for Atcoder contests
|
3
|
+
(日本語で解説した記事は[こちら](https://qiita.com/QWYNG/items/0e2e6b72bd1969d0d751))
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'green_day'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install green_day
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
login(this command stores your cookie as `cookie-store` in current directory)
|
22
|
+
|
23
|
+
$ bundle exec green_day login
|
24
|
+
|
25
|
+
If you want to delete session, remove `cookie-store`
|
26
|
+
|
27
|
+
This command creates directory and spec.
|
28
|
+
|
29
|
+
$ bundle exec green_day new <contest-name>
|
30
|
+
|
31
|
+
For example
|
32
|
+
|
33
|
+
$ bundle exec green_day new abc150
|
34
|
+
|
35
|
+
```
|
36
|
+
abc150
|
37
|
+
├── A.rb
|
38
|
+
├── B.rb
|
39
|
+
├── C.rb
|
40
|
+
├── D.rb
|
41
|
+
├── E.rb
|
42
|
+
├── F.rb
|
43
|
+
└── spec
|
44
|
+
├── A_spec.rb
|
45
|
+
├── B_spec.rb
|
46
|
+
├── C_spec.rb
|
47
|
+
├── D_spec.rb
|
48
|
+
├── E_spec.rb
|
49
|
+
└── F_spec.rb
|
50
|
+
```
|
51
|
+
|
52
|
+
Example of output spec
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'rspec'
|
56
|
+
|
57
|
+
RSpec.describe 'test' do
|
58
|
+
it 'test with "2 900\n"' do
|
59
|
+
io = IO.popen("ruby abc150/A.rb", "w+")
|
60
|
+
io.puts("2 900\n")
|
61
|
+
expect(io.gets).to eq("Yes\n")
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'test with "1 501\n"' do
|
65
|
+
io = IO.popen("ruby abc150/A.rb", "w+")
|
66
|
+
io.puts("1 501\n")
|
67
|
+
expect(io.gets).to eq("No\n")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'test with "4 2000\n"' do
|
71
|
+
io = IO.popen("ruby abc150/A.rb", "w+")
|
72
|
+
io.puts("4 2000\n")
|
73
|
+
expect(io.gets).to eq("Yes\n")
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
You need create `.env` and set `USER_NAME` and `PASSWORD` for spec. see `env.sample`
|
87
|
+
Those env is already set as secret on CI.
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/QWYNG/green_day. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the GreenDay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/green_day/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'green_day'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/green_day
ADDED
data/green_day.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'green_day/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'green_day'
|
9
|
+
spec.executables = ['green_day']
|
10
|
+
spec.version = GreenDay::VERSION
|
11
|
+
spec.authors = ['qwyng']
|
12
|
+
spec.email = ['ikusawasi@gmail.com']
|
13
|
+
|
14
|
+
spec.summary = 'CLI tool for AtCoder and Ruby'
|
15
|
+
spec.description = 'CLI tool for AtCoder and Ruby'
|
16
|
+
spec.homepage = 'https://github.com/QWYNG/green_day'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
+
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'faraday', '< 1.0'
|
29
|
+
spec.add_dependency 'faraday-cookie_jar'
|
30
|
+
spec.add_dependency 'nokogiri'
|
31
|
+
spec.add_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_dependency 'thor'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
34
|
+
spec.add_development_dependency 'dotenv'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rubocop'
|
37
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday-cookie_jar'
|
5
|
+
require 'webrick/cookie'
|
6
|
+
require 'nokogiri'
|
7
|
+
|
8
|
+
module GreenDay
|
9
|
+
class AtcoderClient
|
10
|
+
ATCODER_ENDPOINT = 'https://atcoder.jp'
|
11
|
+
COOKIE_DB = 'cookie-store'
|
12
|
+
attr_reader :client, :cookie_jar
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@cookie_jar = create_or_load_cookie_jar
|
16
|
+
@client = Faraday.new(url: ATCODER_ENDPOINT) do |builder|
|
17
|
+
builder.use :cookie_jar, jar: cookie_jar
|
18
|
+
builder.request :url_encoded
|
19
|
+
builder.adapter :net_http
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def contest_exist?(contest_name)
|
24
|
+
res = client.get("contests/#{contest_name}")
|
25
|
+
res.status == 200
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch_task_codes(contest)
|
29
|
+
body = get_parsed_body("contests/#{contest.name}/tasks")
|
30
|
+
|
31
|
+
# 3問だったら<tbody>の中に<tr>が3 * 2個 </tbody> が1mh個
|
32
|
+
tasks_size = ((body.at('tbody').children.size - 1) / 2.0).ceil
|
33
|
+
('A'..'Z').to_a.shift(tasks_size)
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch_inputs_and_outputs(contest, task)
|
37
|
+
contest_name = contest.name
|
38
|
+
path = "contests/#{contest_name}/tasks/#{contest_name}_#{task.code.downcase}"
|
39
|
+
body = get_parsed_body(path)
|
40
|
+
samples = body.css('.lang-ja > .part > section > pre').map { |e| e.children.text }
|
41
|
+
|
42
|
+
inputs, outputs = samples.partition.with_index { |_sample, i| i.even? }
|
43
|
+
|
44
|
+
[inputs, outputs]
|
45
|
+
end
|
46
|
+
|
47
|
+
def login(username, password)
|
48
|
+
csrf_token = obtain_atcoder_csrf_token
|
49
|
+
|
50
|
+
client.post('/login',
|
51
|
+
username: username,
|
52
|
+
password: password,
|
53
|
+
csrf_token: csrf_token)
|
54
|
+
|
55
|
+
unless login_succeed?
|
56
|
+
## ex error:Username or Password is incorrect
|
57
|
+
raise Error, CGI.unescape(select_flash_cookie.value).split('.').shift
|
58
|
+
end
|
59
|
+
|
60
|
+
cookie_jar.save(COOKIE_DB)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def create_or_load_cookie_jar
|
66
|
+
jar = HTTP::CookieJar.new
|
67
|
+
jar.load(COOKIE_DB) if File.exist?(COOKIE_DB)
|
68
|
+
jar
|
69
|
+
end
|
70
|
+
|
71
|
+
def obtain_atcoder_csrf_token
|
72
|
+
get_login_response = client.get('/login')
|
73
|
+
login_html = Nokogiri::HTML.parse(get_login_response.body)
|
74
|
+
login_html.at('input[name="csrf_token"]')['value']
|
75
|
+
rescue StandardError
|
76
|
+
raise Error, 'cant get_csrf_token'
|
77
|
+
end
|
78
|
+
|
79
|
+
def login_succeed?
|
80
|
+
flash_cookie = select_flash_cookie
|
81
|
+
flash_cookie.value.include?('Welcome')
|
82
|
+
end
|
83
|
+
|
84
|
+
def select_flash_cookie
|
85
|
+
cookie_jar.store.instance_variable_get(:@jar)['atcoder.jp']['/']['REVEL_FLASH']
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_parsed_body(path)
|
89
|
+
res = client.get(path)
|
90
|
+
Nokogiri::HTML.parse(res.body)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'io/console'
|
5
|
+
require_relative 'atcoder_client'
|
6
|
+
require_relative 'contest'
|
7
|
+
require_relative 'test_builder'
|
8
|
+
|
9
|
+
module GreenDay
|
10
|
+
class Cli < Thor
|
11
|
+
desc 'login Atcoder', 'login Atcoder and save session'
|
12
|
+
def login
|
13
|
+
print 'username:'
|
14
|
+
username = STDIN.gets.chomp!
|
15
|
+
password = STDIN.getpass('password:').chomp!
|
16
|
+
|
17
|
+
AtcoderClient.new.login(username, password)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'new [contest name]', 'create contest workspace and spec'
|
21
|
+
def new(contest_name)
|
22
|
+
contest = Contest.new(contest_name)
|
23
|
+
FileUtils.makedirs("#{contest_name}/spec")
|
24
|
+
|
25
|
+
contest.tasks.each do |task|
|
26
|
+
task_code = task.code
|
27
|
+
answer = File.open("#{contest_name}/#{task_code}.rb", 'w')
|
28
|
+
test = TestBuilder.build_test(answer, task.input_output_hash)
|
29
|
+
|
30
|
+
File.open("#{contest.name}/spec/#{task_code}_spec.rb", 'w') do |f|
|
31
|
+
f.write(test)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'atcoder_client'
|
4
|
+
require_relative 'task'
|
5
|
+
|
6
|
+
module GreenDay
|
7
|
+
class Contest
|
8
|
+
attr_reader :atcoder_client, :name, :tasks
|
9
|
+
|
10
|
+
def initialize(contest_name)
|
11
|
+
client = AtcoderClient.new
|
12
|
+
raise GreenDay::Error 'cant find contest' unless client.contest_exist?(contest_name)
|
13
|
+
|
14
|
+
@name = contest_name
|
15
|
+
@tasks = client.fetch_task_codes(self).map do |task_code|
|
16
|
+
Task.new(self, task_code)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GreenDay
|
4
|
+
class Task
|
5
|
+
attr_reader :contest, :code, :input_output_hash
|
6
|
+
def initialize(contest, code)
|
7
|
+
@contest = contest
|
8
|
+
@code = code
|
9
|
+
@input_output_hash = create_input_output_hash
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def create_input_output_hash
|
15
|
+
client = AtcoderClient.new
|
16
|
+
|
17
|
+
input_samples, output_samples =
|
18
|
+
client.fetch_inputs_and_outputs(contest, self)
|
19
|
+
|
20
|
+
hash = {}
|
21
|
+
input_samples.zip(output_samples).each do |input, output|
|
22
|
+
hash[input] = output
|
23
|
+
end
|
24
|
+
|
25
|
+
hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GreenDay
|
4
|
+
module TestBuilder
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def build_test(answer, input_output_hash)
|
8
|
+
<<~SPEC
|
9
|
+
require 'rspec'
|
10
|
+
|
11
|
+
RSpec.describe 'test' do
|
12
|
+
#{input_output_hash.map { |input, output| build_example(answer, input, output) }.join("\n")}
|
13
|
+
end
|
14
|
+
SPEC
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_example(answer, input, output)
|
18
|
+
<<~SPEC
|
19
|
+
#{tab}it 'test with #{unify_cr_lf(input)}' do
|
20
|
+
#{tab}#{tab}io = IO.popen("ruby #{answer.path}", "w+")
|
21
|
+
#{tab}#{tab}io.puts(#{unify_cr_lf(input)})
|
22
|
+
#{tab}#{tab}expect(io.gets).to eq(#{unify_cr_lf(output)})
|
23
|
+
#{tab}end
|
24
|
+
SPEC
|
25
|
+
end
|
26
|
+
|
27
|
+
def unify_cr_lf(string)
|
28
|
+
string.gsub(/\R/, "\n").dump
|
29
|
+
end
|
30
|
+
|
31
|
+
def tab
|
32
|
+
"\s\s"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/green_day.rb
ADDED
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: green_day
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- qwyng
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "<"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-cookie_jar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: CLI tool for AtCoder and Ruby
|
140
|
+
email:
|
141
|
+
- ikusawasi@gmail.com
|
142
|
+
executables:
|
143
|
+
- green_day
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".env.sample"
|
148
|
+
- ".github/workflows/ruby.yml"
|
149
|
+
- ".gitignore"
|
150
|
+
- ".rspec"
|
151
|
+
- ".rubocop.yml"
|
152
|
+
- CODE_OF_CONDUCT.md
|
153
|
+
- Gemfile
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- bin/console
|
158
|
+
- bin/setup
|
159
|
+
- exe/green_day
|
160
|
+
- green_day.gemspec
|
161
|
+
- lib/green_day.rb
|
162
|
+
- lib/green_day/atcoder_client.rb
|
163
|
+
- lib/green_day/cli.rb
|
164
|
+
- lib/green_day/contest.rb
|
165
|
+
- lib/green_day/task.rb
|
166
|
+
- lib/green_day/test_builder.rb
|
167
|
+
- lib/green_day/version.rb
|
168
|
+
homepage: https://github.com/QWYNG/green_day
|
169
|
+
licenses:
|
170
|
+
- MIT
|
171
|
+
metadata:
|
172
|
+
homepage_uri: https://github.com/QWYNG/green_day
|
173
|
+
source_code_uri: https://github.com/QWYNG/green_day
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubygems_version: 3.1.2
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: CLI tool for AtCoder and Ruby
|
193
|
+
test_files: []
|