Sha256: 602e714166bc7eed4344d4a82a0855b37fe3fc96728be2b7e446cfd8bcf35cd3

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

require 'spec_helper'

describe Fzip::Zipper, 'next' do
  let(:tree) {
    [
      ['x', '+', 'y'],
      ['a', '*', 'b']
    ]
  }
  let(:zipper) { Fzip.array(tree) }

  let(:sequence) {
    [
      tree,
      ['x', '+', 'y'],
      'x',
      '+',
      'y',
      ['a', '*', 'b'],
      'a',
      '*',
      'b'
    ]
  }

  it 'should go depth first' do
    sequence.each.with_index do |n, idx|
      nth = (0...idx).inject(zipper) {|z| z.next}
      expect(nth.node).to eq n

      p nth.node
      sequence.first(idx+1).reverse.each.with_index do |p, pidx|
        puts " => #{p.inspect}"
        pth = (0...pidx).inject(nth) {|n| n.prev}
        expect(pth.node).to eq p
      end
    end
  end

  it 'should go to the end' do
    z = zipper
    9.times do
      expect(z.end?).to be_false
      z = z.next
    end
    expect(z.end?).to be_true
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fzip-0.2.0 spec/next_spec.rb