mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/tsort.rb: Returns an enumerator if no block is given.
[ruby-core:66270] [Feature #10508] Proposed by Andrey Savchenko. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eab191040e
commit
0eadc632c1
3 changed files with 26 additions and 6 deletions
|
@ -57,6 +57,9 @@ class TSortTest < Test::Unit::TestCase # :nodoc:
|
|||
r = []
|
||||
TSort.tsort_each(each_node, each_child) {|n| r << n }
|
||||
assert_equal([4, 2, 3, 1], r)
|
||||
|
||||
r = TSort.tsort_each(each_node, each_child).map {|n| n.to_s }
|
||||
assert_equal(['4', '2', '3', '1'], r)
|
||||
end
|
||||
|
||||
def test_s_strongly_connected_components
|
||||
|
@ -85,6 +88,11 @@ class TSortTest < Test::Unit::TestCase # :nodoc:
|
|||
r << scc
|
||||
}
|
||||
assert_equal([[4], [2, 3], [1]], r)
|
||||
|
||||
r = TSort.each_strongly_connected_component(each_node, each_child).map {|scc|
|
||||
scc.map(&:to_s)
|
||||
}
|
||||
assert_equal([['4'], ['2', '3'], ['1']], r)
|
||||
end
|
||||
|
||||
def test_s_each_strongly_connected_component_from
|
||||
|
@ -95,6 +103,11 @@ class TSortTest < Test::Unit::TestCase # :nodoc:
|
|||
r << scc
|
||||
}
|
||||
assert_equal([[4], [2, 3], [1]], r)
|
||||
|
||||
r = TSort.each_strongly_connected_component_from(1, each_child).map {|scc|
|
||||
scc.map(&:to_s)
|
||||
}
|
||||
assert_equal([['4'], ['2', '3'], ['1']], r)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue