acts-as-dag 1.1.4 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/dag_test.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
+ gem 'activerecord', '= 3.0.0'
4
+ require 'active_record'
3
5
  require "./init"
4
6
 
5
7
 
@@ -20,10 +22,10 @@ end
20
22
  #Used for redefinition testing
21
23
  class Redefiner < ActiveRecord::Base
22
24
  acts_as_dag_links :node_class_name => 'Redefiner',
23
- :direct_column => 'd',
24
- :count_column => 'c',
25
- :ancestor_id_column => 'foo_id',
26
- :descendant_id_column => 'bar_id'
25
+ :direct_column => 'd',
26
+ :count_column => 'c',
27
+ :ancestor_id_column => 'foo_id',
28
+ :descendant_id_column => 'bar_id'
27
29
  set_table_name 'edges2'
28
30
  end
29
31
 
@@ -39,85 +41,85 @@ end
39
41
 
40
42
  class AlphaNode < ActiveRecord::Base
41
43
  has_dag_links :link_class_name => 'Poly',
42
- :descendant_class_names => ['BetaNode','GammaNode','ZetaNode']
44
+ :descendant_class_names => ['BetaNode', 'GammaNode', 'ZetaNode']
43
45
  set_table_name 'alpha_nodes'
44
46
  end
45
47
 
46
48
  class BetaNode < ActiveRecord::Base
47
49
  has_dag_links :link_class_name => 'Poly',
48
- :ancestor_class_names => ['AlphaNode','BetaNode'],
49
- :descendant_class_names => ['BetaNode','GammaNode','ZetaNode']
50
+ :ancestor_class_names => ['AlphaNode', 'BetaNode'],
51
+ :descendant_class_names => ['BetaNode', 'GammaNode', 'ZetaNode']
50
52
  set_table_name 'beta_nodes'
51
53
  end
52
54
 
53
55
  class GammaNode < ActiveRecord::Base
54
56
  has_dag_links :link_class_name => 'Poly',
55
- :ancestor_class_names => ['AlphaNode','BetaNode','GammaNode'],
56
- :descendant_class_names => ['GammaNode','ZetaNode']
57
+ :ancestor_class_names => ['AlphaNode', 'BetaNode', 'GammaNode'],
58
+ :descendant_class_names => ['GammaNode', 'ZetaNode']
57
59
  set_table_name 'gamma_nodes'
58
60
  end
59
61
 
60
62
  class ZetaNode < ActiveRecord::Base
61
63
  has_dag_links :link_class_name => 'Poly',
62
- :ancestor_class_names => ['AlphaNode','BetaNode','GammaNode']
64
+ :ancestor_class_names => ['AlphaNode', 'BetaNode', 'GammaNode']
63
65
  set_table_name 'zeta_nodes'
64
66
  end
65
67
 
66
68
 
67
69
  #Unit Tests for the DAG plugin
68
70
  class DagTest < Test::Unit::TestCase
69
-
71
+
70
72
  #Setups up database in memory
71
73
  def setup
72
74
  ActiveRecord::Schema.define(:version => 1) do
73
- create_table :edges do |t|
74
- t.column :ancestor_id, :integer
75
- t.column :descendant_id, :integer
76
- t.column :direct, :boolean
77
- t.column :count, :integer
78
- end
79
-
80
- create_table :edges2 do |t|
81
- t.column :foo_id, :integer
82
- t.column :bar_id, :integer
83
- t.column :d, :boolean
84
- t.column :c, :integer
85
- end
86
-
87
- create_table :nodes do |t|
88
- t.column :name, :string
89
- end
90
-
91
- create_table :alpha_nodes do |t|
92
- t.column :name, :string
93
- end
94
-
95
- create_table :beta_nodes do |t|
96
- t.column :name, :string
97
- end
98
-
99
- create_table :gamma_nodes do |t|
100
- t.column :name, :string
101
- end
102
-
103
- create_table :zeta_nodes do |t|
104
- t.column :name, :string
105
- end
106
-
107
- create_table :redef_nodes do |t|
108
- t.column :name, :string
109
- end
75
+ create_table :edges do |t|
76
+ t.column :ancestor_id, :integer
77
+ t.column :descendant_id, :integer
78
+ t.column :direct, :boolean
79
+ t.column :count, :integer
80
+ end
81
+
82
+ create_table :edges2 do |t|
83
+ t.column :foo_id, :integer
84
+ t.column :bar_id, :integer
85
+ t.column :d, :boolean
86
+ t.column :c, :integer
87
+ end
88
+
89
+ create_table :nodes do |t|
90
+ t.column :name, :string
91
+ end
92
+
93
+ create_table :alpha_nodes do |t|
94
+ t.column :name, :string
95
+ end
96
+
97
+ create_table :beta_nodes do |t|
98
+ t.column :name, :string
99
+ end
100
+
101
+ create_table :gamma_nodes do |t|
102
+ t.column :name, :string
103
+ end
110
104
 
111
- create_table :poly_edges do |t|
112
- t.column :ancestor_id, :integer
113
- t.column :ancestor_type, :string
114
- t.column :descendant_id, :integer
115
- t.column :descendant_type, :string
116
- t.column :direct, :boolean
117
- t.column :count, :integer
105
+ create_table :zeta_nodes do |t|
106
+ t.column :name, :string
107
+ end
108
+
109
+ create_table :redef_nodes do |t|
110
+ t.column :name, :string
111
+ end
112
+
113
+ create_table :poly_edges do |t|
114
+ t.column :ancestor_id, :integer
115
+ t.column :ancestor_type, :string
116
+ t.column :descendant_id, :integer
117
+ t.column :descendant_type, :string
118
+ t.column :direct, :boolean
119
+ t.column :count, :integer
120
+ end
118
121
  end
119
122
  end
120
- end
121
123
 
122
124
  #Brings down database
123
125
  def teardown
@@ -125,95 +127,95 @@ class DagTest < Test::Unit::TestCase
125
127
  ActiveRecord::Base.connection.drop_table(table)
126
128
  end
127
129
  end
128
-
130
+
129
131
  #Test ancestor id column default value
130
132
  def test_ancestor_id_column_default
131
133
  assert_equal 'ancestor_id', Default.acts_as_dag_options[:ancestor_id_column]
132
134
  end
133
-
135
+
134
136
  #Test descendant id column default value
135
137
  def test_descendant_id_column_default
136
138
  assert_equal 'descendant_id', Default.acts_as_dag_options[:descendant_id_column]
137
139
  end
138
-
140
+
139
141
  #Test direct column default value
140
142
  def test_direct_column_default
141
143
  assert_equal 'direct', Default.acts_as_dag_options[:direct_column]
142
144
  end
143
-
145
+
144
146
  #Test count column default value
145
147
  def test_count_column_default
146
148
  assert_equal 'count', Default.acts_as_dag_options[:count_column]
147
149
  end
148
-
150
+
149
151
  #Test ancestor type column default value
150
152
  def test_ancestor_type_column_default
151
153
  assert_equal 'ancestor_type', Poly.acts_as_dag_options[:ancestor_type_column]
152
154
  end
153
-
155
+
154
156
  #Test descendant type column default value
155
157
  def test_descendant_type_column_default
156
158
  assert_equal 'descendant_type', Poly.acts_as_dag_options[:descendant_type_column]
157
159
  end
158
-
160
+
159
161
  #Test polymorphic option default value
160
162
  def test_polymorphic_default
161
163
  assert Poly.acts_as_dag_options[:polymorphic]
162
164
  assert !Default.acts_as_dag_options[:polymorphic]
163
165
  end
164
-
166
+
165
167
  #more defaults here
166
-
168
+
167
169
  #Tests ancestor_id_column_name instance and class method
168
170
  def test_ancestor_id_column_name
169
171
  assert_equal 'ancestor_id', Default.ancestor_id_column_name
170
172
  assert_equal 'ancestor_id', Default.new.ancestor_id_column_name
171
173
  end
172
-
174
+
173
175
  #Tests descendant_id_column_name instance and class method
174
176
  def test_descendant_id_column_name
175
177
  assert_equal 'descendant_id', Default.descendant_id_column_name
176
178
  assert_equal 'descendant_id', Default.new.descendant_id_column_name
177
179
  end
178
-
180
+
179
181
  #Tests direct_column_name instance and class method
180
182
  def test_direct_column_name
181
183
  assert_equal 'direct', Default.direct_column_name
182
184
  assert_equal 'direct', Default.new.direct_column_name
183
185
  end
184
-
186
+
185
187
  #Tests count_column_name instance and class method
186
188
  def test_count_column_name
187
189
  assert_equal 'count', Default.count_column_name
188
190
  assert_equal 'count', Default.new.count_column_name
189
191
  end
190
-
192
+
191
193
  #Tests ancestor_type_column_name polymorphic instance and class method
192
194
  def test_ancestor_type_column_name
193
195
  assert_equal 'ancestor_type', Poly.ancestor_type_column_name
