Last active
August 29, 2015 14:08
-
-
Save jontonsoup/29124d1015b58bebc1b7 to your computer and use it in GitHub Desktop.
An example stack for Williamson
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 MyStack | |
def initialize | |
@array = Array.new() | |
end | |
def size | |
@array.size | |
end | |
def push(input) | |
@array << input | |
end | |
def pop | |
@array.delete_at(@array.size - 1) | |
end | |
end |
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
require_relative "stack" | |
RSpec.describe MyStack do | |
it "initializes to empty" do | |
stack = MyStack.new() | |
expect(stack.size).to eq 0 | |
end | |
it "adds an object when pushed" do | |
stack = MyStack.new() | |
ten = 10 | |
stack.push(ten) | |
expect(stack.size).to eq 1 | |
end | |
it "removes the last object when popped" do | |
stack = MyStack.new() | |
ten = 10 | |
stack.push(ten) | |
popped_object = stack.pop | |
expect(popped_object).to eq ten | |
expect(stack.size).to eq 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment