Sha256: 69434a8369eed5a4a9ab202d6d29e3ba41e86ae2e855a2c39c99145e830bd8ab

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require_relative '../../lib/csv_decision2'

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

describe CSVDecision2::Index do
  it 'indexes a single column CSV' do
    file = Pathname(File.join(SPEC_DATA_VALID, 'options_in_file3.csv'))
    result = CSVDecision2.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 = CSVDecision2.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 = CSVDecision2.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

1 entries across 1 versions & 1 rubygems

Version Path
csv_decision2-0.5.2 spec/csv_decision2/index_spec.rb