Created
October 29, 2013 10:51
-
-
Save meaganewaller/7212448 to your computer and use it in GitHub Desktop.
LSP
This file contains 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
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