194
196
  assert_equal 'ancestor_type', Poly.new.ancestor_type_column_name
195
197
  end
196
-
198
+
197
199
  #Tests descendant_type_column_name polymorphic instance and class method
198
200
  def test_descendant_type_column_name
199
201
  assert_equal 'descendant_type', Poly.descendant_type_column_name
200
202
  assert_equal 'descendant_type', Poly.new.descendant_type_column_name
201
203
  end
202
-
204
+
203
205
  #Tests that count is a protected function and cannot be assigned
204
206
  def test_count_protected
205
207
  assert_raises(ActiveRecord::ActiveRecordError) { d = Default.new(:count => 1) }
206
208
  assert_raises(ActiveRecord::ActiveRecordError) { d = Default.new()
207
- d.count = 8 }
209
+ d.count = 8 }
208
210
  end
209
-
211
+
210
212
  #Tests that direct is a protected function and cannot be assigned
211
213
  #def test_direct_protected
212
214
  # assert_raises(ActiveRecord::ActiveRecordError) { d = Default.new(:direct => 1) }
213
215
  # assert_raises(ActiveRecord::ActiveRecordError) { d = Default.new()
214
216
  # d.direct = false }
215
217
  #end
216
-
218
+
217
219
  #Tests that make_direct instance method trues direct value and registers change
218
220
  def test_make_direct_method
219
221
  d = Default.new
@@ -222,7 +224,7 @@ class DagTest < Test::Unit::TestCase
222
224
  assert d.direct_changed?
223
225
  assert d.direct
224
226
  end
225
-
227
+
226
228
  #Tests that make_indirect instance method falses direct value and registers change
227
229
  def test_make_indirect_method
228
230
  d = Default.new
@@ -231,26 +233,27 @@ class DagTest < Test::Unit::TestCase
231
233
  assert d.direct_changed?
232
234
  assert !d.direct
233
235
  end
234
-
236
+
235
237
  #Tests that changes register initial settings
236
238
  def test_direct_changed_init_pass_in
237
239
  d = Default.new(:direct => true)
238
240
  assert d.direct_changed?
239
241
  end
242
+
240
243
  #Tests that endpoint construction works
241
244
  def test_make_endpoint
242
245
  a = Node.create!
243
246
  p = Default::EndPoint.from(a)
244
247
  assert p.matches?(a)
245
248
  end
246
-
249
+
247
250
  #Tests that polymorphic endpoint construction works
248
251
  def test_make_endpoint_poly
249
252
  a = AlphaNode.create!
250
253
  p = Poly::EndPoint.from(a)
251
254
  assert p.matches?(a)
252
255
  end
253
-
256
+
254
257
  #Tests that source is correct
255
258
  def test_source_method
256
259
  a = Node.create!
@@ -259,7 +262,7 @@ class DagTest < Test::Unit::TestCase
259
262
  s = edge.source
260
263
  assert s.matches?(a)
261
264
  end
262
-
265
+
263
266
  #Tests that sink is correct
264
267
  def test_sink_method
265
268
  a = Node.create!
@@ -268,7 +271,7 @@ class DagTest < Test::Unit::TestCase
268
271
  s = edge.sink
269
272
  assert s.matches?(b)
270
273
  end
271
-
274
+
272
275
  #Tests that source is correct for polymorphic graphs
273
276
  def test_source_method_poly
274
277
  a = AlphaNode.create!
@@ -277,7 +280,7 @@ class DagTest < Test::Unit::TestCase
277
280
  s = edge.source
278
281
  assert s.matches?(a)
279
282
  end
280
-
283
+
281
284
  #Tests that sink is correct for polymorphic graphs
282
285
  def test_sink_method_poly
283
286
  a = AlphaNode.create!
@@ -286,189 +289,189 @@ class DagTest < Test::Unit::TestCase
286
289
  s = edge.sink
287
290
  assert s.matches?(b)
288
291
  end
289
-
292
+
290
293
  #Tests that source is correct when created from a model
291
294
  def test_source_method_on_resource
292
295
  a = Node.create!
293
296
  s = Default::Source.from(a)
294
297
  assert s.matches?(a)
295
298
  end
296
-
299
+
297
300
  #Tests that sink is correct when created from a model
298
301
  def test_sink_method_on_resource
299
302
  a = Node.create!
300
303
  s = Default::Source.from(a)
301
304
  assert s.matches?(a)
302
305
  end
303
-
306
+
304
307
  #Tests that source is correct when created from a model for a polymorphic graph
305
308
  def test_source_method_on_resource_poly
306
309
  a = AlphaNode.create!
