-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter.rb
More file actions
49 lines (40 loc) · 1001 Bytes
/
writer.rb
File metadata and controls
49 lines (40 loc) · 1001 Bytes
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
class C_writer
@begin_file
@end_file
@code
@test_number
def initialize(number)
@begin_file = "#include <stdio.h>\nint main(){"
@end_file = "return 0;\n}"
@test_number = number
end
def set_code(code)
@code = code
end
def lock_n_load
write_in_file
run_file
write_in_txt
end
def write_in_file
File.open("test.c", "w") do |file|
file.write("#{@begin_file}\n#{@code}\n#{@end_file}")
end
end
def run_file
system("gcc test.c -w");
system("./a.out >> tests/test_#{@test_number}_results.txt");
end
def write_in_txt
data_file = "tests/test_#{@test_number}.txt"
File.open(File.expand_path(data_file), "a") do |file|
file << @code.split("printf")[0]
file << "\n\n"
end
end
def html_generate
c = Html.new(@test_number)
c.generate_html
c.generate_html_results
end
end