require 'spec_helper'

describe Finder do
  before do
    graph = Graph.new
    (1..6).to_a.each{|n| graph.add_node(Node.new(n)) }
    [
      [1, 2, 7], [1, 2, 7], [1, 3, 9],
      [2, 1, 7], [2, 3, 10], [2, 4, 15],
      [3, 1, 9], [3, 2, 10], [3, 4, 11], [3, 6, 2],
      [4, 2, 15], [4, 3, 11], [4, 5, 6],
      [5, 4, 6], [5, 6, 9],
      [6, 1, 14], [6, 3, 2], [6, 5, 9]
    ].each do |set|
      graph.add_edge(*set)
    end
    @graph_sample = graph
  end

  it "should get the shortest path" do
    [ [[1,6], [1,3,6]],
      [[1,5], [1,3,6,5]],
      [[1,4], [1,3,4]],
      [[4,6], [4,3,6]],
      [[4,2], [4,2]],
      [[3,5], [3,6,5]]
    ].each do |values|
      finder = Finder.new(@graph_sample)
      cheaper = finder.get_shortest_path(*values[0])
      cheaper.map(&:name).should == values[1]
    end
  end
end
