Created
September 19, 2012 15:54
-
-
Save jsl/3750445 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
class Node | |
attr_accessor :next | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
def circular?(start = self, current = self.next) | |
puts "\nCircular called with START = #{start} and CURRENT = #{current}" | |
if current.nil? | |
false | |
elsif start == current | |
true | |
else | |
# what does here? | |
end | |
end | |
def to_s | |
name | |
end | |
end | |
describe Node do | |
describe "#circular?" do | |
before do | |
@a = Node.new("Node A") | |
@b = Node.new("Node B") | |
@c = Node.new("Node C") | |
@d = Node.new("Node D") | |
@e = Node.new("Node E") | |
@a.next = @b | |
@b.next = @c | |
@c.next = @d | |
@d.next = @e | |
end | |
it "should return true if the list is circular" do | |
@e.next = @a | |
@a.should be_circular | |
end | |
it "should return false if the list is not circular" do | |
@a.should_not be_circular | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment