Should now ignore *~ files
[graph.njae.git] / spec / graph / edge_spec.rb~
1 require 'spec_helper'
2
3 module Graph
4 describe Edge do
5 let (:e) { Edge.new }
6 describe "#initialize" do
7 it "creates an empty edge" do
8 e = Edge.new
9 e.connections.should be_empty
10 end
11 end # #initialize
12
13 describe "adds attribues" do
14 it "adds then reports arbitrary attributes" do
15 e.score = 15
16 e.score.should == 15
17 end
18 end # adds attributes
19
20 describe "#<<" do
21 it "adds a new vertex to an edge (with a connection)" do
22 e.connections.should be_empty
23 v1 = Vertex.new
24 v2 = Vertex.new
25 e << v1
26 e.should have(1).connections
27 e.should have(1).vertices
28 e.vertices.should include(v1)
29 e << v2
30 e.should have(2).connections
31 e.should have(2).vertices
32 e.vertices.should include(v1)
33 e.vertices.should include(v2)
34 end
35
36 it "adds several vertices to an edge" do
37 e.connections.should be_empty
38 v1 = Vertex.new
39 v2 = Vertex.new
40 e << v1 << v2
41 e.vertices.should include(v1)
42 e.vertices.should include(v2)
43 e.should have(2).vertices
44 end
45
46 it "adds a self-loop" do
47 e.connections.should be_empty
48 v1 = Vertex.new
49 e << v1 << v1
50 e.vertices.should include(v1)
51 e.should have(2).vertices
52 e.vertices.uniq.length.should == 1
53 end
54 end # #<<
55
56 describe "connection_at" do
57 it "returns the connection that links to a vertex" do
58 e.connections.should be_empty
59 v1 = Vertex.new
60 v2 = Vertex.new
61 e << v1 << v2
62
63 e.connection_at(v1).end.should be v1
64 e.connection_at(v2).end.should be v2
65 end
66
67 it "returns nil if there is no connection to that vertex" do
68 e.connections.should be_empty
69 v1 = Vertex.new
70 v2 = Vertex.new
71 v3 = Vertex.new
72 e << v1 << v2
73
74 e.connection_at(v3).should be nil
75 end
76 end # #connection_at
77 end # Edge
78
79 describe Connection do
80 let (:c) {Connection.new }
81
82 describe "adds attribues" do
83 it "adds then reports arbitrary attributes" do
84 c.score = 15
85 c.score.should == 15
86 end
87 end # adds attributes
88 end # Connection
89
90 end