307
310
  s = Poly::Source.from(a)
308
311
  assert s.matches?(a)
309
312
  end
310
-
313
+
311
314
  #Tests that sink is correct when created from a model for a polymorphic graph
312
315
  def test_sink_method_on_resource_poly
313
316
  a = AlphaNode.create!
314
317
  s = Poly::Source.from(a)
315
318
  assert s.matches?(a)
316
319
  end
317
-
320
+
318
321
  #Tests that class method for build works
319
322
  def test_build_lonely_edge
320
323
  a = Node.create!
321
324
  b = Node.create!
322
- e = Default.build_edge(a,b)
325
+ e = Default.build_edge(a, b)
323
326
  assert e.source.matches?(a)
324
327
  assert e.sink.matches?(b)
325
328
  end
326
-
329
+
327
330
  #Tests that create_edge works
328
331
  def test_create_lonely_edge
329
332
  a = Node.create!
330
333
  b = Node.create!
331
- e = Default.create_edge(a,b)
334
+ e = Default.create_edge(a, b)
332
335
  assert e
333
336
  end
334
-
337
+
335
338
  #Tests that create_edge! works
336
339
  def test_create_exla_lonely_edge
337
340
  a = Node.create!
338
341
  b = Node.create!
339
- e = Default.create_edge!(a,b)
342
+ e = Default.create_edge!(a, b)
340
343
  assert_equal e.ancestor, a
341
344
  assert_equal e.descendant, b
342
345
  end
343
-
346
+
344
347
  #Tests that find edge works
345
348
  def test_find_lonely_edge
346
349
  a = Node.create!
347
350
  b = Node.create!
348
- e = Default.create_edge(a,b)
349
- e = Default.find_edge(a,b)
351
+ e = Default.create_edge(a, b)
352
+ e = Default.find_edge(a, b)
350
353
  assert_equal e.ancestor, a
351
354
  assert_equal e.descendant, b
352
355
  end
353
-
356
+
354
357
  #Tests that find link works and find_edge rejects indirects
355
358
  def test_find_lonely_link
356
359
  a = Node.create!
357
360
  b = Node.create!
358
- e = Default.create_edge(a,b)
359
- e = Default.find_link(a,b)
361
+ e = Default.create_edge(a, b)
362
+ e = Default.find_link(a, b)
360
363
  assert_equal e.ancestor, a
361
364
  assert_equal e.descendant, b
362
365
  end
363
-
366
+
364
367
  #Tests that we catch links that would be duplicated on creation
365
368
  def test_validation_on_create_duplication_catch
366
369
  a = Node.create!
367
370
  b = Node.create!
368
- e = Default.create_edge(a,b)
369
- e2 = Default.create_edge(a,b)
371
+ e = Default.create_edge(a, b)
372
+ e2 = Default.create_edge(a, b)
370
373
  assert !e2
371
- assert_raises(ActiveRecord::RecordInvalid) { e3 = Default.create_edge!(a,b) }
374
+ assert_raises(ActiveRecord::RecordInvalid) { e3 = Default.create_edge!(a, b) }
372
375
  end
373
-
376
+
374
377
  #Tests that we catch reversed links on creation (cycles)
375
378
  def test_validation_on_create_reverse_catch
376
379
  a = Node.create!
377
380
  b = Node.create!
378
- e = Default.create_edge(a,b)
379
- e2 = Default.create_edge(b,a)
381
+ e = Default.create_edge(a, b)
382
+ e2 = Default.create_edge(b, a)
380
383
  assert !e2
381
- assert_raises(ActiveRecord::RecordInvalid) { e3 = Default.create_edge!(b,a) }
384
+ assert_raises(ActiveRecord::RecordInvalid) { e3 = Default.create_edge!(b, a) }
382
385
  end
383
-
386
+
384
387
  #Tests that we catch self to self links on creation (self cycles)
385
388
  def test_validation_on_create_short_cycle_catch
386
389
  a = Node.create!
387
390
  b = Node.create!
388
- e = Default.create_edge(a,a)
391
+ e = Default.create_edge(a, a)
389
392
  assert !e
390
- assert_raises(ActiveRecord::RecordInvalid) { e = Default.create_edge!(a,a) }
393
+ assert_raises(ActiveRecord::RecordInvalid) { e = Default.create_edge!(a, a) }
391
394
  end
392
-
395
+
393
396
  #Tests that a direct edge with 1 count cannot be made indirect on update
394
397
  def test_validation_on_update_indirect_catch
395
398
  a = Node.create!
