Skip to content

Instantly share code, notes, and snippets.

@meaganewaller
Created October 29, 2013 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meaganewaller/7212448 to your computer and use it in GitHub Desktop.
Save meaganewaller/7212448 to your computer and use it in GitHub Desktop.
LSP
class Rectangle
attr_reader :width, :height
def initialize(width, height)
@width = width
@height = height
end
def area
@width * @height
end
end
class Square < Rectangle
def initialize(side)
super(side, side)
end
end
describe "testing LSP" do
it "returns right area for a rectangle" do
rect = Rectangle.new(10, 8)
rect.area.should == 80
end
it "returns the right area for a square" do
sq = Square.new(5)
sq.area.should == 25
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment