-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathkruskal_amb_test.rb
More file actions
58 lines (54 loc) · 1.04 KB
/
kruskal_amb_test.rb
File metadata and controls
58 lines (54 loc) · 1.04 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
require 'minitest/autorun'
require "visual_graphs"
#Test for Kruskal's algorithm for adjacency matrix based graph
class Kruskal_ambTest < Minitest::Test
include VisualGraphs
def setup
# Do nothing
end
def teardown
# Do nothing
end
def test1
matrix =
[
[0, 7, 8, -1, -1,-1],
[7, 0, 11, 2, -1, -1],
[8, 11, 0, 6, 9, -1],
[-1, 2, 6, 0, 11, 9],
[-1, -1, 9, 11, 0, 10],
[-1, -1, -1, 9, 10, 0]
]
expected =
[
[0,7,-1,-1,-1,-1],
[7,0,-1,2,-1,-1],
[-1,-1,0,6,9,-1],
[-1,2,6,0,-1,9],
[-1,-1,9,-1,0,-1],
[-1,-1,-1,9,-1,0]
]
result = kruskal matrix
assert_equal result, expected
end
def test2
matrix =
[
[0,2,-1,6,-1],
[2,0,3,8,5],
[-1,3,0,-1,7],
[6,8,-1,0,9],
[-1,5,7,9,0]
]
expected =
[
[0,2,-1,6,-1],
[2,0,3,-1,5],
[-1,3,0,-1,-1],
[6,-1,-1,0,-1],
[-1,5,-1,-1,0],
]
result = kruskal matrix
assert_equal result, expected
end
end