TEST_F(AnalysisDriverFixture,SimpleProject_InsertMeasure) { // create a new project SimpleProject project = getCleanSimpleProject("SimpleProject_InsertMeasure"); // open a measure openstudio::path dir = resourcesPath() / toPath("/utilities/BCL/Measures/SetWindowToWallRatioByFacade"); BCLMeasure measure = BCLMeasure::load(dir).get(); // insert it into the project BCLMeasure projectMeasure = project.insertMeasure(measure); // verify that there is a project-specific copy EXPECT_NE(toString(measure.directory()),toString(projectMeasure.directory())); openstudio::path scriptsDir = project.projectDir() / toPath("scripts"); EXPECT_EQ(toString(completeAndNormalize(scriptsDir)), toString(completeAndNormalize(projectMeasure.directory().parent_path()))); EXPECT_EQ(measure.uuid(),projectMeasure.uuid()); EXPECT_EQ(measure.versionUUID(),projectMeasure.versionUUID()); // DLM: should this be not equal? // verify that it can be retrieved from the project, but its arguments cannot ASSERT_TRUE(project.getMeasureByUUID(measure.uuid())); BCLMeasure temp = project.getMeasureByUUID(measure.uuid()).get(); EXPECT_EQ(toString(projectMeasure.directory()),toString(temp.directory())); EXPECT_EQ(projectMeasure.uuid(),temp.uuid()); EXPECT_EQ(projectMeasure.versionUUID(),temp.versionUUID()); EXPECT_EQ(1u,project.measures().size()); // use embedded Ruby to extract the arguments // (see AnalysisDriverFixture.cpp for interpreter set-up) OSArgumentVector args = argumentGetter->getArguments(projectMeasure, project.seedModel(), project.seedIdf()); EXPECT_FALSE(args.empty()); // register and subsequently retrieve those arguments project.registerArguments(measure,args); // doesn't matter which copy of the measure we use EXPECT_TRUE(project.hasStoredArguments(temp)); OSArgumentVector argsCopy = project.getStoredArguments(projectMeasure); ASSERT_EQ(args.size(),argsCopy.size()); for (int i = 0, n = args.size(); i < n; ++i) { EXPECT_EQ(args[i].name(),argsCopy[i].name()); EXPECT_EQ(args[i].type(),argsCopy[i].type()); } // use this measure to create a new variable/ruby measure // now it is important to use the copy in the project MeasureGroup dv("New Measure Group",MeasureVector()); Problem problem = project.analysis().problem(); problem.push(dv); // here, expect this test to pass. // in pat, if it fails, let user know and call problem.erase(dv). EXPECT_TRUE(problem.fileTypesAreCompatible(dv, projectMeasure.inputFileType(), projectMeasure.outputFileType())); EXPECT_TRUE(dv.push(RubyMeasure(projectMeasure))); }
TEST_F(AnalysisFixture, RubyPerturbation_FreeFormScript) { // construct openstudio::path scriptPath = toPath("myCrazyScript.rb"); RubyPerturbation perturbation(scriptPath, FileReferenceType::OSM, FileReferenceType::OSM); EXPECT_EQ(FileReferenceType(FileReferenceType::OSM),perturbation.inputFileType()); EXPECT_EQ(FileReferenceType(FileReferenceType::OSM),perturbation.outputFileType()); EXPECT_FALSE(perturbation.usesBCLMeasure()); EXPECT_ANY_THROW(perturbation.measure()); EXPECT_ANY_THROW(perturbation.measureDirectory()); EXPECT_ANY_THROW(perturbation.measureUUID()); EXPECT_ANY_THROW(perturbation.measureVersionUUID()); FileReference scriptReference = perturbation.perturbationScript(); EXPECT_EQ(scriptPath,scriptReference.path().filename()); EXPECT_EQ(boost::filesystem::system_complete(scriptPath),scriptReference.path()); EXPECT_EQ(FileReferenceType(FileReferenceType::RB),scriptReference.fileType()); EXPECT_TRUE(perturbation.arguments().empty()); EXPECT_FALSE(perturbation.isUserScript()); EXPECT_FALSE(perturbation.hasIncompleteArguments()); // add arguments the old way perturbation.addArgument("verbose"); perturbation.addArgument("numRandomChanges","10"); // verify status of arguments EXPECT_EQ(2u,perturbation.arguments().size()); EXPECT_TRUE(perturbation.hasIncompleteArguments()); // name-only argument has no value OSArgumentVector incompleteArgs = perturbation.incompleteArguments(); ASSERT_EQ(1u,incompleteArgs.size()); EXPECT_EQ("verbose",incompleteArgs[0].name()); }
TEST_F(AnalysisDriverFixture,SimpleProject_UpdateMeasure) { // create a new project SimpleProject project = getCleanSimpleProject("SimpleProject_UpdateMeasure"); Problem problem = project.analysis().problem(); // insert a measure into the project, extract and register its arguments openstudio::path measuresDir = resourcesPath() / toPath("/utilities/BCL/Measures"); openstudio::path dir = measuresDir / toPath("SetWindowToWallRatioByFacade"); BCLMeasure measure = BCLMeasure::load(dir).get(); BCLMeasure projectMeasure = project.insertMeasure(measure); OSArgumentVector args = argumentGetter->getArguments(projectMeasure, project.seedModel(), project.seedIdf()); project.registerArguments(projectMeasure,args); EXPECT_EQ(1u,project.measures().size()); // use the measure to create a new variable/ruby measure MeasureGroup dv("New Measure Group",MeasureVector()); EXPECT_TRUE(problem.push(dv)); RubyMeasure rp(projectMeasure); rp.setArguments(args); EXPECT_TRUE(dv.push(rp)); EXPECT_EQ(args.size(),rp.arguments().size()); EXPECT_TRUE(rp.hasIncompleteArguments()); BOOST_FOREACH(const OSArgument& arg,args) { if (arg.name() == "wwr") { OSArgument temp = arg.clone(); temp.setValue(0.6); rp.setArgument(temp); } if (arg.name() == "sillHeight") { OSArgument temp = arg.clone(); temp.setValue(1.0); rp.setArgument(temp); } if (arg.name() == "facade") { OSArgument temp = arg.clone(); temp.setValue("South"); rp.setArgument(temp); } } EXPECT_FALSE(rp.hasIncompleteArguments()); openstudio::path tempDir = measuresDir / toPath(toString(createUUID())); { // create fake new version of the measure BCLMeasure newVersion = measure.clone(tempDir).get(); newVersion.incrementVersionId(); newVersion.save(); OSArgumentVector newArgs = args; newArgs.push_back(OSArgument::makeDoubleArgument("frame_width")); // update the measure project.updateMeasure(newVersion,newArgs); // verify the final state of SimpleProject and RubyMeasure EXPECT_EQ(1u,project.measures().size()); BCLMeasure retrievedMeasure = project.getMeasureByUUID(measure.uuid()).get(); EXPECT_NE(measure.versionUUID(),retrievedMeasure.versionUUID()); EXPECT_EQ(newVersion.versionUUID(),retrievedMeasure.versionUUID()); ASSERT_TRUE(project.hasStoredArguments(retrievedMeasure)); OSArgumentVector retrievedArgs = project.getStoredArguments(retrievedMeasure); EXPECT_EQ(args.size() + 1u,retrievedArgs.size()); EXPECT_EQ(retrievedArgs.size(),rp.arguments().size()); EXPECT_TRUE(rp.hasIncompleteArguments()); } boost::filesystem::remove_all(tempDir); }