Class: TSortTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TSortTest
- Defined in:
- lib/tsort.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#test_array ⇒ Object
278 279 280 281 282 283 284 285 286 |
# File 'lib/tsort.rb', line 278 def test_array a = TSortArray[[1], [0], [0], [2]] assert_equal([[0, 1], [2], [3]], a.strongly_connected_components.map {|nodes| nodes.sort}) a = TSortArray[[], [0]] assert_equal([[0], [1]], a.strongly_connected_components.map {|nodes| nodes.sort}) end |
#test_cycle ⇒ Object
271 272 273 274 275 276 |
# File 'lib/tsort.rb', line 271 def test_cycle h = TSortHash[{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}] assert_equal([[4], [2, 3], [1]], h.strongly_connected_components.map {|nodes| nodes.sort}) assert_raise(TSort::Cyclic) { h.tsort } end |
#test_dag ⇒ Object
265 266 267 268 269 |
# File 'lib/tsort.rb', line 265 def test_dag h = TSortHash[{1=>[2, 3], 2=>[3], 3=>[]}] assert_equal([3, 2, 1], h.tsort) assert_equal([[3], [2], [1]], h.strongly_connected_components) end |