<commit_before>require 'spec_helper'

module Qernel
  describe DemandDrivenConverterApi do
    let(:graph) do
      layout = <<-LAYOUT.strip_heredoc
        useable_heat: network(100) == s(0.25) ==> supply_one
        useable_heat: network      == s(0.75) ==> supply_two
      LAYOUT

      GraphParser.new(layout).build
    end # graph

    let(:network)    { graph.converters.detect { |c| c.key == :network    } }
    let(:supply_one) { graph.converters.detect { |c| c.key == :supply_one } }
    let(:supply_two) { graph.converters.detect { |c| c.key == :supply_two } }

    before do
      graph.area.stub!(:number_households).and_return(200)

      supply_one.converter_api = DemandDrivenConverterApi.new(supply_one)
      supply_two.converter_api = DemandDrivenConverterApi.new(supply_two)

      [ supply_one, supply_two ].each do |converter|
        converter.graph = graph

        api = converter.converter_api
        api.stub!(:nominal_capacity_heat_output_per_unit).and_return(20)
        api.stub!(:demand_of_hot_water).and_return(0)
        api.stub!(:demand_of_steam_hot_water).and_return(0)
        api.stub!(:demand_of_useable_heat).and_return(0)
      end
    end

    # ------------------------------------------------------------------------

    describe '#number_of_units' do
      describe 'when households_supplied_per_unit is 1' do
        it 'should be 50.0 when the converter has a 25% share' do
          # binding.pry
          supply_one.converter_api.number_of_units.should eql(50.0)
        end

        it 'should be 150.0 when the converter has a 75% share' do
          supply_two.converter_api.number_of_units.should eql(150.0)
        end
      end

      describe 'when households_supplied_per_unit is 25' do
        before do
          [ supply_one, supply_two ].each do |converter|
            converter.dataset_set(:households_supplied_per_unit, 25)
          end
        end

        it 'should be 50.0 when the converter has a 25% share' do
          supply_one.converter_api.number_of_units.should eql(2.0)
        end

        it 'should be 150.0 when the converter has a 75% share' do
          supply_two.converter_api.number_of_units.should eql(6.0)
        end
      end
    end # number_of_units

    # ------------------------------------------------------------------------

    describe '#full_load_seconds' do<commit_msg>Remove mistakenly added call to pry in DDC spec.<commit_after>require 'spec_helper'

module Qernel
  describe DemandDrivenConverterApi do
    let(:graph) do
      layout = <<-LAYOUT.strip_heredoc
        useable_heat: network(100) == s(0.25) ==> supply_one
        useable_heat: network      == s(0.75) ==> supply_two
      LAYOUT

      GraphParser.new(layout).build
    end # graph

    let(:network)    { graph.converters.detect { |c| c.key == :network    } }
    let(:supply_one) { graph.converters.detect { |c| c.key == :supply_one } }
    let(:supply_two) { graph.converters.detect { |c| c.key == :supply_two } }

    before do
      graph.area.stub!(:number_households).and_return(200)

      supply_one.converter_api = DemandDrivenConverterApi.new(supply_one)
      supply_two.converter_api = DemandDrivenConverterApi.new(supply_two)

      [ supply_one, supply_two ].each do |converter|
        converter.graph = graph

        api = converter.converter_api
        api.stub!(:nominal_capacity_heat_output_per_unit).and_return(20)
        api.stub!(:demand_of_hot_water).and_return(0)
        api.stub!(:demand_of_steam_hot_water).and_return(0)
        api.stub!(:demand_of_useable_heat).and_return(0)
      end
    end

    # ------------------------------------------------------------------------

    describe '#number_of_units' do
      describe 'when households_supplied_per_unit is 1' do
        it 'should be 50.0 when the converter has a 25% share' do
          supply_one.converter_api.number_of_units.should eql(50.0)
        end

        it 'should be 150.0 when the converter has a 75% share' do
          supply_two.converter_api.number_of_units.should eql(150.0)
        end
      end

      describe 'when households_supplied_per_unit is 25' do
        before do
          [ supply_one, supply_two ].each do |converter|
            converter.dataset_set(:households_supplied_per_unit, 25)
          end
        end

        it 'should be 50.0 when the converter has a 25% share' do
          supply_one.converter_api.number_of_units.should eql(2.0)
        end

        it 'should be 150.0 when the converter has a 75% share' do
          supply_two.converter_api.number_of_units.should eql(6.0)
        end
      end
    end # number_of_units

    # ------------------------------------------------------------------------

    describe '#full_load_seconds' do
{'fraction_non_alphanumeric': 0.14849821466078555, 'fraction_numerical': 0.023104389834068473, 'mean_word_length': 2.1390903098220173, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '132571', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1503, 'n_words': 314}