Example #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);
}
Example #2
0
UCFn *Unit::Conversion_to (const Unit *other) {
    UnitsConvFn_t conv_fn;

    if (conv_fn_u(this->units, other->units, &conv_fn) != CONV_OK) {
        throw CONVERSION_ERROR();
    }
    return ( new UCFn(other->units_name.c_str(), this->units_name.c_str(), conv_fn.C[1], conv_fn.C[0]) );
}
Example #3
0
double Unit::Convert_to (double val, const Unit *other) {
    UnitsConvFn_t conv_fn;

    if (conv_fn_u(this->units, other->units, &conv_fn) != CONV_OK) {
        throw Unit::CONVERSION_ERROR();
    }
    return ( conv_fn.C[1]* val + conv_fn.C[0] );
}