Permalink
Browse files

Add value tests and delete method on vertex

  • Loading branch information...
1 parent 9e634da commit c2b78f86f65fd69a230b9761e68e9b1e6d2c0f28 @D4L committed Aug 16, 2012
@@ -6,6 +6,7 @@ module Composition
# public Vertex class
class Vertex
attr_reader :name
+ attr_accessor :value
@@names = []
def name=(name)
@@ -21,3 +22,4 @@ def name=(name)
end
require "abstract_graph/composition/vertex/initialize"
+require "abstract_graph/composition/vertex/delete"
@@ -0,0 +1,14 @@
+# required in "abstract_graph/composition/vertex"
+
+module AbstractGraph
+ module Composition
+ class Vertex
+
+ def delete
+ @@names.delete @name
+ nil
+ end
+
+ end
+ end
+end
@@ -4,8 +4,9 @@ module AbstractGraph
module Composition
class Vertex
- def initialize (name="", value="")
+ def initialize (name="", value=nil)
@name = name
+ @value = value
if @@names.include? name
raise Exception
end
@@ -0,0 +1,18 @@
+require 'spec_helper'
+
+describe AbstractGraph::Composition::Vertex do
+
+ before :each do
+ AbstractGraph::Composition::Vertex.class_variable_set :@@names, []
+ end
+
+ describe "#delete" do
+
+ it "removes the name of the vertex in the namespace" do
+ vertex = AbstractGraph::Composition::Vertex.new("v1")
+ vertex.delete
+ AbstractGraph::Composition::Vertex.class_variable_get(:@@names).should eql([])
+ end
+
+ end
+end
@@ -1,7 +1,7 @@
require 'spec_helper'
describe AbstractGraph::Composition::Vertex do
-
+
before :each do
AbstractGraph::Composition::Vertex.class_variable_set :@@names, []
end
@@ -21,6 +21,11 @@
@vertex.name.should eql(@arbitraryString)
end
+ it "equals to \"\" if nothing was passed as first param" do
+ @vertex2 = AbstractGraph::Composition::Vertex.new()
+ @vertex2.name.should eql("")
+ end
+
end
describe "#name=" do
@@ -53,8 +58,14 @@
end
end
- it "can assign a name after delete removes it" do
- pending "delete method"
+ it "can reuse a name after delete removes it" do
+ @vertex.name = "v1"
+ @vertex.delete
+ begin
+ vertex2 = AbstractGraph::Composition::Vertex.new("v1")
+ rescue Exception => e
+ fail
+ end
end
end
@@ -1,9 +1,46 @@
require 'spec_helper'
describe AbstractGraph::Composition::Vertex do
+
+ before :each do
+ AbstractGraph::Composition::Vertex.class_variable_set :@@names, []
+ end
+
describe "#value" do
+
+ before (:each) do
+ @arbitraryString = "arbitraryString"
+ @arbitraryObject = Object.new
+ end
+
+ it "equals the object passed in #new(String, Object)" do
+ vertex = AbstractGraph::Composition::Vertex.new(@arbitraryString, @arbitraryObject)
+ vertex.value.should eql(@arbitraryObject)
+ end
+
+ it "equals to nil if nothing was passed as second param" do
+ vertex = AbstractGraph::Composition::Vertex.new()
+ vertex.value.should be_nil
+ end
+
end
describe "#value=" do
+
+ before (:each) do
+ @vertex = AbstractGraph::Composition::Vertex.new()
+ end
+
+ it "allows us to change the value of the vertex" do
+ @vertex.value = 2
+ @vertex.value.should eql(2)
+ end
+
+ it "allows us to create two vertices of the same object" do
+ @vertex.value = "Hello"
+ @vertex2 = AbstractGraph::Composition::Vertex.new("v2", "Hello")
+ @vertex.value.should eql(@vertex2.value)
+ end
+
end
end

0 comments on commit c2b78f8

Please sign in to comment.