Class: Clicoder::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/clicoder/cli.rb

Instance Method Summary collapse

Instance Method Details

#add_testObject



114
115
116
117
118
119
120
121
122
123
# File 'lib/clicoder/cli.rb', line 114

def add_test
  load_local_config
  test_count = Dir.glob("#{INPUTS_DIRNAME}/*.txt").count
  input_file = "#{INPUTS_DIRNAME}/#{test_count}.txt"
  output_file = "#{OUTPUTS_DIRNAME}/#{test_count}.txt"
  puts 'Input:'
  system("cat > #{input_file}")
  puts 'Output:'
  system("cat > #{output_file}")
end

#allObject



49
50
51
52
53
# File 'lib/clicoder/cli.rb', line 49

def all
  invoke :build
  invoke :execute
  invoke :judge
end

#browseObject



138
139
140
141
142
# File 'lib/clicoder/cli.rb', line 138

def browse
  load_local_config
  site = get_site
  Launchy.open(site.problem_url)
end

#buildObject



56
57
58
59
# File 'lib/clicoder/cli.rb', line 56

def build
  load_local_config
  system('make build')
end

#downloadObject



126
127
128
129
130
131
132
133
134
135
# File 'lib/clicoder/cli.rb', line 126

def download
  load_local_config
  site = get_site
  # TODO: this is not beautiful
  Dir.chdir('..') do
    site.download_description
    site.download_inputs
    site.download_outputs
  end
end

#executeObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/clicoder/cli.rb', line 62

def execute
  load_local_config
  Dir.glob("#{INPUTS_DIRNAME}/*.txt").each do |input|
    puts "executing #{input}"
    FileUtils.cp(input, TEMP_INPUT_FILENAME)
    system("make execute")
    FileUtils.cp(TEMP_OUTPUT_FILENAME, "#{MY_OUTPUTS_DIRNAME}/#{File.basename(input)}")
  end
  FileUtils.rm([TEMP_INPUT_FILENAME, TEMP_OUTPUT_FILENAME])
end

#judgeObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/clicoder/cli.rb', line 75

def judge
  load_local_config
  accepted = true
  judge = Judge.new(options)
  Dir.glob("#{OUTPUTS_DIRNAME}/*.txt").each do |output|
    puts "judging #{output}"
    my_output =  "#{MY_OUTPUTS_DIRNAME}/#{File.basename(output)}"
    if File.exists?(my_output)
      unless judge.judge(output, my_output)
        puts '! Wrong Answer'
        system("diff -y #{output} #{my_output}")
        accepted = false
      end
    else
      puts "! #{my_output} does not exist"
      accepted = false
    end
  end
  if accepted
    puts "Correct Answer"
  else
    puts "Wrong Answer"
  end
end

#submitObject



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/clicoder/cli.rb', line 101

def submit
  load_local_config
  site = get_site
  if site.submit
    puts "Submission Succeeded."
    site.open_submission
  else
    puts "Submission Failed."
    exit 1
  end
end