Sha256: e5d68efb7c7494f9ef023af4efd1db97497c88797aa489c597d76e18b9a3bf64

Contents?: true

Size: 1.45 KB

Versions: 33

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
module Quby
  describe RangeCategories do
    describe '#initialize' do
      it 'rejects single values and even numbers of parameters' do
        expected_error = "RangeCategories should be of the form (0, 'label 0-10', 10, 'label 10-20', 20)"
        expect { described_class.new 0 }.to raise_exception(expected_error)
        expect { described_class.new 0, 'label', 10, 'lobel' }.to raise_exception(expected_error)
      end
    end

    describe '#as_range_hash' do
      it 'returns a hash of ranges in float form to labels' do
        expected_categories = {(0.0...30.0) => "Zeer laag", (30.0...40.0) => "Laag", (40.0...60.0) => "Gemiddeld",
                               (60.0...70.0) => "Hoog", (70.0..100.0) => "Zeer hoog"} # last range should be inclusive
        range_caterories = described_class.new 0, 'Zeer laag',
                                               30, 'Laag',
                                               40, 'Gemiddeld',
                                               60, 'Hoog',
                                               70, 'Zeer hoog', 100
        expect(range_caterories.as_range_hash).to eq(expected_categories)
      end

      it 'works for a single range' do
        expected_categories = {(0.0..100.0) => "Zeer hoog"}
        range_caterories = described_class.new 0, 'Zeer hoog', 100
        expect(range_caterories.as_range_hash).to eq(expected_categories)
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
quby-5.6.5 spec/quby/range_categories_spec.rb
quby-5.6.3 spec/quby/range_categories_spec.rb
quby-5.6.2 spec/quby/range_categories_spec.rb
quby-5.6.1 spec/quby/range_categories_spec.rb
quby-5.6.0 spec/quby/range_categories_spec.rb
quby-5.5.0 spec/quby/range_categories_spec.rb
quby-5.4.0 spec/quby/range_categories_spec.rb
quby-5.3.1 spec/quby/range_categories_spec.rb
quby-5.3.0 spec/quby/range_categories_spec.rb
quby-5.2.0 spec/quby/range_categories_spec.rb
quby-5.1.3 spec/quby/range_categories_spec.rb
quby-5.1.2 spec/quby/range_categories_spec.rb
quby-5.1.1 spec/quby/range_categories_spec.rb
quby-5.1.0 spec/quby/range_categories_spec.rb
quby-5.0.5 spec/quby/range_categories_spec.rb
quby-5.0.4 spec/quby/range_categories_spec.rb
quby-5.0.3 spec/quby/range_categories_spec.rb
quby-5.0.2 spec/quby/range_categories_spec.rb
quby-5.0.1 spec/quby/range_categories_spec.rb
quby-5.0.0 spec/quby/range_categories_spec.rb