Skip to content
Browse files

Add Edge#name tests and implementation

  • Loading branch information...
1 parent f830270 commit a124e64ce0e428ebe3664f7772ef95e984814e43 Austin on Cygwin committed Dec 13, 2012
View
1 .gitignore
@@ -1,3 +1,4 @@
+*.swp
*.gem
*.rbc
.bundle
View
8 lib/abstract_graph/composition/edge.rb
@@ -5,7 +5,15 @@ module Composition
# public Edge class
class Edge
+ attr_reader :name
+
+ def name=(name)
+ raise ArgumentError if name.class != String
+ @name = name
+ end
end
end
end
+
+require "abstract_graph/composition/edge/initialize"
View
13 lib/abstract_graph/composition/edge/initialize.rb
@@ -0,0 +1,13 @@
+# required in "abstract_graph/composition/edge"
+
+module AbstractGraph
+ module Composition
+ class Edge
+
+ def initialize ( name = "" )
+ @name = name
+ end
+
+ end
+ end
+end
View
28 spec/abstract_graph/composition/edge/initialize_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe AbstractGraph::Composition::Edge do
+
+ describe "#new" do
+
+ before :each do
+ @edge = AbstractGraph::Composition::Edge.new
+ end
+
+ it "returns an object of class Edge" do
+ @edge.should be_an_instance_of(AbstractGraph::Composition::Edge)
+ end
+
+ end
+
+ describe "#new(String)" do
+ before :each do
+ @edge = AbstractGraph::Composition::Edge.new("e1")
+ end
+
+ it "allows vertices to be initiated with a string name" do
+ @edge.should_not be_nil
+ end
+
+ end
+
+end
View
39 spec/abstract_graph/composition/edge/name_spec.rb
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe AbstractGraph::Composition::Edge do
+
+ describe "#name" do
+
+ before :each do
+ @arbitraryString = "arbitraryString"
+ @edge = AbstractGraph::Composition::Edge.new @arbitraryString
+ end
+
+ it "returns a String (Always)" do
+ @edge.name.should be_an_instance_of(String)
+ end
+
+ it "equals to the String in #new(String)" do
+ @edge.name.should eql(@arbitraryString)
+ end
+
+ end
+
+ describe "#name=" do
+
+ before :each do
+ @edge = AbstractGraph::Composition::Edge.new
+ end
+
+ it "names the edge and retrieved by #name" do
+ @edge.name = "Hello World"
+ @edge.name.should eql("Hello World")
+ end
+
+ it "doesn't allow a non-String input" do
+ expect { @edge.name = 100 }.to raise_error
+ end
+
+ end
+
+end

0 comments on commit a124e64

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