void ribi::foam::PointsFileItem::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting ribi::foam::PointsFileItem::Test");
  //operator== and operator!=
  {
    const PointsFileItem i( Coordinat3D(1.1,2.2,3.3) );
    PointsFileItem j( Coordinat3D(2.2,3.3,4.4) );
    assert(i == i);
    assert(i != j);
    assert(j != i);
    assert(j == j);
  }
  //operator<< and operator>>
  {
    const PointsFileItem i( Coordinat3D(1.1,2.2,3.3) );
    std::stringstream s;
    s << i;
    PointsFileItem j;
    s >> j;
    if (i != j)
    {
      TRACE(i);
      TRACE(j);
    }
    assert(i == j);
  }
  TRACE("Finished ribi::foam::PointsFileItem::Test successfully");
}
예제 #2
0
ribi::PlaneZ::PlaneZ() noexcept
  : PlaneZ(
    Coordinat3D(0.0,0.0,0.0),
    Coordinat3D(1.0,0.0,0.0),
    Coordinat3D(0.0,1.0,0.0)
  )
{

}
예제 #3
0
double ribi::foam::Mesh::CalcSimilarityFaster(
  const std::vector<boost::shared_ptr<const ribi::Coordinat3D> >& v,
  const std::vector<ribi::Coordinat3D>& w) noexcept
{
  if (v.size() != w.size()) return std::numeric_limits<double>::max();
  //Sum all coordinats, distance equals the distance between the center points
  const Coordinat3D a = std::accumulate(v.begin(),v.end(),Coordinat3D(),
    [](const Coordinat3D& init, const boost::shared_ptr<const ribi::Coordinat3D> c)
    {
      return init + (*c);
    }
  );
  //for (const boost::shared_ptr<const ribi::Coordinat3D> c: v) { a += (*c); }
  const Coordinat3D b = std::accumulate(w.begin(),w.end(),Coordinat3D());
  return Distance(a,b);
}
void ribi::foam::PointsFile::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  TRACE("Starting ribi::foam::PointsFile::Test");
  //Some initial data
  const Header header("some_name","some_location","some_object");
  std::vector<PointsFileItem> items;
  for (int i=1; i!=4; ++i)
  {
    PointsFileItem item(
      Coordinat3D(
        static_cast<double>(i) * 1.1,
        static_cast<double>(i) * 2.2,
        static_cast<double>(i) * 3.3
      )
    );
    items.push_back(item);
  }
  //operator==
  {
    const PointsFile b(header,items);
    const PointsFile c(header,items);
    assert(header == header);
    assert(b == c);
  }
  //operator!=
  {
    const PointsFile b(header,items);
    const Header other_header("some_other_name","some_other_location","some_other_object");
    assert(header != other_header);
    const PointsFile c(other_header,items);
    assert(b != c);
  }
  //operator!=
  {
    const PointsFile b(header,items);
    std::vector<PointsFileItem> other_items;
    for (int i=1; i!=3; ++i)
    {
      PointsFileItem item(
        Coordinat3D(
          static_cast<double>(i) * 4.4,
          static_cast<double>(i) * 5.5,
          static_cast<double>(i) * 6.6
        )
      );
      other_items.push_back(item);
    }
    const PointsFile c(header,other_items);
    assert(b != c);
  }
  //Stream conversion
  {
    const PointsFile b(header,items);
    std::stringstream s;
    s << b;
    PointsFile c;
    s >> c;
    if (b != c)
    {
      TRACE(b);
      TRACE(c);
    }
    assert(b == c);
  }
  //Read from testing file
  for (int test_index = 0; test_index!=5; ++test_index)
  {
    std::string filename_appendix;
    switch (test_index)
    {
      case 0: filename_appendix = "_1x1x1"; break;
      case 1: filename_appendix = "_1x1x2"; break;
      case 2: filename_appendix = "_1x2x2"; break;
      case 3: filename_appendix = "_2x2x2"; break;
      case 4: filename_appendix = "_3x4x5"; break;
      default: assert(!"Should never get here");
        throw std::logic_error("foam::Files::CreateTestFiles: unknown test index");
    }
    assert(!filename_appendix.empty());
    const std::string filename_base { GetDefaultHeader().GetObject() };
    const std::string filename = filename_base + filename_appendix;
    const std::string resources_path { ":/CppOpenFoam/files/" + filename };

    {
      QFile f( resources_path.c_str() );
      f.copy(filename.c_str());
    }
    {
      if (!fileio::IsRegularFile(filename))
      {
        TRACE("ERROR");
        TRACE(filename);
      }
      assert(fileio::IsRegularFile(filename));
      PointsFile b(filename);
      if (b.GetItems().empty())
      {
        TRACE("ERROR");
      }
      assert(!b.GetItems().empty());
    }
  }
  TRACE("Finished ribi::foam::Header::PointsFile successfully");
}