Skip to content
This repository
Browse code

Add Edge#name tests and implementation

  • Loading branch information...
commit a124e64ce0e428ebe3664f7772ef95e984814e43 1 parent f830270
Austin on Cygwin authored
1  .gitignore
... ... @@ -1,3 +1,4 @@
  1 +*.swp
1 2 *.gem
2 3 *.rbc
3 4 .bundle
8 lib/abstract_graph/composition/edge.rb
@@ -5,7 +5,15 @@ module Composition
5 5
6 6 # public Edge class
7 7 class Edge
  8 + attr_reader :name
  9 +
  10 + def name=(name)
  11 + raise ArgumentError if name.class != String
  12 + @name = name
  13 + end
8 14
9 15 end
10 16 end
11 17 end
  18 +
  19 +require "abstract_graph/composition/edge/initialize"
13 lib/abstract_graph/composition/edge/initialize.rb
... ... @@ -0,0 +1,13 @@
  1 +# required in "abstract_graph/composition/edge"
  2 +
  3 +module AbstractGraph
  4 + module Composition
  5 + class Edge
  6 +
  7 + def initialize ( name = "" )
  8 + @name = name
  9 + end
  10 +
  11 + end
  12 + end
  13 +end
28 spec/abstract_graph/composition/edge/initialize_spec.rb
... ... @@ -0,0 +1,28 @@
  1 +require 'spec_helper'
  2 +
  3 +describe AbstractGraph::Composition::Edge do
  4 +
  5 + describe "#new" do
  6 +
  7 + before :each do
  8 + @edge = AbstractGraph::Composition::Edge.new
  9 + end
  10 +
  11 + it "returns an object of class Edge" do
  12 + @edge.should be_an_instance_of(AbstractGraph::Composition::Edge)
  13 + end
  14 +
  15 + end
  16 +
  17 + describe "#new(String)" do
  18 + before :each do
  19 + @edge = AbstractGraph::Composition::Edge.new("e1")
  20 + end
  21 +
  22 + it "allows vertices to be initiated with a string name" do
  23 + @edge.should_not be_nil
  24 + end
  25 +
  26 + end
  27 +
  28 +end
39 spec/abstract_graph/composition/edge/name_spec.rb
... ... @@ -0,0 +1,39 @@
  1 +require 'spec_helper'
  2 +
  3 +describe AbstractGraph::Composition::Edge do
  4 +
  5 + describe "#name" do
  6 +
  7 + before :each do
  8 + @arbitraryString = "arbitraryString"
  9 + @edge = AbstractGraph::Composition::Edge.new @arbitraryString
  10 + end
  11 +
  12 + it "returns a String (Always)" do
  13 + @edge.name.should be_an_instance_of(String)
  14 + end
  15 +
  16 + it "equals to the String in #new(String)" do
  17 + @edge.name.should eql(@arbitraryString)
  18 + end
  19 +
  20 + end
  21 +
  22 + describe "#name=" do
  23 +
  24 + before :each do
  25 + @edge = AbstractGraph::Composition::Edge.new
  26 + end
  27 +
  28 + it "names the edge and retrieved by #name" do
  29 + @edge.name = "Hello World"
  30 + @edge.name.should eql("Hello World")
  31 + end
  32 +
  33 + it "doesn't allow a non-String input" do
  34 + expect { @edge.name = 100 }.to raise_error
  35 + end
  36 +
  37 + end
  38 +
  39 +end

0 comments on commit a124e64

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