ViennaLS
Loading...
Searching...
No Matches
lsTestAsserts.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <iostream>
5#include <lsCheck.hpp>
6#include <lsMesh.hpp>
7#include <sstream>
8#include <vcTestAsserts.hpp>
9#include <vector>
10
11#define LSTEST_ASSERT_VALID_LS(levelSet, NumericType, D) \
12 { \
13 auto check = viennals::Check<NumericType, D>(levelSet); \
14 check.apply(); \
15 if (check.isValid()) { \
16 std::cout << "SUCCESS" << std::endl; \
17 } else { \
18 throw std::runtime_error( \
19 std::string(__FILE__) + std::string(":") + \
20 std::to_string(__LINE__) + std::string(" in ") + \
21 std::string(__PRETTY_FUNCTION__) + "\n" + check.what()); \
22 } \
23 }
24
25#define LSTEST_ASSERT_MESH_CORNERS(mesh, expected, D, gridDelta) \
26 { \
27 try { \
28 auto &nodes = mesh->getNodes(); \
29 double tolerance = 0.01 * (gridDelta); \
30 for (const auto &ex : expected) { \
31 bool found = false; \
32 for (const auto &n : nodes) { \
33 double distSq = 0.; \
34 for (int i = 0; i < D; ++i) \
35 distSq += (n[i] - ex[i]) * (n[i] - ex[i]); \
36 if (distSq < tolerance) { \
37 found = true; \
38 break; \
39 } \
40 } \
41 if (!found) { \
42 std::stringstream ss; \
43 ss << "Corner not found: ("; \
44 for (int i = 0; i < D; ++i) \
45 ss << ex[i] << (i < D - 1 ? ", " : ""); \
46 ss << ")"; \
47 throw std::runtime_error(ss.str()); \
48 } \
49 } \
50 std::cout << "All expected corners found!" << std::endl; \
51 } catch (const std::exception &e) { \
52 throw std::runtime_error( \
53 std::string(__FILE__) + std::string(":") + \
54 std::to_string(__LINE__) + std::string(" in ") + \
55 std::string(__PRETTY_FUNCTION__) + "\n" + e.what()); \
56 } \
57 }