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(); }