-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.rb
46 lines (38 loc) · 1.08 KB
/
testing.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'test/unit'
require './graph.rb'
require './bfs.rb'
class TestGraph < Test::Unit::TestCase
def setup
@graph = Graph.new('red.txt')
@nodes = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
@edges = [['A', 'B'], ['B', 'C'], ['C', 'D'], ['D', 'E'], ['E', 'F'], ['C', 'G'], ['G', 'H'], ['H', 'I'], ['I', 'F']]
end
def test_nodes
keys = @graph.nodes.keys
@nodes.each do |node|
assert_include(keys, node)
end
end
def recolect_names(neighbors)
array_names = []
neighbors.each do |neighbor|
array_names << neighbor.name
end
return array_names
end
def test_edges
@edges.each do |edge|
neighbors = @graph.nodes[edge[0]].neighbors
neighbor_names = recolect_names(neighbors)
assert_include(neighbor_names, edge[1])
end
end
def test_bfs
best_road_test = ['A', 'B', 'C', 'H', 'F']
start_node = @graph.nodes['A']
final_node = @graph.nodes['F']
bfs = BFS.new(start_node, final_node, @graph.nodes, 'red')
best_road = bfs.get_best_road()
assert_equal(best_road_test, best_road)
end
end