Class: Clicoder::CLI

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

Instance Method Summary collapse

Instance Method Details

#add_testObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/clicoder/cli.rb', line 107

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



42
43
44
45
46
# File 'lib/clicoder/cli.rb', line 42

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

#browseObject



131
132
133
134
135
# File 'lib/clicoder/cli.rb', line 131

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

#buildObject



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

def build
  load_local_config
  system('make build')
end

#downloadObject



119
120
121
122
123
124
125
126
127
128
# File 'lib/clicoder/cli.rb', line 119

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



55
56
57
58
59
60
61
62
63
64
# File 'lib/clicoder/cli.rb', line 55

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/clicoder/cli.rb', line 68

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



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/clicoder/cli.rb', line 94

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