Permalink
Browse files

Add vertex name spec

  • Loading branch information...
D4L committed Aug 10, 2012
1 parent 9209171 commit b6b5ba6f43849b16b4f0a09866ac5f5cc71a6440
@@ -5,6 +5,12 @@ module Composition
# public Vertex class
class Vertex
+ attr_reader :name
+
+ def name=(name)
+ raise ArgumentError if name.class != String
+ @name = name
+ end
end
end
@@ -4,7 +4,8 @@ module AbstractGraph
module Composition
class Vertex
- def initialize name=""
+ def initialize (name="", value="")
+ @name = name
end
@@ -25,4 +25,16 @@
end
+ describe "#new(String, Object)" do
+
+ before (:each) do
+ @vertex = AbstractGraph::Composition::Vertex.new("v1", "Hello")
+ end
+
+ it "allows vertices to be initiated with name and value" do
+ @vertex.should_not be_nil
+ end
+
+ end
+
end
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe AbstractGraph::Composition::Vertex do
+ describe "#name" do
+
+ before (:each) do
+ @arbitraryString = "abitraryString"
+ @vertex = AbstractGraph::Composition::Vertex.new(@arbitraryString)
+ end
+
+ it "returns a String (Always)" do
+ @vertex.name.should be_an_instance_of(String)
+ end
+
+ it "equals to the String in #new(String)" do
+ @vertex.name.should eql(@arbitraryString)
+ end
+
+ end
+
+ describe "#name=" do
+
+ before (:each) do
+ @vertex = AbstractGraph::Composition::Vertex.new()
+ end
+
+ it "names the vertex and retrieved by #name" do
+ @vertex.name = "Hello World"
+ @vertex.name.should eql("Hello World")
+ end
+
+ it "doesn't allow a non-String input" do
+ expect { @vertex.name = 100 }.to raise_error
+ end
+
+ end
+end
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe AbstractGraph::Composition::Vertex do
+ describe "#value" do
+
+ end
+
+ describe "#value=" do
+ end
+end

0 comments on commit b6b5ba6

Please sign in to comment.