Class: Score
- Inherits:
-
Object
- Object
- Score
- Defined in:
- lib/prog_scorer/score.rb
Instance Method Summary collapse
- #compile(cmd, files, student_number) ⇒ Object
- #diff(code, output_path, student_number) ⇒ Object
-
#initialize(report_number, report_name) ⇒ Score
constructor
A new instance of Score.
- #test(student_number) ⇒ Object
- #write_file ⇒ Object
Constructor Details
#initialize(report_number, report_name) ⇒ Score
Returns a new instance of Score.
5 6 7 8 9 10 11 |
# File 'lib/prog_scorer/score.rb', line 5 def initialize(report_number, report_name) @s = "" @report_number = report_number @report_name = report_name @root_dir = "#{@report_number}/#{report_name}" @results_path = "#{@root_dir}/results.txt" end |
Instance Method Details
#compile(cmd, files, student_number) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prog_scorer/score.rb', line 23 def compile(cmd, files, student_number) code = "#{cmd}" for file in files do code += " #{file}" end if system(code) if Dir.glob("#{@root_dir}/testdata/*").count == 0 puts "#{student_number}: #{"success".colorize(:green)}" @s += "#{student_number}: !ok\n" else test(student_number) end else puts "#{student_number}: #{"compile error".colorize(:red)}" @s += "#{student_number}: !NG/compile error\n" end end |
#diff(code, output_path, student_number) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/prog_scorer/score.rb', line 55 def diff(code, output_path, student_number) if(system("#{code} > #{output_path}")) puts "#{student_number}: #{"success".colorize(:green)}" @s += "#{student_number}: !ok\n" else puts "#{student_number}: #{"diff error".colorize(:red)}" @s += "#{student_number}: !NG/diff error\n" end end |
#test(student_number) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/prog_scorer/score.rb', line 41 def test(student_number) Dir.glob("#{@root_dir}/testdata/*") do |input_dir| basename = input_dir.match(/\w+\z/)[0] output_path = "#{@root_dir}/outputs/#{student_number}/#{basename}.txt" mkdir("#{@root_dir}/outputs/#{student_number}") mkdir("#{@root_dir}/diff/#{student_number}") system("./a.out < #{input_dir}/in.txt > #{output_path}") diff_cmd = "diff -Bw #{@root_dir}/outputs/#{student_number}/#{basename}.txt #{input_dir}/exp.txt " diff(diff_cmd, "#{@root_dir}/diff/#{student_number}/#{basename}.txt", student_number) end end |
#write_file ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/prog_scorer/score.rb', line 13 def write_file() File.open(@results_path, mode = "w"){|f| f.write(@s) # ファイルに書き込む } if(!File.exist?("a.out")) system("rm a.out") end end |