396
399
  b = Node.create!
397
- e = Default.create_edge!(a,b)
400
+ e = Default.create_edge!(a, b)
398
401
  e.make_indirect
399
402
  assert !e.save
400
403
  assert_raises(ActiveRecord::RecordInvalid) { e.save! }
401
404
  end
402
-
405
+
403
406
  #Tests that nochanges fails save and save!
404
407
  def test_validation_on_update_no_change_catch
405
408
  a = Node.create!
406
409
  b = Node.create!
407
- e = Default.create_edge!(a,b)
410
+ e = Default.create_edge!(a, b)
408
411
  assert !e.save
409
412
  assert_raises(ActiveRecord::RecordInvalid) { e.save! }
410
413
  end
411
-
414
+
412
415
  #Tests that destroyable? works as required
413
416
  def tests_destroyable
414
417
  a = Node.create!
415
418
  b = Node.create!
416
- e = Default.create_edge!(a,b)
419
+ e = Default.create_edge!(a, b)
417
420
  assert e.destroyable?
418
421
  c = Node.create!
419
- f = Default.create_edge!(b,c)
420
- assert !Default.find_link(a,c).destroyable?
422
+ f = Default.create_edge!(b, c)
423
+ assert !Default.find_link(a, c).destroyable?
421
424
  end
422
-
425
+
423
426
  #Tests that destroy link works
424
427
  def tests_destroy_link
425
428
  a = Node.create!
426
429
  b = Node.create!
427
- e = Default.create_edge!(a,b)
430
+ e = Default.create_edge!(a, b)
428
431
  e.destroy
429
- assert Default.find_edge(a,b).nil?
430
- e = Default.create_edge!(a,b)
432
+ assert Default.find_edge(a, b).nil?
433
+ e = Default.create_edge!(a, b)
431
434
  c = Node.create!
432
- f = Default.create_edge!(b,c)
433
- assert_raises(ActiveRecord::ActiveRecordError) { Default.find_link(a,c).destroy }
435
+ f = Default.create_edge!(b, c)
436
+ assert_raises(ActiveRecord::ActiveRecordError) { Default.find_link(a, c).destroy }
434
437
  end
435
-
438
+
436
439
  #Tests the balancing of a graph in the transitive simple case
437
440
  def test_create_pair_link_transitive
438
441
  a = Node.create!
439
442
  b = Node.create!
440
443
  c = Node.create!
441
- e = Default.create_edge!(a,b)
442
- f = Default.create_edge!(b,c)
443
- g = Default.find_link(a,c)
444
- h = Default.find_edge(a,c)
444
+ e = Default.create_edge!(a, b)
445
+ f = Default.create_edge!(b, c)
446
+ g = Default.find_link(a, c)
447
+ h = Default.find_edge(a, c)
445
448
  assert_equal g.ancestor, a
446
449
  assert_equal g.descendant, c
447
450
  assert_nil h
448
451
  end
449
-
452
+
450
453
  #Tests the ability to make an indirect link direct
451
454
  def test_make_direct_link
452
455
  a = Node.create!
453
456
  b = Node.create!
454
457
  c = Node.create!
455
- e = Default.create_edge!(a,b)
456
- f = Default.create_edge!(b,c)
457
- g = Default.find_link(a,c)
458
+ e = Default.create_edge!(a, b)
459
+ f = Default.create_edge!(b, c)
460
+ g = Default.find_link(a, c)
458
461
  g.make_direct
459
462
  g.save!
460
463
  assert_equal true, g.direct?
461
464
  assert_equal 2, g.count
462
465
  end
463
-
466
+
464
467
  #Tests the ability to make a direct link indirect
465
468
  def test_make_indirect_link
466
469
  a = Node.create!
467
470
  b = Node.create!
468
471
  c = Node.create!
469
- e = Default.create_edge!(a,b)
470
- f = Default.create_edge!(b,c)
471
- g = Default.find_link(a,c)
472
+ e = Default.create_edge!(a, b)
473
+ f = Default.create_edge!(b, c)
474
+ g = Default.find_link(a, c)
472
475
  g.make_direct
473
476
  g.save!
474
477
  g.make_indirect
@@ -476,68 +479,68 @@ class DagTest < Test::Unit::TestCase
476
479
  assert_equal false, g.direct?
477
480
  assert_equal 1, g.count
478
481
  end
479
-
482
+
480
483
  #Tests advanced transitive cases for chain graph rebalancing
481
484
  def test_create_chain_disjoint
482
485
  a = Node.create!
483
486
  b = Node.create!
484
487
  c = Node.create!
