forked from Catishere/software_engineering_2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_ouput_check.rb
83 lines (63 loc) · 1.95 KB
/
input_ouput_check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Run on a foler as
# ruby input_output_check.rb folder_to_check input_to_pass output_to_expect folder_with_implementation
#where
# - folder_to_check - the folder where the files to check are
# - input_to_pass - is the input to be passed to the programs
# - output_to_expect - is the output expected by the programs
# - folder_with_implementation - is true/false if an additional folder with program files should be included
require 'csv'
def student_checked? checked_files, first_name, last_name
checked_files.include? [first_name,last_name]
end
def solved? expected, result
result.gsub(/\s+/, "") == expected ? 1: 0
end
def get_names filename
filename.split("/").last.split("_")
end
def valid_names? names
names.size == 4
end
def remove_file_ext value
value.split(".").first
end
def print_result result, solved
p "The result is"
p result
p "Solved is:"
p solved
end
checked_files = []
script_input = ARGV[1]
script_output = ARGV[2]
include_folder = ARGV[3]
CSV.open("result.csv", "w") do |csv_array|
previous_number = 0
files = Dir.glob(ARGV[0] + '*.rb').select { |f| File.file? f }
files.each do |filename|
name = get_names filename
if valid_names? name
last_name = remove_file_ext name[3]
first_name = name[2]
number = name[1]
clazz = name[0]
if !student_checked? checked_files,first_name,last_name
p "#{clazz},#{number},#{first_name},#{last_name}"
include_folder_string = "-I #{clazz}_#{number}_#{first_name}_#{last_name}/" if include_folder
result= `ruby #{include_folder_string} #{filename} #{script_input}`
solved = solved? script_output, result
print_result result,solved
csv_array << [clazz,number,first_name,last_name,solved]
checked_files << [first_name, last_name]
end
end
end
end
def sort_result
my_csv = CSV.read 'result.csv'
my_csv.sort! { |a,b| [a[0],a[1].to_i] <=> [b[0],b[1].to_i] }
CSV.open("result.csv", "w") do |csv|
my_csv.each {|element| csv << element}
end
end
sort_result