TEST(ReachabilitySphere, appendDirection)
{
    ReachabilitySphere sphere;

    sphere.appendDirection(0.0, 0.0, true);
    sphere.appendDirection(0.0, 90.0, false);

    sphere.appendDirection(0.0, 1.0, 0.0, true);
    sphere.appendDirection(0.0, 0.0, 1.0, false);

    ASSERT_TRUE(sphere._reachableDirections[0].x == 0.0);
    ASSERT_TRUE(sphere._reachableDirections[0].y == 0.0);
    ASSERT_TRUE(sphere._reachableDirections[0].z == 1.0);

    ASSERT_TRUE(sphere._unreachableDirections[0].x == 1.0);
    ASSERT_TRUE(sphere._unreachableDirections[0].y == 0.0);
    ASSERT_TRUE(fuzzyEquals(sphere._unreachableDirections[0].z, 0.0));

    ASSERT_TRUE(sphere._reachableDirections[1].x == 0.0);
    ASSERT_TRUE(sphere._reachableDirections[1].y == 1.0);
    ASSERT_TRUE(sphere._reachableDirections[1].z == 0.0);

    ASSERT_TRUE(sphere._unreachableDirections[1].x == 0.0);
    ASSERT_TRUE(sphere._unreachableDirections[1].y == 0.0);
    ASSERT_TRUE(sphere._unreachableDirections[1].z == 1.0);
}
Exemple #2
0
void Assert::assertEqualsEpsilon( const double& expected, const double& result, const double& epsilon,
		const char* file, int linia )
{
	if (isNaN(expected) && isNaN(result) ) return;
	if (!isNaN(expected) && !isNaN(result) && fuzzyEquals(expected, result, epsilon) ) return;

	TestsListener::theInstance().errorsLog() 
			<< errmsgTag_testFailedIn() << file
			<< errmsgTag_inLine() << linia << "\n" 
			<< errmsgTag_expected()
			<< bold() << expected << normal() << " "
			<< errmsgTag_butWas() 
			<< bold() << result << normal() << "\n";
	TestsListener::theInstance().testHasFailed();
}
void assertEqualsEpsilon(const double & expected, const double & result
                         , const double & epsilon, const char * file, int line)
{
  if ( ( isNaN(expected) && isNaN(result) )
      ||
      ( !isNaN(expected) && !isNaN(result)
      && fuzzyEquals( expected, result, epsilon ) ) )
  {
    return;
  }

  std::stringstream errmsg;
  errmsg.str("");
  errmsg << "assertEquals(double) failed in " << file << ", line #" << line;
  errmsg << " expecting '" << expected << "' got '" << result << "'";
  TestsListener::testHasFailed(errmsg.str());
}
Exemple #4
0
void example_test_class::test_assert_equals()
{
  logMsg("ASSERT_EQUALS() macro demo");
  /*
   Be careful: ASSERT_EQUALS() is not available for each and every type!
   You can find more details in test_asserts.h.
   */
  int a=-1;
  ASSERT_EQUALS(a, a);

  unsigned int h=1;
  ASSERT_EQUALS(h, h);

  int64_t i=-10;
  ASSERT_EQUALS(i, i);

  uint64_t j=10;
  ASSERT_EQUALS(j, j);

  bool b=false;
  ASSERT_EQUALS(b, b);

  float c= -1.23f;
  ASSERT_EQUALS(c, c);

  double d=1.23;
  ASSERT_EQUALS(d, d);

  /*
   For fuzzy comparisons e.g. 1.01 vs. 1.01 fetched from MySQL
   */
  double k = 1.01;
  double l = 1.0999992;
  fuzzyEquals(k, l, 0.001);

  long double e=1.23e12;
  ASSERT_EQUALS(e, e);

  const char f[]="foo";
  ASSERT_EQUALS(f, f);

  std::string g("good idea");
  ASSERT_EQUALS(g, g);
}
TEST(ReachabilitySphere, getPrincipalComponents)
{
    ReachabilitySphere sphere;
    std::vector<Vector> vectors;
    std::vector<Vector> components;

    // a line in x direction should give the main principal component lying in x direction
    vectors.push_back(Vector(0.0, 0.0, 0.0));
    vectors.push_back(Vector(1.0, 0.0, 0.0));
    vectors.push_back(Vector(2.0, 0.0, 0.0));
    vectors.push_back(Vector(3.0, 0.0, 0.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(components[2].x == 1.0);
    ASSERT_TRUE(components[2].y == 0.0);
    ASSERT_TRUE(components[2].z == 0.0);

    vectors.clear();

    // a line in y direction should give the main principal component lying in y direction
    vectors.push_back(Vector(0.0, 0.0, 0.0));
    vectors.push_back(Vector(0.0, 1.0, 0.0));
    vectors.push_back(Vector(0.0, 2.0, 0.0));
    vectors.push_back(Vector(0.0, 3.0, 0.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(components[2].x == 0.0);
    ASSERT_TRUE(components[2].y == 1.0);
    ASSERT_TRUE(components[2].z == 0.0);

    vectors.clear();

    // a line in z direction should give the main principal component lying in z direction
    vectors.push_back(Vector(0.0, 0.0, 0.0));
    vectors.push_back(Vector(0.0, 0.0, 1.0));
    vectors.push_back(Vector(0.0, 0.0, 2.0));
    vectors.push_back(Vector(0.0, 0.0, 3.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(components[2].x == 0.0);
    ASSERT_TRUE(components[2].y == 0.0);
    ASSERT_TRUE(components[2].z == 1.0);

    vectors.clear();

    // filling just x and y directions should give the least principal component in z direction
    vectors.push_back(Vector(1.0, 2.0, 0.0));
    vectors.push_back(Vector(2.0, 1.0, 0.0));
    vectors.push_back(Vector(1.0, 0.0, 0.0));
    vectors.push_back(Vector(0.0, 1.0, 0.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(components[0].x == 0.0);
    ASSERT_TRUE(components[0].y == 0.0);
    ASSERT_TRUE(components[0].z == 1.0);

    vectors.clear();

    // filling just y and z directions should give the least principal component in x direction
    vectors.push_back(Vector(0.0, 2.0, 0.0));
    vectors.push_back(Vector(0.0, 1.0, 2.0));
    vectors.push_back(Vector(0.0, 0.0, 1.0));
    vectors.push_back(Vector(0.0, 1.0, 1.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(components[0].x == 1.0);
    ASSERT_TRUE(components[0].y == 0.0);
    ASSERT_TRUE(components[0].z == 0.0);

    vectors.clear();

    // filling just x and z directions should give the least principal component in y direction
    vectors.push_back(Vector(1.0, 0.0, 0.0));
    vectors.push_back(Vector(2.0, 0.0, 2.0));
    vectors.push_back(Vector(2.0, 0.0, 1.0));
    vectors.push_back(Vector(0.0, 0.0, 1.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(components[0].x == 0.0);
    ASSERT_TRUE(components[0].y == 1.0);
    ASSERT_TRUE(components[0].z == 0.0);

    vectors.clear();

    // a line in x-y direction should give the main principal component lying in x-y direction
    vectors.push_back(Vector(0.0, 0.0, 0.0));
    vectors.push_back(Vector(1.0, 1.0, 0.0));
    vectors.push_back(Vector(2.0, 2.0, 0.0));
    vectors.push_back(Vector(3.0, 3.0, 0.0));
    
    components = sphere.getPrincipalComponents(vectors);

    ASSERT_TRUE(fuzzyEquals(std::abs(components[2].x), 0.707106781));
    ASSERT_TRUE(fuzzyEquals(std::abs(components[2].y), 0.707106781));
    ASSERT_TRUE(components[2].z == 0.0);


    // test Capability of type cone
    Capability cone(CONE, 70.0, 55.0, 35.0);
    
    sphere = createReachabilitySphereFromCapability(cone, 400);

    components = sphere.getPrincipalComponents(sphere._reachableDirections);

    // test phi
    ASSERT_TRUE(atan2(components[0].y, components[0].x) * 180.0 / M_PI < 72.0);
    ASSERT_TRUE(atan2(components[0].y, components[0].x) * 180.0 / M_PI > 68.0);

    // test theta
    ASSERT_TRUE(acos(components[0].z) * 180.0 / M_PI < 56.0);
    ASSERT_TRUE(acos(components[0].z) * 180.0 / M_PI > 54.0);


    // test Capability of type cylinder_1
    Capability cylinder1(CYLINDER_1, 70.0, 55.0, 35.0);
    
    sphere = createReachabilitySphereFromCapability(cylinder1, 400);

    components = sphere.getPrincipalComponents(sphere._reachableDirections);

    // test phi
    ASSERT_TRUE(atan2(components[2].y, components[2].x) * 180.0 / M_PI < 72.0);
    ASSERT_TRUE(atan2(components[2].y, components[2].x) * 180.0 / M_PI > 68.0);

    // test theta
    ASSERT_TRUE(acos(components[2].z) * 180.0 / M_PI < 56.0);
    ASSERT_TRUE(acos(components[2].z) * 180.0 / M_PI > 54.0);


    // test Capability of type cylinder_2
    Capability cylinder2(CYLINDER_2, 70.0, 55.0, 35.0);
    
    sphere = createReachabilitySphereFromCapability(cylinder2, 400);

    components = sphere.getPrincipalComponents(sphere._reachableDirections);

    // test phi
    ASSERT_TRUE(atan2(components[0].y, components[0].x) * 180.0 / M_PI < 72.0);
    ASSERT_TRUE(atan2(components[0].y, components[0].x) * 180.0 / M_PI > 68.0);

    // test theta
    ASSERT_TRUE(acos(components[0].z) * 180.0 / M_PI < 56.0);
    ASSERT_TRUE(acos(components[0].z) * 180.0 / M_PI > 54.0);
}