Upgrade to Pro — share decks privately, control downloads, hide ads and more …

My Gems for AtCoder

Hiroaki Osawa
July 11, 2024
46

My Gems for AtCoder

Hiroaki Osawa

July 11, 2024
Tweet

Transcript

  1. My Gems for AtCoder My Gems for AtCoder 大澤広朗 X:@qwyngg

    GitHub:@QWYNG Roppongi.rb # 20 Powered by Rabbit 3.0.3 and COZMIXNG
  2. GreenDayのデモ(1) $ bundle exec green_day new abc150 abc150 ├── A.rb

    ├── B.rb ├── C.rb ├── D.rb ├── E.rb ├── F.rb └── spec ├── A_spec.rb ├── B_spec.rb ├── C_spec.rb ├── D_spec.rb ├── E_spec.rb └── F_spec.rb
  3. GreenDayのデモ(2) RSpec.describe 'abc150/A.rb' do it 'test with "2 900\n"' do

    io = IO.popen('ruby abc150/A.rb', 'w+') io.puts("2 900\n") io.close_write expect(io.readlines.join).to eq("Yes\n") end it 'test with "1 501\n"' do io = IO.popen('ruby abc150/A.rb', 'w+') io.puts("1 501\n") io.close_write expect(io.readlines.join).to eq("No\n") end it 'test with "4 2000\n"' do io = IO.popen('ruby abc150/A.rb', 'w+') io.puts("4 2000\n") io.close_write expect(io.readlines.join).to eq("Yes\n") end end
  4. IrbRemoteのデモ(1) # sample.rb require 'irb-remote' k = 1 ; x

    = 500 check_completion = '補完確認用変数' binding.irb_remote puts k * 500 >= x ? 'Yes' : 'No'
  5. IrbRemoteのデモ(3) $ irb-remote # 別の仮想端末で実行 Connected to remote session on

    druby://127.0.0.1:9876 From: sample.rb @ line 5 : 1: require 'irb-remote' 2: k = 1 ; x = 500 3: check_completion = '補完確認用変数' 4: => 5: binding.irb_remote 6: 7: puts k * 500 >= x ? 'Yes' : 'No' irb-remote> check_completion check_completionPress Option+d to read the full document String < Object ---------------------------------------- Includes: Comparable (from ruby core) Rainbow::Ext::String::InstanceMethods (from gem rainbow-3.1.1) (from ruby core) ----------------------------------------
  6. why IrbRemote?(3) 解答コード内でIRBを起動するとIRB出力が キャプチャされてしまう > rspec abc150/spec/A_spec.rb 1) abc150/A.rb test

    with "2 900\n" Failure/Error: expect(io.readlines.join).to eq("Yes\n") Diff: @@ -1,9 +1,18 @@ + +From: abc150/A.rb @ line 3 : + + 1: k, x = gets.split.map(&:to_i) + 2: check_complition = '予測変換もいい感じになってほしいなぁ' + => 3: binding.irb + 4: puts k * 500 >= x ? 'Yes' : 'No' +Switch to inspect mode. + Yes