nera 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +37 -0
  3. data/README.rdoc +47 -0
  4. data/Rakefile +27 -0
  5. data/bin/nera +29 -0
  6. data/bin/nera_addsim +30 -0
  7. data/lib/nera/nera_cui.rb +417 -0
  8. data/lib/nera/nera_database.rb +281 -0
  9. data/lib/nera/nera_db_folders.rb +226 -0
  10. data/lib/nera/nera_dialog.rb +205 -0
  11. data/lib/nera/nera_job_layer_controller.rb +237 -0
  12. data/lib/nera/nera_job_records.rb +111 -0
  13. data/lib/nera/nera_job_script.rb +202 -0
  14. data/lib/nera/nera_parameter_layer_controller.rb +157 -0
  15. data/lib/nera/nera_parameter_records.rb +186 -0
  16. data/lib/nera/nera_run_layer_controller.rb +192 -0
  17. data/lib/nera/nera_run_records.rb +184 -0
  18. data/lib/nera/nera_simulator.rb +26 -0
  19. data/lib/nera/nera_simulator_layer_controller.rb +66 -0
  20. data/lib/nera/nera_simulator_records.rb +84 -0
  21. data/lib/nera.rb +25 -0
  22. data/lib/nera_addsim/make_simulator.rb +307 -0
  23. data/scripts/make_manifest.rb +21 -0
  24. data/test/runner.rb +3 -0
  25. data/test/test_helper.rb +52 -0
  26. data/test/test_nera_database.rb +221 -0
  27. data/test/test_nera_db_folders.rb +209 -0
  28. data/test/test_nera_dialog.rb +134 -0
  29. data/test/test_nera_job_layer_controller.rb +132 -0
  30. data/test/test_nera_job_records.rb +260 -0
  31. data/test/test_nera_parameter_layer_controller.rb +188 -0
  32. data/test/test_nera_parameter_records.rb +285 -0
  33. data/test/test_nera_run_layer_controller.rb +171 -0
  34. data/test/test_nera_run_records.rb +290 -0
  35. data/test/test_nera_simulator.rb +26 -0
  36. data/test/test_nera_simulator_layer_controller.rb +54 -0
  37. data/test/test_nera_simulator_records.rb +140 -0
  38. metadata +125 -0
