Skip to content

Instantly share code, notes, and snippets.

@jontonsoup
Last active August 29, 2015 14:08
Show Gist options
  • Save jontonsoup/29124d1015b58bebc1b7 to your computer and use it in GitHub Desktop.
Save jontonsoup/29124d1015b58bebc1b7 to your computer and use it in GitHub Desktop.
An example stack for Williamson
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
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