void CompileTimeArithmetic_unit_value_add() { typedef unit_value_t<meters, 3, 2> mRatio; using sum = unit_value_add<mRatio, mRatio>; ASSERT_EQUAL(meter_t(3.0), sum::value()); ASSERT((traits::is_unit_value_t_category<category::length_unit, sum>)); typedef unit_value_t<feet, 1> ftRatio; using sumf = unit_value_add<ftRatio, mRatio>; ASSERT((std::is_same_v<typename std::decay<foot_t>::type, typename std::decay<decltype(sumf::value())>::type>)); ASSERT_EQUAL_DELTA(5.92125984, sumf::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::length_unit, sumf>)); typedef unit_value_t<celsius, 1> cRatio; typedef unit_value_t<fahrenheit, 2> fRatio; using sumc = unit_value_add<cRatio, fRatio>; ASSERT((std::is_same<typename std::decay<celsius_t>::type, typename std::decay<decltype(sumc::value())>::type>::value)); ASSERT_EQUAL_DELTA(2.11111111111, sumc::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::temperature_unit, sumc>)); typedef unit_value_t<angle::radian, 1> rRatio; typedef unit_value_t<angle::degree, 3> dRatio; using sumr = unit_value_add<rRatio, dRatio>; ASSERT((std::is_same<typename std::decay<angle::radian_t>::type, typename std::decay<decltype(sumr::value())>::type>::value)); ASSERT_EQUAL_DELTA(1.05235988, sumr::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::angle_unit, sumr>)); }
void CompileTimeArithmetic_unit_value_subtract() { typedef unit_value_t<meters, 3, 2> mRatio; using diff = unit_value_subtract<mRatio, mRatio>; ASSERT_EQUAL(meter_t(0), diff::value()); ASSERT((traits::is_unit_value_t_category<category::length_unit, diff>)); typedef unit_value_t<feet, 1> ftRatio; using difff = unit_value_subtract<ftRatio, mRatio>; ASSERT((std::is_same_v< std::decay_t<foot_t>, std::decay_t<decltype(difff::value())>>)); ASSERT_EQUAL_DELTA(-3.92125984, difff::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::length_unit, difff>)); typedef unit_value_t<celsius, 1> cRatio; typedef unit_value_t<fahrenheit, 2> fRatio; using diffc = unit_value_subtract<cRatio, fRatio>; ASSERT((std::is_same<typename std::decay<celsius_t>::type, typename std::decay<decltype(diffc::value())>::type>::value)); ASSERT_EQUAL_DELTA(-0.11111111111, diffc::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::temperature_unit, diffc>)); typedef unit_value_t<angle::radian, 1> rRatio; typedef unit_value_t<angle::degree, 3> dRatio; using diffr = unit_value_subtract<rRatio, dRatio>; ASSERT((std::is_same<typename std::decay<angle::radian_t>::type, typename std::decay<decltype(diffr::value())>::type>::value)); ASSERT_EQUAL_DELTA(0.947640122, diffr::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::angle_unit, diffr>)); }
void CompileTimeArithmetic_unit_value_sqrt() { typedef unit_value_t<square_meters, 10> mRatio; using root = unit_value_sqrt<mRatio>; ASSERT((std::is_convertible<typename std::decay<meter_t>::type, typename std::decay<decltype(root::value())>::type>::value)); ASSERT_EQUAL_DELTA(3.16227766017, root::value().to<double>(), 5.0e-9); ASSERT((traits::is_unit_value_t_category<category::length_unit, root>)); typedef unit_value_t<hectare, 51, 7> hRatio; using rooth = unit_value_sqrt<hRatio, 100000000>; ASSERT((std::is_convertible<typename std::decay<mile_t>::type, typename std::decay<decltype(rooth::value())>::type>::value)); ASSERT_EQUAL_DELTA(2.69920623253, rooth::value().to<double>(), 5.0e-8); ASSERT_EQUAL_DELTA(269.920623, rooth::value().convert<meters>().to<double>(), 5.0e-6); ASSERT((traits::is_unit_value_t_category<category::length_unit, rooth>)); typedef unit_value_t<steradian, 18, 10> rRatio; using rootr = unit_value_sqrt<rRatio>; ASSERT((traits::is_angle_unit<decltype(rootr::value())>)); ASSERT_EQUAL_DELTA(1.3416407865, rootr::value().to<double>(), 5.0e-8); ASSERT_EQUAL_DELTA(76.870352574, rootr::value().convert<angle::degrees>().to<double>(), 5.0e-6); ASSERT((traits::is_unit_value_t_category<category::angle_unit, rootr>)); }
void AnythingConstructorsTest::FloatConstrTest() // Test if the dafault constructor generates an anything-object with good reactions. { // The method called now are assumed to work correctly (they are being tested later on). Anything anyHlp = fFloat; ASSERT( fFloat.GetType() == AnyDoubleType ); ASSERT_EQUAL( fFloat.IsNull(), false ); ASSERT_EQUAL( fFloat.IsNull(), false ); ASSERT( fFloat.IsNull() == 0 ); ASSERT_EQUAL( fFloat.GetSize(), 1L ); ASSERT( fFloat == anyHlp ); ASSERT( !(fFloat != anyHlp) ); ASSERT( fFloat.IsEqual(anyHlp) ); // here we use 14 significant digits fFloat = -24.490123456789; double testDouble = -24.490123456789; ASSERT_EQUAL_DELTA( testDouble, fFloat.AsDouble(0), 0.000000000001 ); ASSERT_EQUAL( "-24.4901234567", fFloat.AsString().SubString(0, 14) ); ASSERT_EQUAL( "-24.490123456789", fFloat.AsString() ); ASSERT_EQUAL( -24L, fFloat.AsLong() ); ASSERT_EQUAL( -24L, fFloat.AsLong(1234) ); ASSERT( !fFloat.AsBool() ); ASSERT( fFloat.AsBool(true) ); ASSERT_EQUAL( 0, fFloat.AsBool() ); ASSERT_EQUAL_DELTA( (double) - 24.4901, fFloat.AsDouble(), 0.0001 ); ASSERT( fFloat.AsDouble(2.3) == (double) - 24.490123456789 ); ASSERT( fFloat.AsDouble(2.3) != (double) - 24.4901 ); DummyIFAObj testObj("Test"), testObjDummy("TestObjDummy"); // We use a DummyIFAObj, it is the simples IFAObject that can be instantiated ASSERT( fFloat.AsIFAObject(&testObj) == &testObj ); ASSERT( fFloat.AsIFAObject(&testObj) != &testObjDummy ); ASSERT( fFloat.AsIFAObject() == NULL ); ASSERT_EQUAL( 16, fFloat.AsString().Length() ); ASSERT_EQUAL( "-24.490123456789", fFloat.AsString("Default") ); ASSERT( !fFloat.Contains("testSlot") ); ASSERT_LESS( fFloat.FindValue("testSlot"), 0L ); // Does it survive? fFloat.Remove(-1L); fFloat.Remove(0L); fFloat.Remove(1L); ASSERT_LESS( fFloat.FindIndex("testSlots"), 0L ); ASSERT_EQUAL( fFloat.IsDefined("testSlots"), false ); ASSERT( fFloat.SlotName(0) == NULL ); ASSERT( fFloat.At(-1L) == fFloat.At(0L) ); ASSERT( (fFloat.At(0L)).AsLong(3L) == 3L ); ASSERT( fFloat.At(1L) == NULL ); ASSERT( fFloat[1L] == NULL ); Anything anyTest = -24.51; ASSERT( anyTest.AsLong() == -24L ); }
void test_c_ImpostoVeiculo() { Automovel a1("Fiat",5,1997,"gasolina",1200); Camiao c1("Ford",3,1999,"gasolina",1400,1000); Bicicleta b1("XX",4,2002,"TodoTerreno"); ASSERT_EQUAL_DELTA(29.06, a1.calcImposto(),0.001); ASSERT_EQUAL_DELTA(45.15,c1.calcImposto(),0.001); ASSERT_EQUAL_DELTA(0,b1.calcImposto(),0.001); }
void GridContainerTest::testGetSet(){ const int X = 9; const int Y = 4; const int Z = 7; //const int TOTAL_VALS = (X+1) * (Y+1) * (Z+1); const double TEST_VAL = 1.3; Point point(X, Y, Z); GridContainer gc(point); gc.clear(TEST_VAL); ASSERT_EQUAL_DELTA(TEST_VAL, gc.getValue(Coordinates<int>(0,0,0)), 0.00001); ASSERT_EQUAL_DELTA(TEST_VAL, gc.getValue(Coordinates<int>(X-4,Y-1,Z-2)), 0.00001); ASSERT_EQUAL_DELTA(TEST_VAL, gc.getValue(Coordinates<int>(X,Y,Z)), 0.00001); }
void CompileTimeArithmetic_unit_value_power() { typedef unit_value_t<meters, 2> mRatio; using sq = unit_value_power<mRatio, 2>; ASSERT((std::is_convertible<typename std::decay<square_meter_t>::type, typename std::decay<decltype(sq::value())>::type>::value)); ASSERT_EQUAL_DELTA(4, sq::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::area_unit, sq>)); typedef unit_value_t<angle::radian, 18, 10> rRatio; using sqr = unit_value_power<rRatio, 2>; ASSERT((std::is_convertible<typename std::decay<steradian_t>::type, typename std::decay<decltype(sqr::value())>::type>::value)); ASSERT_EQUAL_DELTA(3.24, sqr::value().to<double>(), 5.0e-8); ASSERT_EQUAL_DELTA(10636.292574038049895092690529904, (sqr::value().convert<degrees_squared>().to<double>()), 5.0e-10); ASSERT((traits::is_unit_value_t_category<category::solid_angle_unit, sqr>)); }
void test_f_CalculoImposto() { Veiculo *v1 =new Automovel("Fiat",5,1997,"gasolina",1200); Veiculo *v2= new Camiao("Ford",3,1999,"gasolina",1400,1000); Veiculo *v3=new Bicicleta("XX",4,2002,"TodoTerreno"); Frota f; f.adicionaVeiculo(v1); f.adicionaVeiculo(v2); f.adicionaVeiculo(v3); ASSERT_EQUAL_DELTA(74.21, f.totalImposto(),0.001); }
void AnythingConstructorsTest::DoubleConstr1Test() { // Test if the dafault constructor generates an anything-object with good reactions. // The method called now are assumed to work correctly (they are being tested later on). // fDouble2 = 8.1; there is no exact binary representation Anything anyHlp = fDouble2; ASSERT( fDouble2.GetType() == AnyDoubleType ); ASSERT_EQUAL( fDouble2.IsNull(), false ); ASSERT_EQUAL( fDouble2.IsNull(), false ); ASSERT( fDouble2.IsNull() == 0 ); ASSERT_EQUAL( fDouble2.GetSize(), 1L ); ASSERT( fDouble2 == anyHlp ); ASSERT( !(fDouble2 != anyHlp) ); ASSERT( fDouble2.IsEqual(anyHlp) ); ASSERT_EQUAL( "8.1", fDouble2.AsString().SubString(0, 6) ); ASSERT_EQUAL( "8.1", fDouble2.AsString() ); ASSERT_EQUAL( "8.1", fDouble2.AsString("Default") ); ASSERT_EQUAL( 8L, fDouble2.AsLong() ); ASSERT_EQUAL( 8L, fDouble2.AsLong(1234) ); ASSERT( !fDouble2.AsBool() ); ASSERT( fDouble2.AsBool(true) ); ASSERT_EQUAL_DELTA( 8.1, fDouble2.AsDouble(), 0.1 ); DummyIFAObj testObj("Test"), testObjDummy("TestObjDummy"); // We use a DummyIFAObj, it is the simplest IFAObject that can be instantiated ASSERT( fDouble2.AsIFAObject(&testObj) == &testObj ); ASSERT( fDouble2.AsIFAObject(&testObj) != &testObjDummy ); ASSERT( fDouble2.AsIFAObject() == NULL ); ASSERT_EQUAL( fDouble2.Contains("testSlot"), false ); ASSERT_LESS( fDouble2.FindValue("testSlot"), 0L ); // Does it survive? fDouble2.Remove(-1L); fDouble2.Remove(0L); fDouble2.Remove(1L); ASSERT_LESS( fDouble2.FindIndex("testSlots"), 0L ); ASSERT_EQUAL( fDouble2.IsDefined("testSlots"), false ); ASSERT( fDouble2.SlotName(0) == NULL ); ASSERT( fDouble2.At(-1L) == fDouble2.At(0L) ); ASSERT_EQUAL( (fDouble2.At(0L)).AsLong(-2), -2L ); ASSERT( fDouble2.At(1L) == NULL ); ASSERT( fDouble2[1L] == NULL ); }
void CompileTimeArithmetic_unit_value_multiply() { typedef unit_value_t<meters, 2> mRatio; typedef unit_value_t<feet, 656168, 100000> ftRatio; // 2 meter using product = unit_value_multiply<mRatio, mRatio>; ASSERT_EQUAL(square_meter_t(4), product::value()); ASSERT((traits::is_unit_value_t_category<category::area_unit, product>)); using productM = unit_value_multiply<mRatio, ftRatio>; ASSERT( (std::is_same_v< std::decay_t<square_meter_t>, std::decay_t<decltype(productM::value())>>)); ASSERT_EQUAL_DELTA(4.0, productM::value().to<double>(), 5.0e-7); ASSERT((traits::is_unit_value_t_category<category::area_unit, productM>)); using productF = unit_value_multiply<ftRatio, mRatio>; ASSERT((std::is_same<typename std::decay<square_foot_t>::type, typename std::decay<decltype(productF::value())>::type>::value)); ASSERT_EQUAL_DELTA(43.0556444224, productF::value().to<double>(), 5.0e-6); ASSERT((traits::is_unit_value_t_category<category::area_unit, productF>)); using productF2 = unit_value_multiply<ftRatio, ftRatio>; ASSERT((std::is_same<typename std::decay<square_foot_t>::type, typename std::decay<decltype(productF2::value())>::type>::value)); ASSERT_EQUAL_DELTA(43.0556444224, productF2::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::area_unit, productF2>)); typedef unit_value_t<units::force::newton, 5> nRatio; using productN = unit_value_multiply<nRatio, ftRatio>; ASSERT(!(std::is_same<typename std::decay<torque::newton_meter_t>::type, typename std::decay<decltype(productN::value())>::type>::value)); ASSERT((std::is_convertible<typename std::decay<torque::newton_meter_t>::type, typename std::decay<decltype(productN::value())>::type>::value)); ASSERT_EQUAL_DELTA(32.8084, productN::value().to<double>(), 5.0e-8); ASSERT_EQUAL_DELTA(10.0, (productN::value().convert<newton_meter>().to<double>()), 5.0e-7); ASSERT((traits::is_unit_value_t_category<category::torque_unit, productN>)); typedef unit_value_t<angle::radian, 11, 10> r1Ratio; typedef unit_value_t<angle::radian, 22, 10> r2Ratio; using productR = unit_value_multiply<r1Ratio, r2Ratio>; ASSERT((std::is_same<typename std::decay<steradian_t>::type, typename std::decay<decltype(productR::value())>::type>::value)); ASSERT_EQUAL_DELTA(2.42, productR::value().to<double>(), 5.0e-8); ASSERT_EQUAL_DELTA(7944.39137, (productR::value().convert<degrees_squared>().to<double>()), 5.0e-6); ASSERT((traits::is_unit_value_t_category<category::solid_angle_unit, productR>)); }
void CompileTimeArithmetic_unit_value_divide() { typedef unit_value_t<meters, 2> mRatio; typedef unit_value_t<feet, 656168, 100000> ftRatio; // 2 meter using product = unit_value_divide<mRatio, mRatio>; ASSERT_EQUAL(scalar_t(1), product::value()); ASSERT((traits::is_unit_value_t_category<category::scalar_unit, product>)); using productM = unit_value_divide<mRatio, ftRatio>; ASSERT((std::is_same<typename std::decay<scalar_t>::type, typename std::decay<decltype(productM::value())>::type>::value)); ASSERT_EQUAL_DELTA(1., productM::value().to<double>(), 5.0e-7); ASSERT((traits::is_unit_value_t_category<category::scalar_unit, productM>)); using productF = unit_value_divide<ftRatio, mRatio>; ASSERT((std::is_same<typename std::decay<scalar_t>::type, typename std::decay<decltype(productF::value())>::type>::value)); ASSERT_EQUAL_DELTA(1.0, productF::value().to<double>(), 5.0e-6); ASSERT((traits::is_unit_value_t_category<category::scalar_unit, productF>)); using productF2 = unit_value_divide<ftRatio, ftRatio>; ASSERT((std::is_same<typename std::decay<scalar_t>::type, typename std::decay<decltype(productF2::value())>::type>::value)); ASSERT_EQUAL_DELTA(1.0, productF2::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::scalar_unit, productF2>)); typedef unit_value_t<seconds, 10> sRatio; using productMS = unit_value_divide<mRatio, sRatio>; ASSERT((std::is_same<typename std::decay<meters_per_second_t>::type, typename std::decay<decltype(productMS::value())>::type>::value)); ASSERT_EQUAL_DELTA(0.2, productMS::value().to<double>(), 5.0e-8); ASSERT((traits::is_unit_value_t_category<category::velocity_unit, productMS>)); typedef unit_value_t<angle::radian, 20> rRatio; using productRS = unit_value_divide<rRatio, sRatio>; ASSERT((std::is_same<typename std::decay<radians_per_second_t>::type, typename std::decay<decltype(productRS::value())>::type>::value)); ASSERT_EQUAL_DELTA(2, productRS::value().to<double>(), 5.0e-8); ASSERT_EQUAL_DELTA(114.592, (productRS::value().convert<degrees_per_second>().to<double>()), 5.0e-4); ASSERT((traits::is_unit_value_t_category<category::angular_velocity_unit, productRS>)); }
void distanceTest_08(){ Point a = Point(-1,-1); Point b = Point(1,1); ASSERT_EQUAL_DELTA(2*sqrt(2),myDistance(a,b),0.000001); }
void distanceTest_07(){ Point a = Point(1,0); Point b = Point(0,1); ASSERT_EQUAL_DELTA(sqrt(2),myDistance(a,b),0.000001); }