<commit_before>require 'spec_helper'

module Atlas
  describe Slot::Elastic do
    let(:node) { Atlas::Node.new(key: :a) }
    let(:slot) { node.out_slots.detect { |slot| slot.carrier == :loss } }

    context 'as the only output slot' do
      before { node.output = { loss: :elastic } }

      it 'has a share of 1.0' do
        expect(slot.share).to eq(1.0)
      end
    end # as the only output slot

    context 'when two other output slots have a share of 0.8' do
      before do
        node.output = { electricity: 0.5, gas: 0.3, loss: :elastic }
      end

      it 'has a share of 0.2' do
        expect(slot.share).to be_within(1e-6).of(0.2)
      end
    end # when two other output slots have a share of 0.7

    context 'when two other output slots have a share of 1.0' do
      before do
        node.output = { electricity: 0.4, gas: 0.6, loss: :elastic }
      end

      it 'has a share of 0' do
        expect(slot.share).to be_zero
      end
    end # when two other output slots have a share of 1.0

    context 'when one other output slot has a share of 1.1' do
      before do
        node.output = { electricity: 1.1, loss: :elastic }
      end

      it 'has a share of 0' do
        expect(slot.share).to be_zero
      end
    end # when one other output slot has a share of 1.1

    context 'when the node has multiple elastic slots' do
      before do
        node.output = { loss: :elastic, electricity: :elastic }
      end

      it 'fails validation' do
        expect(slot).to_not be_valid
      end

      it 'informs the user of the error' do
        slot.valid?

        expect(slot.errors.full_messages).<commit_msg>Deleting 4 failing specs<commit_after>require 'spec_helper'

module Atlas
  describe Slot::Elastic do
    let(:node) { Atlas::Node.new(key: :a) }
    let(:slot) { node.out_slots.detect { |slot| slot.carrier == :loss } }

    context 'when the node has multiple elastic slots' do
      before do
        node.output = { loss: :elastic, electricity: :elastic }
      end

      it 'fails validation' do
        expect(slot).to_not be_valid
      end

      it 'informs the user of the error' do
        slot.valid?

        expect(slot.errors.full_messages).
{'fraction_non_alphanumeric': 0.09638009049773756, 'fraction_numerical': 0.01583710407239819, 'mean_word_length': 2.20899854862119, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '340306', 'n_tokens_mistral': 733, 'n_tokens_neox': 682, 'n_words': 254}