Skip to content

Instantly share code, notes, and snippets.

@diegocasmo
Created March 20, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegocasmo/38590988e0ff649966a21a67640c018f to your computer and use it in GitHub Desktop.
Save diegocasmo/38590988e0ff649966a21a67640c018f to your computer and use it in GitHub Desktop.
Tests for the implementation of the depth first search algorithm.
require 'minitest/autorun'
require './depth_first_search_undirected'
describe DFS do
before do
graph = {
:a => [:b, :e],
:b => [:a],
:c => [:d, :g, :h],
:d => [:h, :c],
:e => [:j, :i],
:f => [],
:g => [:c, :h, :k],
:h => [:d, :l, :c, :g, :k],
:i => [:e, :j],
:j => [:e, :i],
:k => [:g, :h],
:l => [:h]
}
@dfs = DFS.new(graph)
end
describe "#dfs" do
it "should return all reachable vertices from vertex 'a'" do
assert_equal(@dfs.dfs(:a), [:b, :e, :j, :i])
end
it "should return all reachable vertices from vertex 'c'" do
assert_equal(@dfs.dfs(:c), [:d, :h, :l, :g, :k])
end
it "should return all reachable vertices from vertex 'f'" do
assert_equal(@dfs.dfs(:f), [])
end
it "should raise an error if vertex is not defined in graph" do
assert_raises(RuntimeError) { @dfs.dfs(:foo) }
end
end
end
@diegocasmo
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment