Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dubadub committed Jun 7, 2014
1 parent 675f06a commit 2def44f
Showing 1 changed file with 11 additions and 39 deletions.
50 changes: 11 additions & 39 deletions spec/lib/topo_sort_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,44 @@
it "should sort nothing" do
nodes = {}
sorted = TopoSort.sort(nodes)
sorted.should == []
expect(sorted).to match_array([])
end

it "should sort one node without dependencies" do
nodes = {
a: nil
}
nodes = { :a => nil }

sorted = TopoSort.sort(nodes)
sorted.should == [:a]
expect(sorted).to match_array([:a])
end

it "should sort several nodes without dependencies" do
nodes = {
a: nil,
b: nil,
c: nil
}
nodes = { :a => nil, :b => nil, :c => nil }

sorted = TopoSort.sort(nodes)
sorted.should == [:a, :b, :c]
expect(sorted).to match_array([:a, :b, :c])
end

it "should sort several nodes with one that has dependency" do
nodes = {
a: nil,
b: :c,
c: nil
}
nodes = { :a => nil, :b => :c, :c => nil }

sorted = TopoSort.sort(nodes)
sorted.should == [:a, :c, :b]
expect(sorted).to match_array([:a, :c, :b])
end

it "should sort several nodes with several nodes that have dependency" do
nodes = {
a: nil,
b: :c,
c: :f,
d: :a,
e: :b,
f: nil
}
nodes = { :a => nil, :b => :c, :c => :f, :d => :a, :e => :b, :f => nil }

sorted = TopoSort.sort(nodes)
sorted.should == [:a, :f, :c, :b, :d, :e]
expect(sorted).to match_array([:a, :f, :c, :b, :d, :e])
end

it "should raise error when node depends on themselve" do
nodes = {
a: nil,
b: nil,
c: :c
}
nodes = { :a => nil, :b => nil, :c => :c }
expect { TopoSort.sort(nodes) }.to raise_error(TopoSort::SelfDependency, /sort failed: detected self-dependency/)
end

it "should raise error when circular dependency is presented" do
nodes = {
a: nil,
b: :c,
c: :f,
d: :a,
e: nil,
f: :b
}
nodes = { :a => nil, :b => :c, :c => :f, :d => :a, :e => nil, :f => :b }
expect { TopoSort.sort(nodes) }.to raise_error(TopoSort::Cyclic, /sort failed: detected cyclic dependency/)
end
end

0 comments on commit 2def44f

Please sign in to comment.