Ejemplo n.º 1
0
TEST(UnitsInterface, Newton_to_Pound)
{
  UnitsConvFn_t Newton_to_Pound;
  UnitsConvFn_t Newton_to_Pound2;
  Units_t* Newton = (Units_t*) NULL;
  Units_t* Pound = (Units_t*) NULL;
  double pounds;

  ASSERT_EQ(CONV_OK, conv_fn_s("kg*m/s2", "lbm*ft/s2", &Newton_to_Pound));

  Newton = new_units("kg*m/s2");
  Pound = new_units("lbm*ft/s2");

  ASSERT_NE((Units_t*) NULL, Newton);
  ASSERT_NE((Units_t*) NULL, Pound);

  ASSERT_EQ(CONV_OK, conv_fn_u(Newton, Pound, &Newton_to_Pound2));

  EXPECT_EQ(0, memcmp(&Newton_to_Pound, &Newton_to_Pound2, sizeof(UnitsConvFn_t)));

  pounds = convert_units(1.0, &Newton_to_Pound);

  ASSERT_NEAR((1.0/(0.45359237*0.3048)), pounds, TOL);

  clean_up_Units_t(&Newton);
  clean_up_Units_t(&Pound);
  ASSERT_EQ((Units_t*) NULL, Newton);
  ASSERT_EQ((Units_t*) NULL, Pound);
}
Ejemplo n.º 2
0
Unit::Unit() {
    const char *name = "--";
    if ((this->units = new_units(name)) == NULL) {
        throw Unit::CONVERSION_ERROR();
    }
    this->units_name = name;
}
Ejemplo n.º 3
0
TEST(UnitsInterface, BogusUnit)
{
  Units_t *Bogus = (Units_t*) NULL;

  std::cerr << "The purpose of this test is to throw to an exception. Error messages are expected." << std::endl;

  ASSERT_EQ((Units_t*) NULL, Bogus = new_units("foo"));
}
Ejemplo n.º 4
0
std::string Unit::setUnitName(const char *name) {
    CONV_FREE(this->units);

    if ((this->units = new_units(name)) == NULL) {
        throw Unit::CONVERSION_ERROR();
    }
    this->units_name = name;
    return(this->units_name);
}