Sha256: b4bd127f7e4238cc69c7a616dfed961137f4d237370f9c5699f8f2eada9b8d6a

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require_relative '../../lib/csv_decision'

SPEC_DATA_VALID ||= File.join(CSVDecision.root, 'spec', 'data', 'valid')
SPEC_DATA_INVALID ||= File.join(CSVDecision.root, 'spec', 'data', 'invalid')

describe CSVDecision::Index do
  it 'indexes a single column CSV' do
    file = Pathname(File.join(SPEC_DATA_VALID, 'options_in_file3.csv'))
    result = CSVDecision.parse(file)

    expected = {
      'none' => 0,
      'one' => 1,
      'two' => 2,
      'three' => 3,
      nil => 4,
      0 => 5,
      1 => 6,
      2 => 7,
      3 => 8
    }

    expect(result.index.columns).to eq [0]
    expect(result.index.hash).to eql expected
  end

  it 'indexes two columns with contiguous values' do
    file = Pathname(File.join(SPEC_DATA_VALID, 'multi_column_index.csv'))
    result = CSVDecision.parse(file)

    expected = {
      %w[integer none] => [[0, 1]],
      %w[integer one] => [[2, 3]],
      %w[string none] => [[4, 5]],
      %w[string one] => [[6, 7]]
    }

    expect(result.index.columns).to eq [1, 2]
    expect(result.index.hash).to eql expected
  end

  it 'indexes two columns with non-contiguous values' do
    file = Pathname(File.join(SPEC_DATA_VALID, 'multi_column_index2.csv'))
    result = CSVDecision.parse(file)

    expected = {
      %w[integer none] => [0, 8],
      %w[string none] => [[1, 2]],
      %w[string one] => [3, [6, 7]],
      %w[integer one] => [[4, 5]]
    }

    expect(result.index.columns).to eq [1, 2]
    expect(result.index.hash).to eql expected
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
csv_decision2-0.5.1 spec/csv_decision/index_spec.rb
csv_decision-0.5.1 spec/csv_decision/index_spec.rb
csv_decision-0.5.0 spec/csv_decision/index_spec.rb
csv_decision-0.4.1 spec/csv_decision/index_spec.rb
csv_decision-0.4.0 spec/csv_decision/index_spec.rb
csv_decision-0.3.2 spec/csv_decision/index_spec.rb
csv_decision-0.3.1 spec/csv_decision/index_spec.rb
csv_decision-0.3.0 spec/csv_decision/index_spec.rb