Example #1
0
TEST(Table, UnitConversion) {

  openstudio::path p = resourcesPath()/toPath("utilities/Table/HeightWeight.csv");
  Table table = Table::load(p);
  table.setTitle("Height and Weight");
  table.setNHead(1);
  table.setNLeft(1);
  EXPECT_FALSE(table.convertUnits(0));
  EXPECT_FALSE(table.convertUnits(1));

  // expanded test to help debug on gcc
  ASSERT_TRUE(table.nRows() >= 2);
  ASSERT_TRUE(table.nCols() >= 3);
  EXPECT_EQ("lb_m",table.units(2));
  std::stringstream ss;
  ss << table[0][2];
  std::string tmp = extractUnitString(ss.str());
  EXPECT_EQ("lb_m",tmp);
  tmp = convertToStandardForm(tmp);
  EXPECT_EQ("lb_m",tmp);
  EXPECT_TRUE(containsRegisteredBaseUnit(tmp));

  ASSERT_TRUE(table[1][2].isInt());
  double d = table[1][2].toDouble();
  Quantity q = createQuantity(d,tmp).get();

  EXPECT_TRUE(table.convertUnits(2));
  std::string unitStr = table.units(2);
  EXPECT_EQ("kg",unitStr);
  p = resourcesPath()/toPath("utilities/Table/HeightWeightSI.csv");
  boost::filesystem::ofstream outFile(p);
  ASSERT_TRUE(outFile);
  table.printToStream(outFile,TableFormat(TableFormat::CSV));
  outFile.close();

  p = resourcesPath()/toPath("utilities/Table/EUI.csv");
  table = Table::load(p);
  table.setTitle("EUIs");
  table.setCaption("EUIs of several buildings");
  table.setNHead(2);
  table.setNLeft(2);
  EXPECT_TRUE(table.convertUnits(2));
  unitStr = table.units(2);
  EXPECT_EQ("kJ/m^2",unitStr);
  // now cols 2 and 3 should be equal except for kJ/m^2 v. MJ/m^2.
  for (unsigned i = 0, n = table.nRows(); i < n; ++i) {
    if (table.isRowIndex(i,Table::BODY)) {
      double d2 = table[i][2].toDouble();
      double d3 = table[i][3].toDouble();
      EXPECT_NEAR((d2-(d3*1000.0))/(d2),0.0,1.0E-3);
    }
  }
  p = resourcesPath()/toPath("utilities/Table/EUISI.csv");
  outFile.open(p);
  ASSERT_TRUE(outFile);
  table.printToStream(outFile,TableFormat(TableFormat::CSV));
  outFile.close();

}
TEST_F(UnitsFixture,QuantityFactory_ReturnQuantityObjects) {
  LOG(Debug,"QuantityFactory_ReturnQuantityObjects");

  Quantity l1 = createQuantity(32.0,"m").get();
  //ASSERT_THROW(createIPQuantity(32.0,"m"),Exception);
  testStreamOutput("32 m",l1);

  Quantity f1 = createQuantity(-70.1,"lb_f").get();
  //ASSERT_THROW(createSIQuantity(-70.1,"lb_f"),Exception);
  testStreamOutput("-70.1 lb_f",f1);

  Quantity P1 = createQuantity(300.0,"kBtu/h").get();
  //ASSERT_THROW(createIPQuantity(300,"Btu/h"),Exception);
  EXPECT_EQ(3,P1.scale().exponent);
  EXPECT_EQ(1,P1.baseUnitExponent("Btu"));

  Quantity m1 = createQuantity(23.522,"ft*m").get();
  EXPECT_EQ(1,m1.baseUnitExponent("ft"));
  EXPECT_EQ(1,m1.baseUnitExponent("m"));
  testStreamOutput("23.522 ft*m",m1);
}