485
488
  d = Node.create!
486
- e = Default.create_edge!(a,b)
487
- f = Default.create_edge!(c,d)
488
- g = Default.create_edge!(b,c)
489
+ e = Default.create_edge!(a, b)
490
+ f = Default.create_edge!(c, d)
491
+ g = Default.create_edge!(b, c)
489
492
  #a to c
490
- test = Default.find_link(a,c)
491
- testnil = Default.find_edge(a,c)
493
+ test = Default.find_link(a, c)
494
+ testnil = Default.find_edge(a, c)
492
495
  assert_equal test.ancestor, a
493
496
  assert_equal test.descendant, c
494
497
  assert_nil testnil
495
498
  #a to d
496
- test = Default.find_link(a,d)
497
- testnil = Default.find_edge(a,d)
499
+ test = Default.find_link(a, d)
500
+ testnil = Default.find_edge(a, d)
498
501
  assert_equal test.ancestor, a
499
502
  assert_equal test.descendant, d
500
503
  assert_nil testnil
501
504
  #b to d
502
- test = Default.find_link(b,d)
503
- testnil = Default.find_edge(b,d)
505
+ test = Default.find_link(b, d)
506
+ testnil = Default.find_edge(b, d)
504
507
  assert_equal test.ancestor, b
505
508
  assert_equal test.descendant, d
506
509
  assert_nil testnil
507
510
  end
508
-
511
+
509
512
  #Tests class method connect
510
513
  def test_manual_connect_lonely_edge
511
514
  a = Node.create!
512
515
  b = Node.create!
513
- e = Default.connect!(a,b)
514
- e2 = Default.find_edge(a,b)
516
+ e = Default.connect!(a, b)
517
+ e2 = Default.find_edge(a, b)
515
518
  assert e2.direct?
516
519
  assert_equal 1, e2.count
517
- assert_equal e,e2
520
+ assert_equal e, e2
518
521
  assert_equal e2.ancestor, a
519
522
  assert_equal e2.descendant, b
520
523
  end
521
-
524
+
522
525
  #Tests simple indirect link creation
523
526
  def test_auto_simple_cross
524
527
  a = Node.create!
525
528
  b = Node.create!
526
529
  c = Node.create!
527
- e = Default.connect(a,b)
528
- e2 = Default.connect(b,c)
529
- indirect = Default.find_link(a,c)
530
+ e = Default.connect(a, b)
531
+ e2 = Default.connect(b, c)
532
+ indirect = Default.find_link(a, c)
530
533
  assert !indirect.nil?
531
534
  assert !indirect.direct?
532
535
  assert_equal 1, indirect.count
533
536
  assert_equal a, indirect.ancestor
534
- assert_equal c, indirect.descendant
537
+ assert_equal c, indirect.descendant
535
538
  end
536
-
539
+
537
540
  ##########################
538
541
  #TESTS FOR has_dag_links #
539
542
  ##########################
540
-
543
+
541
544
  #Tests has_many links_as_ancestor
542
545
  def test_has_many_links_as_ancestor
543
546
  a = Node.create!
@@ -548,7 +551,7 @@ class DagTest < Test::Unit::TestCase
548
551
  assert_equal e.ancestor, a
549
552
  assert_equal e.descendant, b
550
553
  end
551
-
554
+
552
555
  #Tests has_many links_as_descendant
553
556
  def test_has_many_links_as_descendant
554
557
  a = Node.create!
@@ -559,7 +562,7 @@ class DagTest < Test::Unit::TestCase
559
562
  assert_equal e.ancestor, a
560
563
  assert_equal e.descendant, b
561
564
  end
562
-
565
+
563
566
  #Tests has_many links_as_parent
564
567
  def test_has_many_links_as_parent
565
568
  a = Node.create!
@@ -570,7 +573,7 @@ class DagTest < Test::Unit::TestCase
570
573
  assert_equal e.ancestor, a
571
574
  assert_equal e.descendant, b
572
575
  end
573
-
576
+
574
577
  #Tests has_many links_as_child
575
578
  def test_has_many_links_as_child
576
579
  a = Node.create!
@@ -581,43 +584,43 @@ class DagTest < Test::Unit::TestCase
581
584
  assert_equal e.ancestor, a
582
585
  assert_equal e.descendant, b
583
586
  end
584
-
587
+
585
588
  #Tests has_many descendants
586
589
  def test_has_many_descendants
587
590
  a = Node.create!
588
591
  b = Node.create!
589
592
  a.descendants << b
