Sha256: f283282844ee951e884d9119ae373dc44f5fec05fad4b6a94a7c9e4819b8d586

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

require 'utc_rpn_calc'

describe UtcRpnCalc::Calculator do

  subject do
    UtcRpnCalc::Calculator.new(input).calculate
  end

  describe 'operations' do

    context 'addition' do
      let(:input) { "1 2 +" }
      it { should eq("0003") }
    end

    context 'subtraction' do
      let(:input) { "F 1 -" }
      it { should eq("000E") }
    end

    context 'multiplication' do
      let(:input) { "3 2 *" }
      it { should eq("0006") }
    end

    context 'division' do
      let(:input) { "6 2 /" }
      it { should eq("0003") }
    end

    context 'logical AND' do
      let(:input) { "FF00 0FF0 &" }
      it { should eq("0F00") }
    end

    context 'logical OR' do
      let(:input) { "FF00 0FF0 |" }
      it { should eq("FFF0") }
    end

    context 'logical XOR' do
      let(:input) { "FF00 0FF0 X" }
      it { should eq("F0F0") }
    end

    context 'logical NOT' do
      let(:input) { "00FF ~" }
      it { should eq("FF00") }
    end

    context 'multiple operations' do
      let(:input) { "2 3 * 4 +" }
      it { should eq("000A") }
    end

  end

  describe 'return value' do

    context 'when input is valid' do

      context 'result greater than FFFF' do
        let(:input) { "ABCD ABCD +" }
        it { should eq("FFFF") }
      end

      context 'result less than 0000' do
        let(:input) { "5 A -" }
        it { should eq("0000") }
      end

    end

    context 'when input is invalid' do
      let(:input) { "2 * 3" }
      it { should eq("BLARGH!") }
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
utc_rpn_calc-0.1.0 spec/lib/calculator_spec.rb
utc_rpn_calc-0.0.1 spec/calculator_spec.rb