@@ -0,0 +1,221 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TC_NERA_DB < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @test_dir = "test_filelock"
7
+ FileUtils.mkdir(@test_dir)
8
+ FileUtils.chdir(@test_dir)
9
+ @path_to_db = "./testdb"
10
+ NERA::Database.create_table( @path_to_db)
11
+ @db = NERA::Database.new( @path_to_db)
12
+ end
13
+
14
+ def teardown
15
+ FileUtils.chdir("..")
16
+ FileUtils.rm_r(@test_dir)
17
+ end
18
+
19
+ def test_constructor
20
+ assert_raise( RuntimeError ) { ( NERA::Database.new("Unknown") ) }
21
+ end
22
+
23
+ def test_create_table
24
+ assert_nil( NERA::Database.create_table( @path_to_db) )
25
+ end
26
+
27
+ def test_add_find
28
+ # test of add and find
29
+ rec = { :key1 => 0.8, :key2 => DateTime.now}
30
+ given_id = @db.add( rec)
31
+ assert_equal( 1, given_id)
32
+ found = @db.find_by_id( 1)
33
+ rec[:id] = 1
34
+ assert_equal( rec, found)
35
+
36
+ # test of id
37
+ given_id = @db.add( rec)
38
+ assert_equal( 2,given_id)
39
+ found = @db.find_by_id( 2)
40
+ rec[:id] = 2
41
+ assert_equal( rec, found)
42
+
43
+ # test of find
44
+ found = @db.find_by_id( 3)
45
+ assert_equal( nil, found)
46
+ found = @db.find_by_id( 0)
47
+ assert_equal( nil, found)
48
+
49
+ assert_raise( ArgumentError) {
50
+ @db.find_by_id("3")
51
+ }
52
+
53
+ # test of find_all
54
+ found = @db.find_all do |r| true end
55
+ a = rec.dup
56
+ a[:id] = 1
57
+ b = rec.dup
58
+ b[:id] = 2
59
+ assert_equal( [ a, b], found.sort do |a,b| a[:id] <=> b[:id] end )
60
+
61
+ all1 = @db.find_all do |r| true end
62
+ all2 = @db.find_all do |r|
63
+ r[:key1000] = 1000
64
+ end
65
+ assert_equal( all1, all2)
66
+ all3 = @db.find_all do |r| true end
67
+ assert_equal( all1, all3)
68
+
69
+ found = @db.find_all do |r| false end
70
+ assert_equal( nil, found)
71
+
72
+ # test of add ( type check)
73
+ rec = { :key1 => 1, :key2 => 2.1, :key3 => "value3", :key4 => Date.new, :key5 => DateTime.now }
74
+ new_id = @db.add( rec)
75
+ rec[:id] = new_id
76
+ found = @db.find_all do |r|
77
+ r == rec
78
+ end
79
+ assert_equal( 1, found.size)
80
+ assert_equal( rec, found[0])
81
+
82
+ before = @db.find_all do |r| true end
83
+ rec = { :key1 => { 'another' => 'hash' } }
84
+ assert_raise( ArgumentError) {
85
+ flag = @db.add( rec)
86
+ }
87
+ after = @db.find_all do |r| true end
88
+ assert_equal( after, before)
89
+ end
90
+
91
+ def test_update
92
+ 10.times do |i|
93
+ record = { :key1 => i, :key2 => i.to_f}
94
+ @db.add( record)
95
+ end
96
+ found = @db.find_all do |r| true end
97
+ assert_equal( found.size, 10)
98
+
99
+ rec_to_update = found.find do |rec|
100
+ rec[:id] == 5
101
+ end
102
+ rec_to_update[:key1] = 'updated'
103
+ flag = @db.update( rec_to_update)
104
+ assert_equal(true, flag)
105
+ rec5 = @db.find_by_id( 5)
106
+ assert_equal( rec5, rec_to_update)
107
+
108
+ rec_to_update[:id] = 30
109
+ flag = @db.update( rec_to_update)
110
+ assert_nil(flag)
111
+ end
112
+
113
+ def test_destroy
114
+ 10.times do |i|
115
+ record = { :key1 => i, :key2 => i.to_f}
116
+ @db.add( record)
117
+ end
118
+
119
+ found = @db.find_all do |r| true end
120
+ assert_equal( 10, found.size)
121
+
122
+ # destroy by id
123
+ rec3 = @db.find_by_id(3)
124
+ flag = @db.destroy(3)
125
+ assert( flag)
126
+ assert_equal( rec3, flag)
127
+ found = @db.find_all do |r| true end
128
+ assert_equal( 9, found.size)
129
+ flag = found.find do |r| r[:id] == 3 end
130
+ assert_nil( flag)
131
+
132
+ flag = @db.destroy(30)
133
+ assert_nil( flag)
134
+
135
+ # should be nil
136
+ flag = @db.destroy(3)
137
+ assert_nil( flag)
138
+ found = @db.find_all do |r| true end
139
+ assert_equal( 9, found.size)
140
+
141
+ # destroy by array
142
+ destroyed = @db.destroy([1,3,9])
143
+ assert( destroyed[0])
144
+ assert_nil( destroyed[1])
145
+ assert( destroyed[2])
146
+ found = @db.find_all do |r| true end
147
+ assert_equal( 7, found.size)
148
+ flag = found.find do |r| r[:id] == 1 end
149
+ assert_nil( flag)
150
+ flag = found.find do |r| r[:id] == 9 end
151
+ assert_nil( flag)
152
+
153
+ # destroy by range
154
+ destroyed = @db.destroy( 9..10)
155
+ assert( destroyed)
156
+ destroyed = @db.destroy( 9..10)
157
+ assert_nil( destroyed)
158
+ found = @db.find_all do |r| true end
159
+ assert_equal( 6, found.size)
160
+ flag = found.find do |r| r[:id] == 10 end
161
+ assert_nil( flag)
162
+
163
+ # test max_id
164
+ @db.add( { :key1 => "11'th"} )
165
+ found = @db.find_all do |r| true end
166
+ assert_equal( 7, found.size)
167
+ flag = found.find do |r| r[:id] == 11 end
168
+ assert( flag)
169
+
170
+ # test type
171
+ assert_raise( ArgumentError) {
172
+ @db.destroy("hoge")
173
+ }
174
+ end
175
+
176
+ def test_block
177
+ 10.times do |i|
178
+ record = { :key1 => i+1, :key2 => (i+1).to_f}
179
+ @db.add( record)
180
+ end
181
+
182
+ @db.transaction do
183
+ arr = @db.find_all do |rec|
184
+ rec[:id] <= 5
185
+ end
186
+ arr.each do |rec|
187
+ rec[:key1] += 100
188
+ @db.update( rec)
189
+ end
190
+ end
191
+
192
+ a = @db.find_all do |r| true end
193
+ assert_equal( 10, a.size)
194
+ a = @db.find_all do |rec| rec[:key1] > 100 end
195
+ assert_equal( 5, a.size)
196
+ flag = a.find do |rec| rec[:key1] == 101 end
197
+ assert( flag)
198
+ flag = a.find do |rec| rec[:key1] == 102 end
199
+ assert( flag)
200
+ flag = a.find do |rec| rec[:key1] == 103 end
201
+ assert( flag)
202
+ flag = a.find do |rec| rec[:key1] == 104 end
203
+ assert( flag)
204
+ flag = a.find do |rec| rec[:key1] == 105 end
205
+ assert( flag)
206
+
207
+ a = @db.find_all do |r| true end
208
+ t = nil
209
+ assert_raise(RuntimeError) {
210
+ @db.transaction {
211
+ t = @db.destroy(3)
212
+ raise RuntimeError
213
+ }
214
+ }
215
+ assert(t)
216
+ b = @db.find_all do |r| true end
217
+ assert_equal( a, b)
218
+
219
+ end
220
+
221
+ end
@@ -0,0 +1,209 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TC_NERA_DB_FOLDERS < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @testdir = "test"
7
+ FileUtils.mkdir(@testdir)
8
+ FileUtils.chdir(@testdir)
9
+
10
+ @db_folder = "nera_db"
11
+ NERA::DbFolders.create_db( @db_folder)
12
+ @dbf = NERA::DbFolders.new( @db_folder)
13
+ end
14
+
15
+ def teardown
16
+ FileUtils.chdir('..')
17
+ FileUtils.rm_r(@testdir)
18
+ end
19
+
20
+ def test_constructor
21
+ FileUtils.mkdir("dummy")
22
+ assert_raise( RuntimeError) {
23
+ NERA::DbFolders.new("dummy")
24
+ }
25
+ assert_raise( RuntimeError) {
26
+ NERA::DbFolders.new("unknown")
27
+ }
28
+ end
29
+
30
+ def test_createdb
31
+ assert( FileTest.directory?(@db_folder) )
32
+ assert( FileTest.directory?(@db_folder+"/Jobs/") )
33
+ assert( FileTest.directory?(@db_folder+"/Jobs/Include") )
34
+ assert( FileTest.directory?(@db_folder+"/Tables") )
35
+ assert( FileTest.directory?(@db_folder+"/Simulator_classes") )
36
+ assert( FileTest.exist?(@db_folder+"/Tables/jobs.pstore") )
37
+ assert( FileTest.exist?(@db_folder+"/simulators.yml") )
38
+ assert( FileTest.exist?(@db_folder+"/Jobs/jobs.yml") )
39
+ assert_raise( RuntimeError) {
40
+ NERA::DbFolders.create_db( @db_folder)
41
+ }
42
+
43
+ end
44
+
45
+ def test_path_to_sim_layer
46
+ p = @dbf.path_to_simulator_layer
47
+ assert_equal( @db_folder+'/', p)
48
+ end
49
+
50
+ def test_path_to_sim_tables
51
+ p = @dbf.path_to_simulators_table
52
+ assert_equal( @db_folder+"/Tables/simulators.pstore", p)
53
+ p = @dbf.path_to_simulators_yaml
54
+ assert_equal( @db_folder+"/simulators.yml", p)
55
+ end
56
+
57
+ def test_create_new_simulator_folder
58
+ r = @dbf.create_new_simulator_folder( Ising )
59
+ assert_equal( true, r)
60
+ assert( FileTest.directory?( @db_folder+"/Ising/") )
61
+ assert( FileTest.directory?( @db_folder+"/Tables/Ising/") )
62
+ assert( FileTest.exist?( @db_folder+"/Ising/parameters.yml") )
63
+
64
+ r = @dbf.create_new_simulator_folder( XY )
65
+ assert_equal( true, r)
66
+ assert( FileTest.directory?( @db_folder+"/XY/") )
67
+ assert( FileTest.directory?( @db_folder+"/Tables/XY/") )
68
+ assert( FileTest.exist?( @db_folder+"/XY/parameters.yml") )
69
+
70
+ assert_raise( ArgumentError) {
71
+ @dbf.create_new_simulator_folder( Temp)
72
+ }
73
+
74
+ r = @dbf.create_new_simulator_folder( Ising )
75
+ assert_nil( r)
76
+ end
77
+
78
+ def test_path_to_param_layer
79
+ r = @dbf.path_to_parameter_layer( Ising)
80
+ assert_nil(r)
81
+ r = @dbf.create_new_simulator_folder( Ising )
82
+ r = @dbf.path_to_parameter_layer( Ising)
83
+ assert_equal( @db_folder+"/Ising/", r)
84
+ assert_raise( ArgumentError) {
85
+ @dbf.path_to_parameter_layer( Temp)
86
+ }
87
+ end
88
+
89
+ def test_path_to_param_table
90
+ r = @dbf.path_to_parameters_table( Ising)
91
+ assert_nil(r)
92
+ r = @dbf.create_new_simulator_folder( Ising )
93
+ assert_equal( true, r)
94
+ r = @dbf.path_to_parameters_table( Ising)
95
+ assert_equal( @db_folder+"/Tables/Ising/parameters.pstore", r)
96
+ r = @dbf.path_to_parameters_yaml( Ising)
97
+ assert_equal( @db_folder+ "/Ising/parameters.yml", r)
98
+ assert_raise( ArgumentError) {
99
+ @dbf.path_to_parameters_table( Temp)
100
+ }
101
+ end
102
+
103
+ def test_create_new_param_folder
104
+ r = @dbf.create_new_parameter_folder( Ising, 5)
105
+ assert_nil( r)
106
+ @dbf.create_new_simulator_folder( Ising )
107
+ r = @dbf.create_new_parameter_folder( Ising, 1)
108
+ assert_equal( true, r)
109
+ assert( FileTest.directory?( @db_folder+"/Ising/00001/") )
110
+ assert( FileTest.directory?( @db_folder+"/Tables/Ising/00001/") )
111
+ assert( FileTest.exist?( @db_folder+"/Ising/00001/runs.yml") )
112
+ r = @dbf.create_new_parameter_folder( Ising, 2)
113
+ assert_equal( true, r)
114
+ assert( FileTest.directory?( @db_folder+"/Ising/00002/") )
115
+ assert( FileTest.directory?( @db_folder+"/Tables/Ising/00002/") )
116
+ assert( FileTest.exist?( @db_folder+"/Ising/00002/runs.yml") )
117
+ r = @dbf.create_new_parameter_folder( Ising, 2)
118
+ assert_equal( nil, r)
119
+
120
+ assert_raise( RuntimeError) {
121
+ r = @dbf.create_new_parameter_folder( Ising, 100000)
122
+ }
123
+ assert_raise( RuntimeError) {
124
+ r = @dbf.create_new_parameter_folder( Ising, 0)
125
+ }
126
+ assert_raise( ArgumentError) {
127
+ @dbf.create_new_parameter_folder( Temp)
128
+ }
129
+ end
130
+
131
+ def test_path_to_run_layer
132
+ assert_raise( ArgumentError) {
133
+ s = @dbf.path_to_run_layer( Temp, 1)
134
+ }
135
+
136
+ s = @dbf.path_to_run_layer( Ising, 1)
137
+ assert_nil( s)
138
+ @dbf.create_new_simulator_folder( Ising)
139
+ s = @dbf.path_to_run_layer( Ising, 1)
140
+ assert_equal( false, FileTest.directory?(s))
141
+ @dbf.create_new_parameter_folder( Ising, 1)
142
+ s = @dbf.path_to_run_layer( Ising, 1)
143
+ assert_equal( @db_folder+"/Ising/00001/", s)
144
+
145
+ s = @dbf.path_to_run_layer( Ising, 1000)
146
+ assert_equal( @db_folder+"/Ising/01000/", s)
147
+ end
148
+
149
+ def test_path_to_runs_table
150
+ assert_raise( ArgumentError) {
151
+ s = @dbf.path_to_runs_table( Temp, 1)
152
+ }
153
+
154
+ s = @dbf.path_to_runs_table( Ising, 1)
155
+ assert_nil( s)
156
+ @dbf.create_new_simulator_folder( Ising)
157
+ s = @dbf.path_to_runs_table( Ising, 1)
158
+ assert_equal( false, FileTest.exist?(s))
159
+ @dbf.create_new_parameter_folder( Ising, 1)
160
+ s = @dbf.path_to_runs_table( Ising, 1)
161
+ assert_equal( @db_folder+"/Tables/Ising/00001/runs.pstore", s)
162
+ s = @dbf.path_to_runs_yaml( Ising, 1)
163
+ assert_equal( @db_folder+"/Ising/00001/runs.yml", s)
164
+
165
+ s = @dbf.path_to_runs_table( Ising, 999)
166
+ assert_equal( @db_folder+"/Tables/Ising/00999/runs.pstore", s)
167
+ s = @dbf.path_to_runs_yaml( Ising, 999)
168
+ assert_equal( @db_folder+"/Ising/00999/runs.yml", s)
169
+
170
+ end
171
+
172
+ def test_path_to_job_layer
173
+ p = @dbf.path_to_job_layer
174
+ assert_equal( @db_folder+"/Jobs/", p)
175
+ end
176
+
177
+ def test_path_to_jobs_table
178
+ p = @dbf.path_to_jobs_table
179
+ assert_equal( @db_folder+"/Tables/jobs.pstore", p)
180
+ p = @dbf.path_to_jobs_yaml
181
+ assert_equal( @db_folder+"/Jobs/jobs.yml", p)
182
+ end
183
+
184
+ def test_to_job_script( job_id)
185
+ p = @dbf.path_to_job_script(125)
186
+ assert_equal( @db_folder+"/Jobs/j000125.sh", p)
187
+ end
188
+
189
+ def test_path_to_include_layer
190
+ p = @dbf.path_to_include_layer
191
+ assert_equal( @db_folder+"/Jobs/Include/", p)
192
+ end
193
+
194
+ def test_search_include_files
195
+ FileUtils.touch( @dbf.path_to_include_layer + "j000001.tar.bz2")
196
+ FileUtils.touch( @dbf.path_to_include_layer + "j000003.tar.bz2")
197
+ FileUtils.touch( @dbf.path_to_include_layer + "j00001.tar.bz2")
198
+ should_be = [ @dbf.path_to_include_layer + "j000001.tar.bz2", @dbf.path_to_include_layer + "j000003.tar.bz2"]
199
+ l = @dbf.search_include_files
200
+ assert_equal( should_be, l)
201
+ end
202
+
203
+ def test_path_to_finished_jobs_file
204
+ p = @dbf.path_to_finished_jobs_file
205
+ assert_equal( @db_folder+"/Tables/finished_jobs.yml", p)
206
+ end
207
+
208
+ end
209
+
@@ -0,0 +1,134 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+
4
+ class TC_NERA_DIALOG < Test::Unit::TestCase
5
+
6
+ def setup
7
+ end
8
+
9
+ def teardown
10
+ end
11
+
12
+ def test_select_one
13
+ a = ["first","second","third"]
14
+ i = Dialog::select_one( a, "Input a number for a test of 'Dialog::select_one'", 1)
15
+ assert( i.is_a?(Integer) )
16
+ assert( i < 3 )
17
+ assert( i >= 0 )
18
+
19
+ b = []
20
+ assert_raise( ArgumentError) {
21
+ i = Dialog::select_one( b, "Select one")
22
+ }
23
+
24
+ c = "hoge"
25
+ assert_raise( ArgumentError) {
26
+ i = Dialog::select_one( c, "Select one")
27
+ }
28
+
29
+ assert_raise( ArgumentError) {
30
+ i = Dialog::select_one( a, "Select one", 100)
31
+ }
32
+ end
33
+
34
+ def test_select_one_or_return_string
35
+ a = ["first","second","third"]
36
+ i = Dialog::select_one_or_return_string( a, "Input a number for a test of 'Dialog::select_one_or_return_string'",2)
37
+ assert( i.is_a?(Integer) )
38
+ assert( i < 3 )
39
+ assert( i >= 0 )
40
+
41
+ i = Dialog::select_one_or_return_string( a, "Input a string for a test of 'Dialog::select_one_or_return_string'","test string")
42
+ assert( i.is_a?(String) )
43
+
44
+ b = []
45
+ assert_raise( ArgumentError) {
46
+ i = Dialog::select_one_or_return_string( b, "Select one")
47
+ }
48
+ c = []
49
+ assert_raise( ArgumentError) {
50
+ i = Dialog::select_one_or_return_string( c, "Select one")
51
+ }
52
+ end
53
+
54
+ def test_select_many
55
+ a = ["first","second","third","fourth","fifth"]
56
+ s = Dialog::select_many( a, "Input 3 for a test of 'Dialog::select_many'", 3)
57
+ assert( s.is_a?(Array) )
58
+ assert_equal( 1, s.size)
59
+ assert( s[0].is_a?(Integer) )
60
+ assert( s[0] < a.size )
61
+ assert( s[0] >= 0)
62
+
63
+ s = Dialog::select_many( a, "Input '0,3,4' for a test of 'Dialog::select_many'", '0,3,4')
64
+ assert( s.is_a?(Array) )
65
+ assert_equal( 3, s.size)
66
+ s.each do |i|
67
+ assert( i.is_a?(Integer) )
68
+ assert( i < a.size )
69
+ assert( i >= 0 )
70
+ end
71
+
72
+ s = Dialog::select_many( a, "Input '1-3' for a test of 'Dialog::select_many'", '1-3')
73
+ assert( s.is_a?(Array) )
74
+ assert_equal( 3, s.size)
75
+ s.each do |i|
76
+ assert( i.is_a?(Integer) )
77
+ assert( i < a.size )
78
+ assert( i >= 0)
79
+ end
80
+
81
+ b = []
82
+ assert_raise(ArgumentError) {
83
+ s = Dialog::select_many( b, "Input '1-3' for a test of 'Dialog::select_many'", '1-3')
84
+ }
85
+
86
+ c = "hoge"
87
+ assert_raise(ArgumentError) {
88
+ s = Dialog::select_many( c, "Input '1-3' for a test of 'Dialog::select_many'", '1-3')
89
+ }
90
+
91
+ end
92
+
93
+ def test_message
94
+ str = "This is a test"
95
+ Dialog::message( str)
96
+ end
97
+
98
+ def test_set_multiple_values
99
+ arg = [ [:L,Integer,32], [:K,Float,0.22], [:txt,String,'hoge'] ]
100
+ h = Dialog::set_multiple_values( arg)
101
+ assert( h.is_a?(Hash) )
102
+ assert( h[:L].is_a?(Integer) )
103
+ assert( h[:K].is_a?(Float) )
104
+ assert( h[:txt].is_a?(String) )
105
+ assert_equal( 3, h.size)
106
+
107
+ arg = [ [:L,Integer], [:K,Float], [:txt,String] ]
108
+ assert_raise(ArgumentError) {
109
+ h = Dialog::set_multiple_values( arg)
110
+ }
111
+ arg = [ [:L,32], [:K,0.22], [:txt,"hoge"] ]
112
+ assert_raise(ArgumentError) {
113
+ h = Dialog::set_multiple_values( arg)
114
+ }
115
+ arg = [ [:L,Integer,32], [:K,Float,0.22], [:L,String,"hoge"] ]
116
+ assert_raise(ArgumentError) {
117
+ h = Dialog::set_multiple_values( arg)
118
+ }
119
+
120
+ end
121
+
122
+ def test_get_integer
123
+ s = Dialog::get_integer( "Input a positive number", 0) do |i|
124
+ i >= 0
125
+ end
126
+ assert( s.is_a?(Integer))
127
+ assert( s >= 0 )
128
+
129
+ assert_raise( ArgumentError) {
130
+ Dialog::get_integer( "Input a number", "hoge")
131
+ }
132
+ end
133
+
134
+ end
@@ -0,0 +1,132 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+
4
+ class TC_NERA_JOB_LAYER_CONTROLLER < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @testdir = 'test_sim_controller'
8
+ FileUtils.mkdir(@testdir)
9
+ FileUtils.chdir(@testdir)
10
+ @db_folder = "nera_db"
11
+ NERA::DbFolders.create_db( @db_folder)
12
+ @dbf = NERA::DbFolders.new( @db_folder)
13
+ @slc = NERA::SimulatorLayerController.new( @db_folder)
14
+ @plc = NERA::ParameterLayerController.new( @db_folder, Ising)
15
+ pid = @plc.create_a_new_parameter_set({:L => 32, :K => 0.01, :tmax => 1})
16
+ @rlc = NERA::RunLayerController.new( @db_folder, Ising, pid)
17
+ @rlc.create_jobs( 3, 1)
18
+ @jlc = NERA::JobLayerController.new( @db_folder)
19
+ end
20
+
21
+ def teardown
22
+ FileUtils.chdir('..')
23
+ FileUtils.rm_r(@testdir)
24
+ end
25
+
26
+ def test_constructor
27
+ assert_raise( ArgumentError) {
28
+ NERA::JobLayerController.new( @dbf)
29
+ }
30
+ end
31
+
32
+ def test_path_to_job_layer
33
+ assert_equal( @dbf.path_to_job_layer, @jlc.path_to_job_layer)
34
+ end
35
+
36
+ def test_not_finished_list_in_csv
37
+ h, l = @jlc.not_finished_list_in_csv
38
+ assert_equal( "id, state, simulator, param_id, run_id, num_runs, created_at, updated_at, host_name", h)
39
+ assert_equal( 3, l.size)
40
+ dstr = DateTime.now.to_s.split('T')[0]
41
+ assert_equal( "1, created, Ising, 1, 1, 1, #{dstr}, #{dstr}, ", l[0])
42
+ assert_equal( "2, created, Ising, 1, 2, 1, #{dstr}, #{dstr}, ", l[1])
43
+ assert_equal( "3, created, Ising, 1, 3, 1, #{dstr}, #{dstr}, ", l[2])
44
+
45
+ f = @jlc.cancel_jobs( [2])
46
+ h, l = @jlc.not_finished_list_in_csv
47
+ assert_equal( "id, state, simulator, param_id, run_id, num_runs, created_at, updated_at, host_name", h)
48
+ assert_equal( 2, l.size)
49
+ assert_equal( "1, created, Ising, 1, 1, 1, #{dstr}, #{dstr}, ", l[0])
50
+ assert_equal( "3, created, Ising, 1, 3, 1, #{dstr}, #{dstr}, ", l[1])
51
+ end
52
+
53
+ def test_cancel_jobs
54
+ assert_raise( ArgumentError) {
55
+ @jlc.cancel_jobs(1)
56
+ }
57
+
58
+ f = @jlc.cancel_jobs( [1,2] )
59
+ assert(f)
60
+ h, l = @jlc.not_finished_list_in_csv
61
+ assert_equal( 1, l.size)
62
+ assert_equal( 3, l[0].split(',')[0].to_i)
63
+
64
+ flag = File.exist?( @dbf.path_to_job_script(1))
65
+ assert_equal( false, flag)
66
+ flag = File.exist?( @dbf.path_to_job_script(2))
67
+ assert_equal( false, flag)
68
+
69
+ h, l = @rlc.not_finished_jobs_list_in_csv
70
+ assert_equal( 1, l.size)
71
+
72
+ f = @jlc.cancel_jobs( [1000] )
73
+ assert_nil( f)
74
+ end
75
+
76
+ def test_include_list
77
+ l = @jlc.include_list
78
+ assert_equal( 0, l.size)
79
+
80
+ FileUtils.touch( @dbf.path_to_include_layer + "j000001.tar.bz2")
81
+ FileUtils.touch( @dbf.path_to_include_layer + "j000003.tar.bz2")
82
+ l = @jlc.include_list
83
+ assert_equal( ["j000001.tar.bz2","j000003.tar.bz2"], l)
84
+
85
+ FileUtils.touch( @dbf.path_to_include_layer + "g000001.tar.bz2")
86
+ l2 = @jlc.include_list
87
+ assert_equal( l, l2)
88
+ end
89
+
90
+ def test_include
91
+ prepare_zipped_file
92
+ fname = "j000001.tar.bz2"
93
+ @jlc.include(fname)
94
+ f = FileTest.exist?(fname)
95
+ assert_equal( false, f)
96
+ count = 0
97
+ File.open( @dbf.path_to_finished_jobs_file, 'r') do |io|
98
+ YAML.load_documents( io) do |doc|
99
+ p doc
100
+ count += 1
101
+ end
102
+ end
103
+ assert_equal( 1, count)
104
+ h, l = @jlc.not_finished_list_in_csv
105
+ assert_equal( 2, l.size)
106
+ h, l = @rlc.not_finished_jobs_list_in_csv
107
+ assert_equal( 2, l.size)
108
+ end
109
+
110
+ def test_include_all
111
+ prepare_zipped_file
112
+ @jlc.include_all
113
+ a = Dir.glob( @dbf.path_to_include_layer + "*" )
114
+ assert_equal( [], a)
115
+ h, l = @jlc.not_finished_list_in_csv
116
+ assert_equal( [], l)
117
+ h, l = @rlc.not_finished_jobs_list_in_csv
118
+ assert_equal( [], l)
119
+ end
120
+
121
+ def prepare_zipped_file
122
+ Dir.chdir( @dbf.path_to_job_layer) {
123
+ system "sh ./j000001.sh"
124
+ system "mv j000001.tar.bz2 Include/"
125
+ system "sh ./j000002.sh"
126
+ system "mv j000002.tar.bz2 Include/"
127
+ system "sh ./j000003.sh"
128
+ system "mv j000003.tar.bz2 Include/"
129
+ }
130
+ end
131
+
132
+ end