590
- e = Default.find_link(a,b)
591
- assert !e.nil?
593
+ e = Default.find_link(a, b)
594
+ assert !e.nil?
592
595
  end
593
-
596
+
594
597
  #Tests has_many ancestors
595
598
  def test_has_many_ancestors
596
599
  a = Node.create!
597
600
  b = Node.create!
598
601
  b.ancestors << a
599
- e = Default.find_link(a,b)
600
- assert !e.nil?
602
+ e = Default.find_link(a, b)
603
+ assert !e.nil?
601
604
  end
602
-
605
+
603
606
  #Tests has_many children
604
607
  def test_has_many_children
605
608
  a = Node.create!
606
609
  b = Node.create!
607
610
  a.children << b
608
- e = Default.find_link(a,b)
609
- assert !e.nil?
611
+ e = Default.find_link(a, b)
612
+ assert !e.nil?
610
613
  end
611
-
614
+
612
615
  #Tests has_many parents
613
616
  def test_has_many_parents
614
617
  a = Node.create!
615
618
  b = Node.create!
616
619
  b.parents << a
617
- e = Default.find_link(a,b)
618
- assert !e.nil?
619
- end
620
-
620
+ e = Default.find_link(a, b)
621
+ assert !e.nil?
622
+ end
623
+
621
624
  #Tests leaf? instance method
622
625
  def test_leaf_instance_method
623
626
  a = Node.create!
@@ -629,7 +632,7 @@ class DagTest < Test::Unit::TestCase
629
632
  assert !a.leaf?
630
633
  assert b.leaf?
631
634
  end
632
-
635
+
633
636
  #Tests root? instance method
634
637
  def test_root_instance_method
635
638
  a = Node.create!
@@ -641,7 +644,7 @@ class DagTest < Test::Unit::TestCase
641
644
  assert !b.root?
642
645
  assert a.root?
643
646
  end
644
-
647
+
645
648
  #Tests has_many links_as_ancestor
646
649
  def test_has_many_links_as_ancestor_poly
647
650
  a = BetaNode.create!
@@ -652,7 +655,7 @@ class DagTest < Test::Unit::TestCase
652
655
  assert_equal e.ancestor, a
653
656
  assert_equal e.descendant, b
654
657
  end
655
-
658
+
656
659
  #Tests has_many links_as_descendant
657
660
  def test_has_many_links_as_descendant_poly
658
661
  a = BetaNode.create!
@@ -663,7 +666,7 @@ class DagTest < Test::Unit::TestCase
663
666
  assert_equal e.ancestor, a
664
667
  assert_equal e.descendant, b
665
668
  end
666
-
669
+
667
670
  #Tests has_many links_as_parent
668
671
  def test_has_many_links_as_parent_poly
669
672
  a = BetaNode.create!
@@ -674,7 +677,7 @@ class DagTest < Test::Unit::TestCase
674
677
  assert_equal e.ancestor, a
675
678
  assert_equal e.descendant, b
676
679
  end
677
-
680
+
678
681
  #Tests has_many links_as_child
679
682
  def test_has_many_links_as_child_poly
680
683
  a = BetaNode.create!
@@ -685,7 +688,7 @@ class DagTest < Test::Unit::TestCase
685
688
  assert_equal e.ancestor, a
686
689
  assert_equal e.descendant, b
687
690
  end
688
-
691
+
689
692
  #Tests leaf? instance method
690
693
  def test_leaf_instance_method_poly
691
694
  a = BetaNode.create!
@@ -697,7 +700,7 @@ class DagTest < Test::Unit::TestCase
697
700
  assert !a.leaf?
698
701
  assert b.leaf?
699
702
  end
700
-
703
+
701
704
  #Tests root? instance method
702
705
  def test_root_instance_method_poly
703
706
  a = BetaNode.create!
@@ -709,7 +712,7 @@ class DagTest < Test::Unit::TestCase
709
712
  assert !b.root?
710
713
  assert a.root?
711
714
  end
712
-
715
+
713
716
  #Tests has_many links_as_ancestor_for_*
714
717
  def test_has_many_links_as_ancestor_for
715
718
  a = AlphaNode.create!
@@ -720,7 +723,7 @@ class DagTest < Test::Unit::TestCase
720
723
  assert_equal e.ancestor, a
721
724
  assert_equal e.descendant, b
722
725
  end
723
-
726
+
724
727
  #Tests has_many links_as_descendant_for_*
725
728
  def test_has_many_links_as_descendant_for
726
729
  a = AlphaNode.create!
@@ -731,7 +734,7 @@ class DagTest < Test::Unit::TestCase
731
734
  assert_equal e.ancestor, a
