Sha256: becc17e6cc577f3f49c35f52d6fdb397c446d762e03aa630a9b891845fed8f2c

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require_relative '../spec_helper' # Use the RSpec framework
require_relative '../support/factory_atomic'

# Load the class under test
require_relative '../../lib/mini_kraken/composite/list'

module MiniKraken
  module Composite
    describe List do
      include MiniKraken::FactoryAtomic # Use mix-in module

      let(:pea) { k_symbol(:pea) }
      let(:pod) { k_symbol(:pod) }
      let(:corn) { k_symbol(:corn) }

      context 'Module as a factory:' do
        subject { List }

        it 'builds a pair wiht one argument (= one element proper list)' do
          pair = subject.cons(pea)
          expect(pair.car).to eq(pea)
          expect(pair.cdr).to be_nil
        end

        it 'builds a pair with two explicit arguments' do
          pair = subject.cons(pea, pod)
          expect(pair.car).to eq(pea)
          expect(pair.cdr).to eq(pod)
        end

        it 'builds a null list from an empty array' do
          l = subject.make_list([])
          expect(l).to be_kind_of(ConsCell)
          expect(l).to be_null
        end

        it 'builds a proper list from an non-empty array' do
          l = subject.make_list([pea, pod, corn])

          expect(l.car).to eq(pea)
          expect(l.cdr.car).to eq(pod)
          expect(l.cdr.cdr.car).to eq(corn)
          expect(l.cdr.cdr.cdr).to be_nil
        end
      end # context
    end # describz
  end # module
end # module

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mini_kraken-0.3.03 spec/composite/list_spec.rb
mini_kraken-0.3.02 spec/composite/list_spec.rb
mini_kraken-0.3.01 spec/composite/list_spec.rb
mini_kraken-0.3.00 spec/composite/list_spec.rb