# ******************************************************************************* # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC. # All rights reserved. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # (1) Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # (2) Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # (3) Neither the name of the copyright holder nor the names of any contributors # may be used to endorse or promote products derived from this software without # specific prior written permission from the respective party. # # (4) Other than as required in clauses (1) and (2), distributions in any form # of modifications or other derivative works may not use the "OpenStudio" # trademark, "OS", "os", or any other confusingly similar designation without # specific prior written permission from Alliance for Sustainable Energy, LLC. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ******************************************************************************* require 'openstudio' require 'openstudio/measure/ShowRunnerOutput' require 'fileutils' require_relative '../measure.rb' require 'minitest/autorun' class IncreaseInsulationRValueForRoofs_Test < Minitest::Test # def setup # end # def teardown # end def test_IncreaseInsulationRValueForRoofs_01_bad # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # make an empty model model = OpenStudio::Model::Model.new # get arguments and test that they are what we are expecting arguments = measure.arguments(model) assert_equal(5, arguments.size) assert_equal('r_value', arguments[0].name) assert_equal(30.0, arguments[0].defaultValueAsDouble) # set argument values to bad values and run the measure argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) r_value = arguments[0].clone assert(r_value.setValue(9000.0)) argument_map['r_value'] = r_value measure.run(model, runner, argument_map) result = runner.result assert(result.value.valueName == 'Fail') end def test_IncreaseInsulationRValueForRoofs_NewConstruction_FullyCosted # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new(File.dirname(__FILE__) + '/EnvelopeAndLoadTestModel_01.osm') model = translator.loadModel(path) assert(!model.empty?) model = model.get # get arguments and test that they are what we are expecting arguments = measure.arguments(model) # set argument values to good values and run the measure on model with spaces argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # set all argument values count = -1 r_value = arguments[count += 1].clone assert(r_value.setValue(50.0)) argument_map['r_value'] = r_value allow_reduction = arguments[count += 1].clone assert(allow_reduction.setValue('false')) argument_map['allow_reduction'] = allow_reduction material_cost_increase_ip = arguments[count += 1].clone assert(material_cost_increase_ip.setValue(2.0)) argument_map['material_cost_increase_ip'] = material_cost_increase_ip one_time_retrofit_cost_ip = arguments[count += 1].clone assert(one_time_retrofit_cost_ip.setValue(0.0)) argument_map['one_time_retrofit_cost_ip'] = one_time_retrofit_cost_ip years_until_retrofit_cost = arguments[count += 1].clone assert(years_until_retrofit_cost.setValue(0)) argument_map['years_until_retrofit_cost'] = years_until_retrofit_cost # test initial model conditions surface1_found = false surface2_found = false model.getSurfaces.each do |surface| if surface.name.get == 'Surface 20' surface1_found = true construction = surface.construction # should use "ASHRAE_189.1-2009_ExtWall_Mass_ClimateZone_alt-res 5" assert(!construction.empty?) construction = construction.get.to_Construction assert(!construction.empty?) assert(construction.get.layers.size == 4) assert(construction.get.layers[2].name.get == 'Wall Insulation [42]') assert(construction.get.layers[2].thickness == 0.091400) elsif surface.name.get == 'Surface 14' # this is the one that doesnt get changed surface2_found = true construction = surface.construction # should use "Test_No Insulation" assert(!construction.empty?) construction = construction.get.to_Construction assert(!construction.empty?) assert(construction.get.layers.size == 3) assert(construction.get.layers[0].name.get == '000_M01 100mm brick') assert(construction.get.layers[1].name.get == '8IN CONCRETE HW_RefBldg') assert(construction.get.layers[2].name.get == '1/2IN Gypsum') end end assert(surface1_found) assert(surface2_found) measure.run(model, runner, argument_map) result = runner.result # show_output(result) #this displays the output when you run the test assert(result.value.valueName == 'Success') assert(result.info.size == 2) assert(result.warnings.empty?) # test final model conditions # loop over info warnings # loop over warnings end def test_IncreaseInsulationRValueForRoofs_Retrofit_FullyCosted # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new(File.dirname(__FILE__) + '/EnvelopeAndLoadTestModel_01.osm') model = translator.loadModel(path) assert(!model.empty?) model = model.get # get arguments and test that they are what we are expecting arguments = measure.arguments(model) # set argument values to good values and run the measure on model with spaces argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # set all argument values count = -1 r_value = arguments[count += 1].clone assert(r_value.setValue(50.0)) argument_map['r_value'] = r_value allow_reduction = arguments[count += 1].clone assert(allow_reduction.setValue('false')) argument_map['allow_reduction'] = allow_reduction material_cost_increase_ip = arguments[count += 1].clone assert(material_cost_increase_ip.setValue(2.0)) argument_map['material_cost_increase_ip'] = material_cost_increase_ip one_time_retrofit_cost_ip = arguments[count += 1].clone assert(one_time_retrofit_cost_ip.setValue(3.5)) argument_map['one_time_retrofit_cost_ip'] = one_time_retrofit_cost_ip years_until_retrofit_cost = arguments[count += 1].clone assert(years_until_retrofit_cost.setValue(0)) argument_map['years_until_retrofit_cost'] = years_until_retrofit_cost measure.run(model, runner, argument_map) result = runner.result # show_output(result) #this displays the output when you run the test assert(result.value.valueName == 'Success') assert(result.info.size == 3) assert(result.warnings.empty?) end def test_IncreaseInsulationRValueForRoofs_Retrofit_NoCost # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new(File.dirname(__FILE__) + '/EnvelopeAndLoadTestModel_01.osm') model = translator.loadModel(path) assert(!model.empty?) model = model.get # get arguments and test that they are what we are expecting arguments = measure.arguments(model) # set argument values to good values and run the measure on model with spaces argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # set all argument values count = -1 r_value = arguments[count += 1].clone assert(r_value.setValue(50.0)) argument_map['r_value'] = r_value allow_reduction = arguments[count += 1].clone assert(allow_reduction.setValue('false')) argument_map['allow_reduction'] = allow_reduction material_cost_increase_ip = arguments[count += 1].clone assert(material_cost_increase_ip.setValue(0.0)) argument_map['material_cost_increase_ip'] = material_cost_increase_ip one_time_retrofit_cost_ip = arguments[count += 1].clone assert(one_time_retrofit_cost_ip.setValue(0.0)) argument_map['one_time_retrofit_cost_ip'] = one_time_retrofit_cost_ip years_until_retrofit_cost = arguments[count += 1].clone assert(years_until_retrofit_cost.setValue(0)) argument_map['years_until_retrofit_cost'] = years_until_retrofit_cost measure.run(model, runner, argument_map) result = runner.result # show_output(result) #this displays the output when you run the test assert(result.value.valueName == 'Success') assert(result.info.size == 1) assert(result.warnings.empty?) end def test_IncreaseInsulationRValueForExteriorWalls_ReverseTranslatedModel # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new(File.dirname(__FILE__) + '/ReverseTranslatedModel.osm') model = translator.loadModel(path) assert(!model.empty?) model = model.get # get arguments and test that they are what we are expecting arguments = measure.arguments(model) # set argument values to good values and run the measure on model with spaces argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # set all argument values count = -1 r_value = arguments[count += 1].clone assert(r_value.setValue(50.0)) argument_map['r_value'] = r_value allow_reduction = arguments[count += 1].clone assert(allow_reduction.setValue('false')) argument_map['allow_reduction'] = allow_reduction material_cost_increase_ip = arguments[count += 1].clone assert(material_cost_increase_ip.setValue(2.0)) argument_map['material_cost_increase_ip'] = material_cost_increase_ip one_time_retrofit_cost_ip = arguments[count += 1].clone assert(one_time_retrofit_cost_ip.setValue(3.5)) argument_map['one_time_retrofit_cost_ip'] = one_time_retrofit_cost_ip years_until_retrofit_cost = arguments[count += 1].clone assert(years_until_retrofit_cost.setValue(0)) argument_map['years_until_retrofit_cost'] = years_until_retrofit_cost measure.run(model, runner, argument_map) result = runner.result # show_output(result) #this displays the output when you run the test assert(result.value.valueName == 'NA') assert(result.info.size == 1) assert(result.warnings.size == 1) end def test_IncreaseInsulationRValueForExteriorWalls_EmptySpaceNoLoadsOrSurfaces # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # make an empty model model = OpenStudio::Model::Model.new # add a space to the model without any geometry or loads, want to make sure measure works or fails gracefully new_space = OpenStudio::Model::Space.new(model) # get arguments and test that they are what we are expecting arguments = measure.arguments(model) # set argument values to good values and run the measure on model with spaces argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # set all argument values count = -1 r_value = arguments[count += 1].clone assert(r_value.setValue(50.0)) argument_map['r_value'] = r_value allow_reduction = arguments[count += 1].clone assert(allow_reduction.setValue('false')) argument_map['allow_reduction'] = allow_reduction material_cost_increase_ip = arguments[count += 1].clone assert(material_cost_increase_ip.setValue(2.0)) argument_map['material_cost_increase_ip'] = material_cost_increase_ip one_time_retrofit_cost_ip = arguments[count += 1].clone assert(one_time_retrofit_cost_ip.setValue(3.5)) argument_map['one_time_retrofit_cost_ip'] = one_time_retrofit_cost_ip years_until_retrofit_cost = arguments[count += 1].clone assert(years_until_retrofit_cost.setValue(0)) argument_map['years_until_retrofit_cost'] = years_until_retrofit_cost measure.run(model, runner, argument_map) result = runner.result # show_output(result) #this displays the output when you run the test assert(result.value.valueName == 'NA') assert(result.info.size == 1) assert(result.warnings.empty?) end def test_IncreaseInsulationRValueForRoofs_AllowReduction # create an instance of the measure measure = IncreaseInsulationRValueForRoofs.new # create an instance of a runner runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new) # load the test model translator = OpenStudio::OSVersion::VersionTranslator.new path = OpenStudio::Path.new(File.dirname(__FILE__) + '/EnvelopeAndLoadTestModel_01.osm') model = translator.loadModel(path) assert(!model.empty?) model = model.get # get arguments and test that they are what we are expecting arguments = measure.arguments(model) # set argument values to good values and run the measure on model with spaces argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments) # set all argument values count = -1 r_value = arguments[count += 1].clone assert(r_value.setValue(2.0)) argument_map['r_value'] = r_value allow_reduction = arguments[count += 1].clone assert(allow_reduction.setValue('true')) argument_map['allow_reduction'] = allow_reduction material_cost_increase_ip = arguments[count += 1].clone assert(material_cost_increase_ip.setValue(0)) argument_map['material_cost_increase_ip'] = material_cost_increase_ip one_time_retrofit_cost_ip = arguments[count += 1].clone assert(one_time_retrofit_cost_ip.setValue(0)) argument_map['one_time_retrofit_cost_ip'] = one_time_retrofit_cost_ip years_until_retrofit_cost = arguments[count += 1].clone assert(years_until_retrofit_cost.setValue(0)) argument_map['years_until_retrofit_cost'] = years_until_retrofit_cost measure.run(model, runner, argument_map) result = runner.result # show_output(result) #this displays the output when you run the test assert(result.value.valueName == 'Success') assert(result.info.size == 1) assert(result.warnings.empty?) end end