732
735
  assert_equal e.descendant, b
733
736
  end
734
-
737
+
735
738
  #Tests has_many links_as_parent_for_*
736
739
  def test_has_many_links_as_parent_for
737
740
  a = AlphaNode.create!
@@ -742,7 +745,7 @@ class DagTest < Test::Unit::TestCase
742
745
  assert_equal e.ancestor, a
743
746
  assert_equal e.descendant, b
744
747
  end
745
-
748
+
746
749
  #Tests has_many links_as_child_for_*
747
750
  def test_has_many_links_as_child_for
748
751
  a = AlphaNode.create!
@@ -753,43 +756,43 @@ class DagTest < Test::Unit::TestCase
753
756
  assert_equal e.ancestor, a
754
757
  assert_equal e.descendant, b
755
758
  end
756
-
759
+
757
760
  #Tests has_many descendant_type
758
761
  def test_has_many_descendant_dvds
759
762
  a = AlphaNode.create!
760
763
  b = BetaNode.create!
761
764
  a.descendant_beta_nodes << b
762
- e = Poly.find_link(a,b)
763
- assert !e.nil?
765
+ e = Poly.find_link(a, b)
766
+ assert !e.nil?
764
767
  end
765
-
768
+
766
769
  #Tests has_many ancestor_type
767
770
  def test_has_many_ancestor_dvds
768
771
  a = AlphaNode.create!
769
772
  b = BetaNode.create!
770
773
  b.ancestor_alpha_nodes << a
771
- e = Poly.find_link(a,b)
772
- assert !e.nil?
774
+ e = Poly.find_link(a, b)
775
+ assert !e.nil?
773
776
  end
774
-
777
+
775
778
  #Tests has_many child_dvds
776
779
  def test_has_many_child_dvds
777
780
  a = AlphaNode.create!
778
781
  b = BetaNode.create!
779
782
  a.child_beta_nodes << b
780
- e = Poly.find_link(a,b)
781
- assert !e.nil?
783
+ e = Poly.find_link(a, b)
784
+ assert !e.nil?
782
785
  end
783
-
786
+
784
787
  #Tests has_many parents
785
788
  def test_has_many_parent_dvds
786
789
  a = AlphaNode.create!
787
790
  b = BetaNode.create!
788
791
  b.parent_alpha_nodes << a
789
- e = Poly.find_link(a,b)
790
- assert !e.nil?
791
- end
792
-
792
+ e = Poly.find_link(a, b)
793
+ assert !e.nil?
794
+ end
795
+
793
796
  #Tests leaf_for_*? instance method
794
797
  def test_leaf_for_instance_method
795
798
  a = BetaNode.create!
@@ -800,7 +803,7 @@ class DagTest < Test::Unit::TestCase
800
803
  b.reload
801
804
  assert !b.leaf_for_beta_nodes?
802
805
  end
803
-
806
+
804
807
  #Tests root_for_*? instance method
805
808
  def test_root_for_instance_method
806
809
  a = BetaNode.create!
@@ -811,42 +814,4 @@ class DagTest < Test::Unit::TestCase
811
814
  b.reload
812
815
  assert !b.root_for_beta_nodes?
813
816
  end
814
- #Tests that longest_path_between works
815
- def test_longest_path_between
816
- a = Node.create!
817
- b = Node.create!
818
- c = Node.create!
819
- d = Node.create!
820
- e = Default.create_edge(a,b)
821
- e = Default.create_edge(b,c)
822
- e = Default.create_edge(a,c)
823
- e = Default.create_edge(c,d)
824
- path = Default.longest_path_between(a,d)
825
- assert_equal [b,c,d], path
826
- end
827
-
828
- #Tests that shortest_path_between works
829
- def test_shortest_path_between
830
- a = Node.create!
831
- b = Node.create!
832
- c = Node.create!
833
- d = Node.create!
834
- e = Default.create_edge(a,b)
835
- e = Default.create_edge(b,c)
836
- e = Default.create_edge(a,c)
837
- e = Default.create_edge(c,d)
838
- path = Default.shortest_path_between(a,d)
839
- assert_equal [c,d], path
840
- end
841
-
842
- # Tests that perpetuate upon destroy works
843
- def tests_perpetuate_upon_destroy_link
844
- a = Node.create!
845
- b = Node.create!
846
- c = Node.create!
847
- e = Default.create_edge!(a,b)
848
- f = Default.create_edge!(b,c)
849
- e.destroy
850
- end
851
-
852
817
  end