Sha256: 9ddce244448fd4305af2b5816ef2ecf2bd55af7e83f181656f8ab657bdfab85f

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require_relative '../spec_helper' # Use the RSpec framework
require_relative '../../lib/mini_kraken/core/k_symbol'

# Load the class under test
require_relative '../../lib/mini_kraken/core/cons_cell'

module MiniKraken
  module Core
    describe ConsCell do
      let(:pea) { KSymbol.new(:pea) }
      let(:pod) { KSymbol.new(:pod) }
      subject { ConsCell.new(pea, pod) }

      context 'Initialization:' do
        it 'could be initialized with one argument' do
          expect { ConsCell.new(pea) }.not_to raise_error
        end

        it 'could be initialized with a second optional argument' do
          expect { ConsCell.new(pea, pod) }.not_to raise_error
        end

        it 'should know its car child' do
          expect(subject.car).to eq(pea)
        end

        it 'should know its cdr child' do
          expect(subject.cdr).to eq(pod)
        end

        it 'should know its children' do
          expect(subject.children).to eq([pea, pod])
        end

        it 'should know if it is empty (null)' do
          expect(subject).not_to be_null
          expect(ConsCell.new(nil, nil)).to be_null
          expect(NullList).to be_null
        end
      end # context

      context 'Provided services:' do
        it 'should compare to itself' do
          expect(subject.eql?(subject)).to be_truthy
          synonym = subject
          expect(subject == synonym).to be_truthy
        end

        it 'should compare to another instance' do
          same = ConsCell.new(pea, pod)
          expect(subject.eql?(same)).to be_truthy

          different = ConsCell.new(pod, pea)
          expect(subject.eql?(different)).to be_falsey

          different = ConsCell.new(pea)
          expect(subject.eql?(different)).to be_falsey
        end
      end # context
    end # describe
  end # module
end # module

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mini_kraken-0.1.06 spec/core/cons_cell_spec.rb
mini_kraken-0.1.05 spec/core/cons_cell_spec.rb