Skip to content
Browse files

Add 'has_vertex' to Graph. Part of #3

  • Loading branch information...
1 parent 4835578 commit fa99fbc8cdaa7bbbcb2483f81a21f2c8b1d0be7a @D4L committed Jan 2, 2013
View
1 lib/abstract_graph/graph.rb
@@ -16,3 +16,4 @@ class Graph
require "abstract_graph/graph/initialize"
require "abstract_graph/graph/add_vertex"
+require "abstract_graph/graph/has_vertex"
View
13 lib/abstract_graph/graph/has_vertex.rb
@@ -0,0 +1,13 @@
+# required in "abstract_graph/graph"
+
+module AbstractGraph
+ class Graph
+
+ # returns whether there exists a vertex with name string
+ # p: String s represents name of query vertex
+ def has_vertex?( s )
+ @vertices.has_key? s || false
+ end
+
+ end
+end
View
1 spec/abstract_graph/composition/uniquenamecollection/method_missing_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+
module AbstractGraph
module Composition
describe UniqueNameCollection do
View
27 spec/abstract_graph/graph/has_vertex_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+module AbstractGraph
+ module Composition
+ describe Graph do
+
+ before :each do
+ @graph = Graph.new
+ end
+
+ describe "#has_vertex?(String)" do
+
+ it "returns whether the string name is a named vertex in the graph" do
+ @graph.add_vertex "MyVertex"
+ @graph.has_vertex?( "MyVertex" ).should be_true
+ end
+
+ it "returns false when the string is not a named vertex" do
+ @graph.has_vertex?( "MyVertex" ).should be_false
+ @graph.has_vertex?( "AlsoFalse" ).should_not be_nil
+ end
+
+ end
+
+ end
+ end
+end

0 comments on commit fa99fbc

Please sign in to comment.
Something went wrong with that request. Please try again.