forked from jruby/jruby
/
directed_graph_spec.rb
43 lines (36 loc) · 1.04 KB
/
directed_graph_spec.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
require 'jruby'
require 'java'
require 'rspec'
import 'org.jruby.ir.util.DirectedGraph'
# This is spec for Directed Graph Library
describe "Directed Graph Utility" do
before do
@graph = DirectedGraph.new
@graph.addEdge(1,2,'simple')
@graph.addEdge(2,3,'simple')
@graph.addEdge(3,4,'simple')
@graph.addEdge(4,1,'simple')
end
it "should add an edge to newly created graph" do
@graph.edges.size.should == 4
@graph.addEdge(4,5,'simple')
@graph.edges.size.should == 5
end
it "should remove an existing edge from a graph" do
@graph.edges.size.should == 4
@graph.removeEdge(1,2)
@graph.edges.size.should == 3
end
it "should not delete a non-existent edge from the graph" do
@graph.edges.size.should == 4
@graph.removeEdge(2,1)
@graph.edges.size.should == 4
end
it "should remove a vertex and its associated edges" do
@graph.removeVertexFor(3)
@graph.edges.size.should == 2
@graph.vertices.size.should == 3
@graph.removeVertexFor(2)
@graph.vertices.size.should == 2
end
end