예제 #1
0
/* Test for bug found in #2900 where it currently returns "1/ftH_{2}O^2" (this is a createUnit problem really...) */
TEST_F(UnitsFixture,UnitFactory_IP_Pressure_wc) {
  {
    OptionalUnit unit = openstudio::createUnit("1/ftH_{2}O");
    ASSERT_TRUE(unit);
    EXPECT_EQ("1/ftH_{2}O", unit->standardString());
  }

  {
    OptionalUnit unit = openstudio::createUnit("1/inH_{2}O");
    ASSERT_TRUE(unit);
    EXPECT_EQ("1/inH_{2}O", unit->standardString());
  }
}
TEST_F(IddFixture,IddFactory_OpenStudioUnits_SubTest3) {
    IddObjectVector objects = IddFactory::instance().getObjects(IddFileType(IddFileType::OpenStudio));
    bool found = false;
    for (const IddObject& object : objects) {
        IddFieldVector fields = object.nonextensibleFields();
        IddFieldVector temp = object.extensibleGroup();
        fields.insert(fields.end(),temp.begin(),temp.end());
        for (const IddField& field : fields) {
            if (OptionalString iddUnits = field.properties().ipUnits) {
                if (*iddUnits == "gal/min") {
                    if (object.type() == IddObjectType::OS_AirTerminal_SingleDuct_ParallelPIU_Reheat) {
                        LOG(Debug,"Gal/min field: " << field.name());
                    }
                    found = true;
                    OptionalUnit ipUnit = field.getUnits(true);
                    ASSERT_TRUE(ipUnit);
                    EXPECT_TRUE(ipUnit->system() == UnitSystem::Mixed);
                    EXPECT_EQ("crgal^3/min",ipUnit->standardString());
                    EXPECT_EQ("gal/min",ipUnit->prettyString());
                }
            }
        }
    }
    EXPECT_TRUE(found);
}
TEST_F(IddFixture,IddFactory_OpenStudioUnits_SubTest1) {
    IddObjectVector objects = IddFactory::instance().getObjects(IddFileType(IddFileType::OpenStudio));
    bool found = false;
    for (const IddObject& object : objects) {
        IddFieldVector fields = object.nonextensibleFields();
        IddFieldVector temp = object.extensibleGroup();
        fields.insert(fields.end(),temp.begin(),temp.end());
        for (const IddField& field : fields) {
            if (OptionalString iddUnits = field.properties().ipUnits) {
                if (*iddUnits == "Btu/h-ft-F") {
                    found = true;
                    OptionalUnit siUnit = field.getUnits(false);
                    ASSERT_TRUE(siUnit);
                    EXPECT_TRUE(siUnit->system() == UnitSystem::SI);
                    EXPECT_EQ("kg*m/s^3*K",siUnit->standardString(false));
                    OptionalUnit ipUnit = field.getUnits(true);
                    ASSERT_TRUE(ipUnit);
                    EXPECT_TRUE(ipUnit->system() == UnitSystem::BTU);
                    Quantity q(1.0,*ipUnit);
                    OptionalQuantity testQ = convert(q,*siUnit);
                    EXPECT_TRUE(testQ);
                    break;
                }
            }
        }
        if (found) {
            break;
        }
    }
    EXPECT_TRUE(found);
}
TEST_F(IddFixture,IddFactory_OpenStudioUnits_SubTest2) {
    IddObjectVector objects = IddFactory::instance().getObjects(IddFileType(IddFileType::OpenStudio));
    bool found = false;
    for (const IddObject& object : objects) {
        IddFieldVector fields = object.nonextensibleFields();
        IddFieldVector temp = object.extensibleGroup();
        fields.insert(fields.end(),temp.begin(),temp.end());
        for (const IddField& field : fields) {
            if (OptionalString iddUnits = field.properties().units) {
                if (*iddUnits == "kg-H2O/kg-Air") {
                    found = true;
                    OptionalUnit siUnit = field.getUnits();
                    ASSERT_TRUE(siUnit);
                    EXPECT_TRUE(siUnit->system() == UnitSystem::SI);
                    EXPECT_EQ("",siUnit->standardString());
                    EXPECT_EQ("kg_{H2O}/kg_{air}",siUnit->prettyString());
                    break;
                }
            }
        }
        if (found) {
            break;
        }
    }
    EXPECT_TRUE(found);
}
TEST_F(IddFixture,IddFactory_Units) {
    std::vector<boost::regex> unsupported;
    unsupported.push_back(boost::regex("\\$"));
    unsupported.push_back(boost::regex("eV"));
    unsupported.push_back(boost::regex("hh:mm"));
    unsupported.push_back(boost::regex("percent"));
    unsupported.push_back(boost::regex("ppm"));

    IddObjectVector objects = IddFactory::instance().getObjects(IddFileType(IddFileType::WholeFactory));
    StringSet goodUnits;
    StringSet badUnits;
    for (const IddObject& object : objects) {
        IddFieldVector fields = object.nonextensibleFields();
        IddFieldVector temp = object.extensibleGroup();
        fields.insert(fields.end(),temp.begin(),temp.end());
        for (const IddField& field : fields) {
            OptionalString iddUnits = field.properties().units;
            OptionalUnit siUnit;
            if (iddUnits) {

                // check if already tested units
                if (goodUnits.find(*iddUnits) != goodUnits.end()) {
                    continue;
                }
                if (badUnits.find(*iddUnits) != badUnits.end()) {
                    continue;
                }

                // screen for unsupported units
                for (const boost::regex& re : unsupported) {
                    if (boost::regex_search(*iddUnits,re)) {
                        iddUnits = boost::none;
                        break;
                    }
                }
                if (!iddUnits) {
                    continue;
                }

                siUnit = field.getUnits(false);
                EXPECT_TRUE(siUnit || field.unitsBasedOnOtherField()) << object.name() << " field: " << field.name();
                if (siUnit) {
                    // could just return junk unit. if not junk, quantity will be convertible
                    // to UnitSystem::SI.
                    Quantity q(1.0,*siUnit);
                    OptionalQuantity testQ = convert(q,UnitSystem(UnitSystem::SI));
                    EXPECT_TRUE(testQ) << "Unable to convert unit '" << *iddUnits << "' to SI for field '"
                                       << field.name() << "' in IddObject '" << object.name() << "'.";
                    if (testQ) {
                        goodUnits.insert(*iddUnits);
                        EXPECT_TRUE(testQ->system() == UnitSystem::SI);
                    } else {
                        badUnits.insert(*iddUnits);
                        LOG(Debug,"Unable to convert unit '" << *iddUnits << "' to SI for field '"
                            << field.name() << "' in IddObject '" << object.name() << "'.");
                    }
                }
                else if (field.unitsBasedOnOtherField()) {
                    goodUnits.insert(*iddUnits);
                    continue;
                }
                else {
                    badUnits.insert(*iddUnits);
                    LOG(Debug,"Unable to instantiate unit '" << *iddUnits << "' for field '"
                        << field.name() << "' in IddObject '" << object.name() << "'.");
                    continue;
                }
                OptionalUnit ipUnit = field.getUnits(true);
                EXPECT_TRUE(ipUnit);
                if (ipUnit) {
                    // could just return junk unit. if not junk, quantity will be convertable
                    // to *siUnit or UnitSystem::SI.
                    Quantity q(1.0,*ipUnit);
                    OptionalQuantity testQ;
                    if (siUnit) {
                        testQ = convert(q,*siUnit);
                    }
                    else {
                        testQ = convert(q,UnitSystem(UnitSystem::SI));
                    }
                    EXPECT_TRUE(testQ);
                    if (testQ) {
                        goodUnits.insert(*iddUnits);
                    }
                    else {
                        badUnits.insert(ipUnit->standardString());
                        LOG(Debug,"Unable to convert unit " << *ipUnit << " to IDD/SI units " << *siUnit
                            << " for field '" << field.name() << "' in IddObject '" << object.name() << "'.");
                    }
                }
                else {
                    badUnits.insert(*iddUnits);
                    LOG(Debug,"Unable to instantiate ipUnit for field " << field.name() << " in IddObject "
                        << object.name() << ", which has units " << *siUnit << ".");
                }
            }
        }
    }
    LOG(Info,"IddUnitStrings not handled properly by the Factories and Converter:");
    for (const std::string& str : badUnits) {
        LOG(Info,"  " << str);
    }
    LOG(Info,"IddUnitStrings handled properly by the Factories and Converter:");
    for (const std::string& str : goodUnits) {
        LOG(Info,"  " << str);
    }
}