Sha256: b96a70498de420545d95603fbf79f3a920376795c6c9b9d994c81442b7f544ae

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require "test_helper"

module Whitespace
  describe Stack do
    before do
      @stack = Stack.new
    end

    describe "#push" do
      it "places an element on top the stack" do
        @stack.push :a
        @stack.push :b

        expect(@stack.top).must_equal :b
      end
    end

    describe "#pop" do
      describe "when the stack is empty" do
        it "raises Whitespace::EmptyError" do
          expect { @stack.pop }.must_raise EmptyError
        end
      end

      describe "when the stack is not empty" do
        it "removes and returns the top element" do
          @stack.push :a
          @stack.push :b

          expect(@stack.pop).must_equal :b
          expect(@stack.top).must_equal :a
        end
      end
    end

    describe "#top" do
      describe "when the stack is empty" do
        it "raises Whitespace::EmptyError" do
          expect { @stack.top }.must_raise EmptyError
        end
      end

      describe "when the stack is not empty" do
        it "returns the top element" do
          @stack.push :a
          expect(@stack.top).must_equal :a
        end
      end
    end

    describe "#size" do
      it "returns the number of elements on the stack" do
        expect(@stack.size).must_equal 0

        @stack.push :a
        @stack.push :b
        @stack.push :c

        expect(@stack.size).must_equal 3
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
whitespace-ruby-1.0.0 test/whitespace/data_structures/stack_test.rb