coderunner 0.12.7 → 0.12.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/coderunner.gemspec +4 -2
- data/lib/coderunner.rb +1 -1
- data/lib/coderunner/class_methods.rb +1 -1
- data/lib/coderunner/instance_methods.rb +27 -5
- data/lib/coderunner/run.rb +24 -8
- data/lib/coderunner/system_modules/generic_linux.rb +3 -1
- data/lib/coderunner/version.rb +4 -0
- data/lib/cubecalccrmod.rb +1 -106
- data/lib/cubecalccrmod/cubecalc.rb +108 -0
- data/lib/cubecalccrmod/{cubecalc_defaults.rb → defaults_files/cubecalc_defaults.rb} +0 -0
- data/test/old_test.rb +472 -0
- data/test/test_coderunner.rb +269 -423
- metadata +4 -2
data/test/test_coderunner.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
|
2
|
+
require 'helper'
|
3
|
+
require 'rbconfig'
|
4
|
+
|
5
|
+
|
3
6
|
|
4
7
|
module Test::Unit::Assertions
|
5
8
|
def assert_system(string)
|
@@ -7,466 +10,309 @@ module Test::Unit::Assertions
|
|
7
10
|
end
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
ppipe = PPipe.new(10, false, redirect: true)
|
13
|
+
unless $cpp_command = ENV['CPP']
|
14
|
+
raise "Please specify the environment variable CPP (the C++ compiler)"
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
$ruby_command = "#{RbConfig::CONFIG['bindir']}/#{RbConfig::CONFIG['ruby_install_name']}"
|
16
18
|
|
17
|
-
#
|
19
|
+
#Dir.chdir('test') do
|
20
|
+
#raise "Couldn't build test program using #{string}" unless system string
|
21
|
+
#end
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
class TestSubmission < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
string = $cpp_command + ' ../cubecalc.cc -o cubecalc'
|
26
|
+
FileUtils.makedirs('test/submission_results')
|
27
|
+
Dir.chdir('test/submission_results'){assert_system string}
|
22
28
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
#exit
|
40
|
-
|
41
|
-
|
42
|
-
puts 'testing canceling a job (not deleting)'
|
43
|
-
fork{system %[ruby ../../coderunner.rb sub -p "{sleep_time: 900}"]}
|
44
|
-
sleep 3
|
45
|
-
fork{system %[ruby ../../coderunner.rb sub -p "{sleep_time: 900, height: 3.0}"]}
|
46
|
-
sleep 4
|
47
|
-
runner = CodeRunner.new(Dir.pwd).update
|
48
|
-
runner.print_out(0)
|
49
|
-
runner.print_out_size = 0
|
50
|
-
runner.cancel_job(2, no_confirm: true, delete: false)
|
51
|
-
#pipe = ppipe.fork do
|
52
|
-
#runner.cancel_job(2)
|
53
|
-
#end
|
54
|
-
##3.times{puts ppipe.gets}
|
55
|
-
#2.times{ppipe.puts(pipe, "")}
|
56
|
-
#puts 'confirming...'
|
57
|
-
## sleep 0.5
|
58
|
-
##2.times{puts ppipe.gets}
|
59
|
-
#puts 'about to say no'
|
60
|
-
#ppipe.puts(pipe, "n")
|
61
|
-
## 9.times{puts ppipe.gets}
|
62
|
-
|
63
|
-
#exit
|
64
|
-
|
65
|
-
puts 'testing cancelling with deleting'
|
66
|
-
|
67
|
-
runner.update
|
68
|
-
runner.print_out(0)
|
69
|
-
runner.print_out_size = 0
|
70
|
-
runner.cancel_job(3, no_confirm: true, delete: true)
|
71
|
-
#pipe = ppipe.fork do
|
72
|
-
#runner.cancel_job(3)
|
73
|
-
#end
|
74
|
-
## 2.times{puts ppipe.gets}
|
75
|
-
#puts 'confirming...'
|
76
|
-
#ppipe.puts(pipe, "")
|
77
|
-
## ppipe.puts(pipe, "\n")
|
78
|
-
## sleep 0.5
|
79
|
-
## 2.times{puts ppipe.gets}
|
80
|
-
#puts 'about to say yes'
|
81
|
-
#ppipe.puts(pipe, "y")
|
82
|
-
## 8.times{puts ppipe.gets}
|
83
|
-
|
84
|
-
puts 'testing canceling complete'
|
85
|
-
|
86
|
-
#exit
|
87
|
-
|
88
|
-
# exit
|
89
|
-
|
90
|
-
puts
|
91
|
-
puts 'testing parameter scan'
|
92
|
-
File.open('parameter_scan.rb', 'w') do |file|
|
93
|
-
file.puts [
|
94
|
-
[
|
95
|
-
['width', [0.3, 0.5]], ['height', [0.5, 4.3]]
|
96
|
-
],
|
97
|
-
[
|
98
|
-
['width', [7.2]], ['height', [3.6, 12.6]]
|
99
|
-
]
|
100
|
-
].inspect
|
29
|
+
def test_submission
|
30
|
+
CodeRunner.submit(Y: 'test/submission_results', C: 'cubecalc', m: 'empty', X: Dir.pwd + '/test/submission_results/cubecalc')
|
31
|
+
CodeRunner.status(Y: 'test/submission_results')
|
32
|
+
assert(FileTest.exist?('test/submission_results/v'))
|
33
|
+
assert(FileTest.exist?('test/submission_results/v/id_1'))
|
34
|
+
assert(FileTest.exist?('test/submission_results/cubecalc_defaults.rb'))
|
35
|
+
end
|
36
|
+
def test_status_loop
|
37
|
+
unless ENV['SHORT_TEST']
|
38
|
+
ENV['CODE_RUNNER_LAUNCHER'] = '4'
|
39
|
+
@thread = Thread.new{CodeRunner.start_launcher(0.2,10)}
|
40
|
+
CodeRunner.submit(Y: 'test/submission_results', C: 'cubecalc', m: 'sleep', X: Dir.pwd + '/test/submission_results/cubecalc', p: '{sleep_time: 2}')
|
41
|
+
CodeRunner.status_loop(Y: 'test/submission_results')
|
42
|
+
@thread.kill
|
43
|
+
ENV.delete('CODE_RUNNER_LAUNCHER')
|
101
44
|
end
|
102
|
-
|
103
|
-
|
45
|
+
end
|
46
|
+
def testanalysis
|
47
|
+
CodeRunner.submit(Y: 'test/submission_results', C: 'cubecalc', m: 'empty', X: Dir.pwd + '/test/submission_results/cubecalc', p: '{width: 2.0, height: 3.0}')
|
48
|
+
runner = CodeRunner.fetch_runner(Y: 'test/submission_results')
|
49
|
+
#system "ps"
|
104
50
|
runner.update
|
105
51
|
runner.print_out(0)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# exit
|
110
|
-
#
|
52
|
+
assert_equal(6.0, runner.run_list[1].volume)
|
111
53
|
end
|
54
|
+
#def test_command_line_submission
|
55
|
+
#assert_system("#{$ruby_command} -I lib/ lib/coderunner.rb submit -C cubecalc -m sleep -D sleep -X #{Dir.pwd}/test/cubecalc -Y test/submission_results")
|
56
|
+
#end
|
57
|
+
def teardown
|
58
|
+
FileUtils.rm_r('test/submission_results')
|
59
|
+
end
|
60
|
+
end
|
112
61
|
|
113
|
-
end # if ARGV[0] == 's'
|
114
62
|
|
115
|
-
|
63
|
+
class TestCodeRunner < Test::Unit::TestCase
|
116
64
|
|
117
|
-
|
118
|
-
|
119
|
-
if ARGV[-1] =~ /1/
|
120
|
-
FileUtils.rm_r 'results' if FileTest.exist? 'results'
|
121
|
-
FileUtils.makedirs 'results'
|
122
|
-
|
123
|
-
# CodeRunner::SYS = ENV['CODE_RUNNER_SYSTEM'] = 'genericlinux_testsystem' if CodeRunner::SYS == 'genericlinux'
|
124
|
-
|
125
|
-
Dir.chdir('results') do
|
126
|
-
|
127
|
-
|
128
|
-
exit unless system %[ruby ../../coderunner.rb submit -C cubecalc -m empty -X ../cubecalc -T]
|
65
|
+
# Override this method as we want the tests to be run in the order they are defined
|
129
66
|
|
130
|
-
|
131
|
-
|
67
|
+
#def self.test_methods
|
68
|
+
#public_instance_methods(true).grep(/^test/).map { |m| m.to_s}
|
69
|
+
#end
|
132
70
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
# exit
|
71
|
+
def setup
|
72
|
+
FileUtils.makedirs('test/results')
|
73
|
+
string = $cpp_command + ' ../cubecalc.cc -o cubecalc'
|
74
|
+
Dir.chdir('test/results'){assert_system string}
|
75
|
+
CodeRunner.submit(Y: tfolder, C: 'cubecalc', m: 'empty', X: Dir.pwd + '/test/results/cubecalc', T: true)
|
76
|
+
# exit
|
77
|
+
defs = File.read('test/results/cubecalc_defaults.rb')
|
78
|
+
File.open('test/results/cubecalc_defaults.rb', 'w'){|f| f.puts defs.sub(/\#(@calculate_sides\s+=\s+)0/, '\11')}
|
79
|
+
CodeRunner.submit(Y: Dir.pwd + '/test/results', p: ["{width: 3.0, height: 8.0}", "{width: 3.0, height: 6.0}", "{width: 3.0, height: 9.0}", "{width: 12.0, height: 9.0}", "{width: 5.0, height: 6.0}", "{width: 11.0, height: 9.0, depth: 2.0}"])
|
80
|
+
@runner = CodeRunner.fetch_runner(Y: Dir.pwd + '/test/results').update
|
81
|
+
end
|
139
82
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
ENV['ROWS'] = Terminal.terminal_size[0].to_s
|
144
|
-
ENV['COLS'] = Terminal.terminal_size[1].to_s
|
145
|
-
puts ENV['ROWS'], ENV['COLS']
|
146
|
-
exit unless system %[ruby ../../coderunner.rb st -N]
|
147
|
-
runner = CodeRunner.new(Dir.pwd).update
|
148
|
-
runner.print_out(0)
|
149
|
-
puts 'testing printing out status complete'
|
83
|
+
def teardown
|
84
|
+
FileUtils.rm_r('test/results')
|
85
|
+
end
|
150
86
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
puts 'using large cache after updating'
|
158
|
-
runner.update
|
159
|
-
runner.use_large_cache = true
|
160
|
-
runner.update.print_out(0)
|
161
|
-
puts 'testing using large cache complete'
|
162
|
-
|
163
|
-
puts 'testing sorting'
|
164
|
-
%x[ruby ../../coderunner.rb sub -p "{width: 12.0, height: 9.0}"]
|
165
|
-
%x[ruby ../../coderunner.rb sub -p "{width: 5.0, height: 6.0}"]
|
166
|
-
puts '----', 'unsorted'
|
167
|
-
exit unless system %[ruby ../../coderunner.rb st -N]
|
168
|
-
puts '----', 'sort by volume'
|
169
|
-
exit unless system %[ruby ../../coderunner.rb st -O "volume" -N]
|
170
|
-
puts '----','sort by width then by height'
|
171
|
-
exit unless system %[ruby ../../coderunner.rb st -O "width;height" -N]
|
172
|
-
puts 'testing sorting complete'
|
173
|
-
|
174
|
-
puts 'testing getting directory'
|
175
|
-
exit unless system %[ruby ../../coderunner.rb dir 3 -UN ]
|
176
|
-
puts 'testing getting directory complete'
|
87
|
+
def tfolder
|
88
|
+
Dir.pwd + '/test/results'
|
89
|
+
end
|
90
|
+
def tfolder2
|
91
|
+
Dir.pwd + '/test/results2'
|
92
|
+
end
|
177
93
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
94
|
+
#def cl(command)
|
95
|
+
#Dir.chdir('results'){assert_system command}
|
96
|
+
#end
|
97
|
+
|
98
|
+
#def cl2(command)
|
99
|
+
#Dir.chdir('results3'){assert_system command}
|
100
|
+
#end
|
184
101
|
|
185
|
-
# exit
|
186
|
-
|
187
|
-
puts 'testing phantom runs'
|
188
|
-
exit unless system %[ruby ../../coderunner.rb st -UN -h -O "volume;area"]
|
189
|
-
puts 'testing using both'
|
190
|
-
exit unless system %[ruby ../../coderunner.rb st -UN -h both -O "volume;id"]
|
191
|
-
puts 'testing phantom runs complete'
|
192
102
|
|
193
|
-
|
194
|
-
|
195
|
-
|
103
|
+
#def cl3(command)
|
104
|
+
#Dir.chdir('results3'){assert_system command}
|
105
|
+
#end
|
106
|
+
|
196
107
|
|
197
|
-
|
198
|
-
|
199
|
-
|
108
|
+
def test_remote_coderunner
|
109
|
+
puts 'testing remote coderunner'
|
110
|
+
rc = RemoteCodeRunner.new(ENV['USER'] + '@localhost', Dir.pwd + '/test/results', U: true, N: true).update
|
111
|
+
assert_equal(@runner.ids.sort, rc.ids.sort)
|
112
|
+
rc.print_out(0)
|
113
|
+
wdvh = rc.graphkit("width:height:depth:volume;;;height")
|
114
|
+
#wdvh.gnuplot
|
115
|
+
assert_equal(4, wdvh.naxes)
|
116
|
+
assert_equal(1, wdvh.data.size)
|
117
|
+
assert_equal([30.0, 18.0, 24.0, 108.0, 27.0, 198.0], wdvh.data[0].axes[:f].data)
|
118
|
+
sds = rc.run_graphkit('sides;;[1,2].include? id')
|
119
|
+
# sds.gnuplot
|
120
|
+
wdvh.close
|
121
|
+
puts 'testing remote coderunner complete'
|
122
|
+
end
|
200
123
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
124
|
+
def test_run_eval_saving
|
125
|
+
puts "\nTesting run command saving"
|
126
|
+
CodeRunner.run_command('@test_var = :will_o_the_wisp', Y: tfolder)
|
127
|
+
@runner.update(false, true)
|
128
|
+
assert_equal(:will_o_the_wisp, @runner.run_list[1].instance_variable_get(:@test_var))
|
129
|
+
CodeRunner.run_command('@test_var2 = :will_o_the_wisps', Y: tfolder)
|
130
|
+
|
131
|
+
@runner.update(false, true)
|
132
|
+
assert_equal(:will_o_the_wisps, @runner.run_list[1].instance_variable_get(:@test_var2))
|
133
|
+
puts 'finished testing run command saving'
|
134
|
+
end
|
212
135
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
136
|
+
def test_relative_directory
|
137
|
+
puts "\nTesting relative directory"
|
138
|
+
@runner.recalc_all = true
|
139
|
+
puts 'updating fully'
|
140
|
+
@runner.update #(true, false)
|
141
|
+
FileUtils.rm_r(tfolder2) if FileTest.exist? tfolder2
|
142
|
+
FileUtils.cp_r(tfolder, tfolder2)
|
143
|
+
r = CodeRunner.fetch_runner(Y: tfolder2, U: true)
|
144
|
+
r.update(false)
|
145
|
+
assert_equal(tfolder, @runner.root_folder)
|
146
|
+
assert_equal(tfolder2, r.root_folder)
|
147
|
+
assert_equal(@runner.run_list[1].directory.sub(File.expand_path(@runner.root_folder) + '/', ''), r.run_list[1].relative_directory)
|
148
|
+
assert_equal(r.root_folder + '/' + r.run_list[1].relative_directory, r.run_list[1].directory)
|
149
|
+
FileUtils.rm_r tfolder2
|
150
|
+
end
|
217
151
|
|
152
|
+
def test_set_start_id_and_merged_code_runner
|
153
|
+
eputs "\ntesting set_start_id"
|
154
|
+
FileUtils.rm_r tfolder2 if FileTest.exist?(tfolder2)
|
155
|
+
FileUtils.mkdir(tfolder2)
|
156
|
+
#cl3('ruby ../../coderunner.rb st -C cubecalc -m empty -X ../cubecalc -T')
|
157
|
+
#cl3("ruby ../../coderunner.rb ev 'set_start_id(20)'")
|
158
|
+
#cl3('ruby ../../coderunner.rb sub -p "{width: 12.0, height: 9.0}"')
|
159
|
+
CodeRunner.status(Y: tfolder2, C: 'cubecalc', m: 'empty', X: tfolder + '/cubecalc')
|
160
|
+
CodeRunner.runner_eval('set_start_id(20)', Y: tfolder2)
|
161
|
+
CodeRunner.submit(Y: tfolder2, p: "{width: 12.0, height: 9.0}")
|
162
|
+
@runner3 = CodeRunner.new(tfolder2).update
|
163
|
+
assert_equal(20, @runner3.start_id)
|
164
|
+
assert_equal(21, @runner3.max_id)
|
165
|
+
#eputs "\ntesting set_start_id complete"
|
166
|
+
@runner3 = CodeRunner.new(tfolder2).update
|
167
|
+
assert_nothing_raised{@mrunner = CodeRunner::Merged.new(@runner, @runner3)}
|
168
|
+
@mrunner.print_out(0)
|
169
|
+
assert_equal(@runner.run_list.size + 1, @mrunner.run_list.size)
|
170
|
+
@mrunner2 = @runner.merge(@runner3)
|
171
|
+
assert_equal(@mrunner2.run_list.keys, @mrunner.run_list.keys)
|
172
|
+
FileUtils.rm_r tfolder2
|
173
|
+
end
|
218
174
|
|
175
|
+
def test_alter_ids
|
176
|
+
FileUtils.rm_r tfolder2 if FileTest.exist?(tfolder2)
|
177
|
+
#FileUtils.mkdir(tfolder2)
|
178
|
+
FileUtils.cp_r(tfolder, tfolder2)
|
179
|
+
@runner4 = CodeRunner.new(tfolder2).update
|
180
|
+
@runner4.alter_ids(40, no_confirm: true)
|
181
|
+
@runner4a = CodeRunner.new(tfolder2).update
|
182
|
+
assert_equal(@runner.ids.map{|id| id + 40}.sort, @runner4.ids.sort)
|
183
|
+
assert_equal(@runner4a.ids.sort, @runner4.ids.sort)
|
184
|
+
@runner4.alter_ids(40, no_confirm: true)
|
185
|
+
@runner4a.update
|
186
|
+
assert_equal(@runner.ids.map{|id| id + 80}.sort, @runner4.ids.sort)
|
187
|
+
assert_equal(@runner4a.ids.sort, @runner4.ids.sort)
|
188
|
+
run = @runner4.run_list.values[0]
|
189
|
+
assert(FileTest.exist?(run.directory), "Run directory exists")
|
190
|
+
ep run.id, 'id'
|
191
|
+
#exit
|
192
|
+
assert_equal(run.id, eval(File.read(run.directory + '/code_runner_info.rb'))[:id])
|
193
|
+
FileUtils.rm_r tfolder2
|
194
|
+
end
|
219
195
|
|
220
|
-
|
196
|
+
#def test_submit_non_parallel_with_large_cache
|
197
|
+
#FileUtils.touch('results/submitting')
|
198
|
+
## fork{cl('ruby ../../coderunner.rb sub -p "{width: 1.887, height: 9.0}"')}
|
199
|
+
#fork{CodeRunner.submit(Y: 'results', p: "{width: 1.887, height: 9.0}", U: true)}
|
200
|
+
#sleep 1.0
|
201
|
+
#@runner.update(true, false)
|
202
|
+
#assert_equal(0, @runner.run_list.values.find_all{|run| run.width==1.887}.size)
|
203
|
+
#FileUtils.rm('results/submitting')
|
204
|
+
#i = 0
|
205
|
+
#Process.waitall
|
206
|
+
## (@runner.update(true, true); sleep 0.5; i+=1 ; flunk if i==20) until @runner.run_list.values.find{|run| run.width==1.887}
|
207
|
+
#@runner.update(true, true)
|
208
|
+
#assert_equal(1, @runner.run_list.values.find_all{|run| run.width==1.887}.size)
|
209
|
+
#@runner.conditions = "id==7"
|
210
|
+
#@runner.destroy(no_confirm: true)
|
211
|
+
#assert_equal(0, @runner.run_list.values.find_all{|run| run.width==1.887}.size)
|
212
|
+
#assert_raise(RuntimeError){CodeRunner.submit(Y: 'results', p: "{run_test_flags: {test_submit_error_handling: true}}", U: true)}
|
213
|
+
#assert(!FileTest.exist?('results/submitting'))
|
214
|
+
#end
|
221
215
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
#
|
226
|
-
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
216
|
+
#def test_latex_graphkit
|
217
|
+
#Dir.chdir('test/results') do
|
218
|
+
##@runner.print_out(0)
|
219
|
+
#sds = @runner.run_graphkit('sides;;[1,2].include? id')
|
220
|
+
##p sds
|
221
|
+
#sds.ylabel = 'Hello'
|
222
|
+
#sds.data.each_with_index{|dk,i| dk.title = i.to_s}
|
223
|
+
#sds.xlabel = '\(\Gamma_{\epsilon}\)'
|
224
|
+
#sds.title = 'Area of the Sides'
|
225
|
+
##sds.gnuplot
|
226
|
+
##pp sds
|
227
|
+
##pid1 = sds.gnuplot
|
228
|
+
|
229
|
+
#sds.gnuplot_write('latgraph.eps', latex: true)
|
230
|
+
##pid = system "okular #{Dir.pwd}/latgraph.eps"
|
231
|
+
##sleep 3
|
232
|
+
##Process.kill 'TERM', pid
|
233
|
+
##Process.kill 'TERM', pid1
|
234
|
+
#end
|
235
|
+
#end
|
242
236
|
|
243
|
-
|
244
|
-
#
|
245
|
-
defs = File.read('results/cubecalc_defaults.rb')
|
246
|
-
File.open('results/cubecalc_defaults.rb', 'w'){|f| f.puts defs.sub(/\#(@calculate_sides\s+=\s+)0/, '\11')}
|
247
|
-
CodeRunner.submit(Y: Dir.pwd + '/results', p: "{width: 3.0, height: 8.0}")
|
248
|
-
CodeRunner.submit(Y: Dir.pwd + '/results', p: "{width: 3.0, height: 6.0}")
|
249
|
-
CodeRunner.submit(Y: Dir.pwd + '/results', p: "{width: 3.0, height: 9.0}")
|
250
|
-
CodeRunner.submit(Y: Dir.pwd + '/results', p: "{width: 12.0, height: 9.0}")
|
251
|
-
CodeRunner.submit(Y: Dir.pwd + '/results', p: "{width: 5.0, height: 6.0}")
|
252
|
-
CodeRunner.submit(Y: Dir.pwd + '/results', p: "{width: 11.0, height: 9.0, depth: 2.0}")
|
253
|
-
|
254
|
-
class TestCodeRunner < Test::Unit::TestCase
|
237
|
+
#def test_graphkit_multiplot
|
238
|
+
#Dir.chdir('test/results') do
|
255
239
|
|
256
|
-
|
240
|
+
#######################
|
241
|
+
## Make 3 random graphs
|
242
|
+
#######################
|
257
243
|
|
258
|
-
def self.test_methods
|
259
|
-
public_instance_methods(true).grep(/^test/).map { |m| m.to_s}
|
260
|
-
end
|
261
244
|
|
262
|
-
|
263
|
-
|
264
|
-
|
245
|
+
## As usual, data can be an array or a GSL::Vector
|
246
|
+
#kit1 = GraphKit.autocreate(x: {data: [0,2,4], title: 'A label with latex \(\Gamma_\epsilon \chi\)', units: '\(\nu e\)'}, y: {data: [3.3, 5.5, 10], title: 'Label with latex \(\beta\)', units: '\(v_{thi}\)'})
|
247
|
+
#kit1.title = 'First Graph'
|
248
|
+
#kit1.gp.label = '\'A label\' at 2,7' # This 'gp' syntax is new. You can set pretty much any gnuplot option like this - see gnuplot help set
|
249
|
+
#kit1.data[0].title = 'A new title'
|
265
250
|
|
266
|
-
|
267
|
-
|
251
|
+
#kit2 = GraphKit.autocreate(x: {data: [0,2,4], title: 'Stuff \(\Gamma_\epsilon \chi\)', units: '\(\nu e\)'}, y: {data: [2, -1, 2], title: 'Some \(\beta\)', units: '\(v_{thi}\)'})
|
252
|
+
#kit2.title = 'Second Graph'
|
253
|
+
#kit2.data[0].gp.with = 'lp linewidth 6' # See gnuplot help plot for data options
|
254
|
+
#kit2.gp.key = 'off'
|
255
|
+
#kit2.xlabel = 'A NEW XLABEL'
|
268
256
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
def cl2(command)
|
274
|
-
Dir.chdir('results3'){assert_system command}
|
275
|
-
end
|
276
|
-
|
257
|
+
#kit3 = GraphKit.autocreate(x: {data: [0,5,10], title: 'Mouse Height \(\Gamma_\epsilon \chi\)', units: '\(\nu e\)'}, y: {data: [4, 3, 4], title: 'Mouse weight \(\kappa\)', units: '\(v_{thi}\)'})
|
258
|
+
#kit3.title = 'Mouse info'
|
259
|
+
#kit3.data[0].gp.with = 'lp'
|
260
|
+
#kit3.gp.key = 'off'
|
277
261
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
262
|
+
######################
|
263
|
+
## Plot a single one
|
264
|
+
######################
|
282
265
|
|
283
|
-
#
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
#rc.print_out(0)
|
288
|
-
#wdvh = rc.graphkit("width:height:depth:volume;;;height")
|
289
|
-
#wdvh.gnuplot
|
290
|
-
#assert_equal(4, wdvh.naxes)
|
291
|
-
#assert_equal(1, wdvh.data.size)
|
292
|
-
#assert_equal([30.0, 18.0, 24.0, 108.0, 27.0, 198.0], wdvh.data[0].axes[:f].data)
|
293
|
-
#sds = rc.run_graphkit('sides;;[1,2].include? id')
|
294
|
-
## sds.gnuplot
|
295
|
-
#wdvh.close
|
296
|
-
#puts 'testing remote coderunner complete'
|
297
|
-
#end
|
266
|
+
#pp kit1
|
267
|
+
#kit1.gnuplot_write('first_graph.eps', latex: true) #Just plot it by itself
|
268
|
+
##system "okular #{Dir.pwd}/first_graph.eps"
|
269
|
+
#pp kit1
|
298
270
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
#puts 'finished testing run command saving'
|
309
|
-
#end
|
271
|
+
############################
|
272
|
+
## Plot multiple graphs
|
273
|
+
###########################
|
274
|
+
|
275
|
+
##$debug_gnuplot=true
|
276
|
+
#kit1.gnuplot_write('aname.eps', latex: true)
|
277
|
+
##exit
|
278
|
+
#kit2.gnuplot_write('anothername.eps', latex: true)
|
279
|
+
#kit3.gnuplot_write('athirdname.eps', latex: true, size: "2.0in,2.0in")
|
310
280
|
|
311
|
-
#
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
#assert_equal(Dir.pwd + '/results', @runner.root_folder)
|
321
|
-
#assert_equal(Dir.pwd + '/results2', r.root_folder)
|
322
|
-
#assert_equal(@runner.run_list[1].directory.sub(File.expand_path(@runner.root_folder) + '/', ''), r.run_list[1].relative_directory)
|
323
|
-
#assert_equal(r.root_folder + '/' + r.run_list[1].relative_directory, r.run_list[1].directory)
|
324
|
-
#end
|
281
|
+
#my_preamble = <<EOF
|
282
|
+
#\\documentclass{article}
|
283
|
+
#%\documentclass[aip,reprint]{}
|
284
|
+
#\\usepackage{graphics,bm,overpic,subfigure,color}
|
285
|
+
|
286
|
+
#\\pagestyle{empty}
|
287
|
+
#\\begin{document}
|
288
|
+
#\\begin{figure}
|
289
|
+
#EOF
|
325
290
|
|
326
|
-
#def test_set_start_id
|
327
|
-
#eputs "\ntesting set_start_id"
|
328
|
-
#FileUtils.rm_r 'results3' if FileTest.exist?('results3')
|
329
|
-
#FileUtils.mkdir('results3')
|
330
|
-
#cl3('ruby ../../coderunner.rb st -C cubecalc -m empty -X ../cubecalc -T')
|
331
|
-
#cl3("ruby ../../coderunner.rb ev 'set_start_id(20)'")
|
332
|
-
#cl3('ruby ../../coderunner.rb sub -p "{width: 12.0, height: 9.0}"')
|
333
|
-
#@runner3 = CodeRunner.new(Dir.pwd + '/results3').update
|
334
|
-
#assert_equal(20, @runner3.start_id)
|
335
|
-
#assert_equal(21, @runner3.max_id)
|
336
|
-
#eputs "\ntesting set_start_id complete"
|
337
|
-
#end
|
338
|
-
|
339
|
-
#def test_merged_code_runner
|
340
|
-
#@runner3 = CodeRunner.new(Dir.pwd + '/results3').update
|
341
|
-
#assert_nothing_raised{@mrunner = CodeRunner::Merged.new(@runner, @runner3)}
|
342
|
-
#@mrunner.print_out(0)
|
343
|
-
#assert_equal(@runner.run_list.size + 1, @mrunner.run_list.size)
|
344
|
-
#@mrunner2 = @runner.merge(@runner3)
|
345
|
-
#assert_equal(@mrunner2.run_list.keys, @mrunner.run_list.keys)
|
346
|
-
#end
|
347
291
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
#
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
292
|
+
## Can use default preamble - just don't include preamble option in function call GraphKit.latex_multiplot('all_graphs.eps')
|
293
|
+
#GraphKit.latex_multiplot('all_graphs.eps', preamble: my_preamble) do
|
294
|
+
#<<EOF
|
295
|
+
#\\subfigure{
|
296
|
+
#\\includegraphics{aname}
|
297
|
+
#}
|
298
|
+
#\\subfigure{
|
299
|
+
#\\begin{overpic}{anothername}
|
300
|
+
#% The location is in percent of image width
|
301
|
+
#\\put(44,22){\\includegraphics[scale=.45]
|
302
|
+
#{athirdname}}
|
303
|
+
#\\end{overpic}
|
304
|
+
#}
|
305
|
+
#EOF
|
306
|
+
|
363
307
|
#end
|
308
|
+
##system "okular #{Dir.pwd}/all_graphs.eps"
|
309
|
+
#assert_equal("all_graphs.eps: PostScript document text conforming DSC level 2.0, type EPS\n", `file all_graphs.eps`)
|
310
|
+
|
311
|
+
#end # Dir.chdir
|
312
|
+
|
364
313
|
|
365
|
-
#def test_submit_non_parallel_with_large_cache
|
366
|
-
#FileUtils.touch('results/submitting')
|
367
|
-
## fork{cl('ruby ../../coderunner.rb sub -p "{width: 1.887, height: 9.0}"')}
|
368
|
-
#fork{CodeRunner.submit(Y: 'results', p: "{width: 1.887, height: 9.0}", U: true)}
|
369
|
-
#sleep 1.0
|
370
|
-
#@runner.update(true, false)
|
371
|
-
#assert_equal(0, @runner.run_list.values.find_all{|run| run.width==1.887}.size)
|
372
|
-
#FileUtils.rm('results/submitting')
|
373
|
-
#i = 0
|
374
|
-
#Process.waitall
|
375
|
-
## (@runner.update(true, true); sleep 0.5; i+=1 ; flunk if i==20) until @runner.run_list.values.find{|run| run.width==1.887}
|
376
|
-
#@runner.update(true, true)
|
377
|
-
#assert_equal(1, @runner.run_list.values.find_all{|run| run.width==1.887}.size)
|
378
|
-
#@runner.conditions = "id==7"
|
379
|
-
#@runner.destroy(no_confirm: true)
|
380
|
-
#assert_equal(0, @runner.run_list.values.find_all{|run| run.width==1.887}.size)
|
381
|
-
#assert_raise(RuntimeError){CodeRunner.submit(Y: 'results', p: "{run_test_flags: {test_submit_error_handling: true}}", U: true)}
|
382
|
-
#assert(!FileTest.exist?('results/submitting'))
|
383
|
-
#end
|
384
314
|
|
385
|
-
|
386
|
-
sds = @runner.run_graphkit('sides;;[1,2].include? id')
|
387
|
-
p sds
|
388
|
-
sds.ylabel = 'Hello'
|
389
|
-
sds.data.each_with_index{|dk,i| dk.title = i.to_s}
|
390
|
-
sds.xlabel = '\(\Gamma_{\epsilon}\)'
|
391
|
-
sds.title = 'Area of the Sides'
|
392
|
-
#pid1 = sds.gnuplot
|
393
|
-
|
394
|
-
sds.gnuplot_write('latgraph.eps', latex: true)
|
395
|
-
#pid = forkex "okular latgraph.eps"
|
396
|
-
sleep 3
|
397
|
-
#Process.kill 'TERM', pid
|
398
|
-
#Process.kill 'TERM', pid1
|
399
|
-
end
|
315
|
+
#end # def
|
400
316
|
|
401
|
-
|
402
|
-
|
403
|
-
######################
|
404
|
-
# Make 3 random graphs
|
405
|
-
######################
|
406
|
-
|
407
|
-
|
408
|
-
# As usual, data can be an array or a GSL::Vector
|
409
|
-
kit1 = GraphKit.autocreate(x: {data: [0,2,4], title: 'A label with latex \(\Gamma_\epsilon \chi\)', units: '\(\nu e\)'}, y: {data: [3.3, 5.5, 10], title: 'Label with latex \(\beta\)', units: '\(v_{thi}\)'})
|
410
|
-
kit1.title = 'First Graph'
|
411
|
-
kit1.gp.label = '\'A label\' at 2,7' # This 'gp' syntax is new. You can set pretty much any gnuplot option like this - see gnuplot help set
|
412
|
-
kit1.data[0].title = 'A new title'
|
413
|
-
|
414
|
-
kit2 = GraphKit.autocreate(x: {data: [0,2,4], title: 'Stuff \(\Gamma_\epsilon \chi\)', units: '\(\nu e\)'}, y: {data: [2, -1, 2], title: 'Some \(\beta\)', units: '\(v_{thi}\)'})
|
415
|
-
kit2.title = 'Second Graph'
|
416
|
-
kit2.data[0].gp.with = 'lp linewidth 6' # See gnuplot help plot for data options
|
417
|
-
kit2.gp.key = 'off'
|
418
|
-
kit2.xlabel = 'A NEW XLABEL'
|
419
|
-
|
420
|
-
kit3 = GraphKit.autocreate(x: {data: [0,5,10], title: 'Mouse Height \(\Gamma_\epsilon \chi\)', units: '\(\nu e\)'}, y: {data: [4, 3, 4], title: 'Mouse weight \(\kappa\)', units: '\(v_{thi}\)'})
|
421
|
-
kit3.title = 'Mouse info'
|
422
|
-
kit3.data[0].gp.with = 'lp'
|
423
|
-
kit3.gp.key = 'off'
|
424
|
-
|
425
|
-
#####################
|
426
|
-
# Plot a single one
|
427
|
-
#####################
|
428
|
-
|
429
|
-
kit1.gnuplot_write('first_graph.eps', latex: true) #Just plot it by itself
|
430
|
-
|
431
|
-
###########################
|
432
|
-
# Plot multiple graphs
|
433
|
-
##########################
|
434
|
-
|
435
|
-
kit1.gnuplot_write('aname.eps', latex: true)
|
436
|
-
kit2.gnuplot_write('anothername.eps', latex: true)
|
437
|
-
kit3.gnuplot_write('athirdname.eps', latex: true, size: "2.0in,2.0in")
|
438
|
-
|
439
|
-
my_preamble = <<EOF
|
440
|
-
\\documentclass{article}
|
441
|
-
%\documentclass[aip,reprint]{}
|
442
|
-
\\usepackage{graphics,bm,overpic,subfigure,color}
|
443
|
-
|
444
|
-
\\pagestyle{empty}
|
445
|
-
\\begin{document}
|
446
|
-
\\begin{figure}
|
447
|
-
EOF
|
448
|
-
|
449
|
-
|
450
|
-
# Can use default preamble - just don't include preamble option in function call GraphKit.latex_multiplot('all_graphs.eps')
|
451
|
-
GraphKit.latex_multiplot('all_graphs.eps', preamble: my_preamble) do
|
452
|
-
<<EOF
|
453
|
-
\\subfigure{
|
454
|
-
\\includegraphics{aname}
|
455
|
-
}
|
456
|
-
\\subfigure{
|
457
|
-
\\begin{overpic}{anothername}
|
458
|
-
% The location is in percent of image width
|
459
|
-
\\put(44,22){\\includegraphics[scale=.45]
|
460
|
-
{athirdname}}
|
461
|
-
\\end{overpic}
|
462
|
-
}
|
463
|
-
EOF
|
464
|
-
end
|
317
|
+
end # class TestCodeRunner
|
465
318
|
|
466
|
-
|
467
|
-
|
468
|
-
end # def
|
469
|
-
|
470
|
-
end # class TestCodeRunner
|
471
|
-
|
472
|
-
end
|