-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'tsort' | ||
|
||
module Datadog | ||
class Configuration | ||
class Resolver | ||
include TSort | ||
|
||
def initialize(dependency_graph = {}) | ||
@dependency_graph = dependency_graph | ||
end | ||
|
||
def tsort_each_node(&blk) | ||
@dependency_graph.each_key(&blk) | ||
end | ||
|
||
def tsort_each_child(node, &blk) | ||
@dependency_graph.fetch(node).each(&blk) | ||
end | ||
|
||
alias call tsort | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'ddtrace/configuration' | ||
|
||
module Datadog | ||
class Configuration | ||
class ResolverTest < Minitest::Test | ||
def test_dependency_solving | ||
graph = { 1 => [2], 2 => [3, 4], 3 => [], 4 => [3], 5 => [1] } | ||
tsort = Resolver.new(graph).call | ||
|
||
assert_equal([3, 4, 2, 1, 5], tsort) | ||
end | ||
|
||
def test_cyclic_dependecy | ||
graph = { 1 => [2], 2 => [1] } | ||
|
||
assert_raises(TSort::Cyclic) do | ||
Resolver.new(graph).call | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters