xtd 0.2.0
base_assert.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../tunit_export.hpp"
6#define __XTD_TUNIT_INTERNAL__
9#define __XTD_TUNIT_INTERNAL__
10#include "abort_error.hpp"
11#include "assert_error.hpp"
12#include "ignore_error.hpp"
13#include <xtd/math>
14#include <xtd/static>
15#include <xtd/types>
16#include <xtd/typeof>
17#include <xtd/string>
18#include <xtd/diagnostics/stack_frame>
19
21namespace xtd {
23 namespace tunit {
31 public:
33
51
68 static void fail(const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
69
86
103
104 protected:
106
114 static void error();
121 static void error(const xtd::string& message);
128 static void error(const xtd::string& actual, const xtd::string& expected, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
129
136 static void fail(const xtd::string& actual, const xtd::string& expected, const xtd::string& message, const xtd::diagnostics::stack_frame& stack_frame = xtd::diagnostics::stack_frame::current());
137
141 template<class value_t>
142 static xtd::string to_string(const value_t& value) {return __tunit_to_string(value);}
146 template<class value_t>
147 static xtd::string to_string(const value_t* value) {return __tunit_to_string(value);}
148
152 template<class collection_t>
153 static xtd::string join_items(const collection_t& collection) {return __tunit_join__items(collection);}
159
161
167 template<class value_a_t, class value_b_t>
168 static bool equals(const value_a_t& value_a, const value_b_t& value_b) {
169 return value_a == value_b;
170 }
175 template<class char_t>
176 static bool equals(const char_t* value_a, const string& value_b) {
177 return xtd::string {value_a} == value_b;
178 }
183 template<class char_t>
184 static bool equals(const string& value_a, const char_t* value_b) {
185 return value_a == xtd::string {value_b};
186 }
191 static bool equals(long double value_a, long double value_b) {
192 return equals(value_a, value_b, 0.0001l);
193 }
198 static bool equals(double value_a, double value_b) {
199 return equals(value_a, value_b, 0.0001);
200 }
205 static bool equals(float value_a, float value_b) {
206 return equals(value_a, value_b, 0.0001f);
207 }
213 static bool equals(double value_a, double value_b, double tolerance) {
214 return value_a == value_b ? true : xtd::math::abs(value_a - value_b) <= (xtd::math::abs(tolerance) * xtd::math::max(xtd::math::abs(value_a), xtd::math::abs(value_b)));
215 }
221 static bool equals(long double value_a, long double value_b, long double tolerance) {
222 return value_a == value_b ? true : xtd::math::abs(value_a - value_b) <= (xtd::math::abs(tolerance) * xtd::math::max(xtd::math::abs(value_a), xtd::math::abs(value_b)));
223 }
229 static bool equals(float value_a, float value_b, float tolerance) {
230 return value_a == value_b ? true : xtd::math::abs(value_a - value_b) <= (xtd::math::abs(tolerance) * xtd::math::max(xtd::math::abs(value_a), xtd::math::abs(value_b)));
231 }
233
234 private:
235 static bool is_debug() noexcept;
236 };
237 }
238}
Contains std::basic_ostream<char_t, char_traits_t>& operator <<(std::basic_ostream<char_t,...
Contains__tunit_join__items functions.
Contains xtd::tunit::abort_error exception.
Contains xtd::tunit::assert_error exception.
Represents text as a sequence of character units.
Definition basic_string.hpp:71
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:48
static stack_frame current(const xtd::diagnostics::source_location &value=xtd::diagnostics::source_location::current()) noexcept
Crates a new xtd::diagnostics::stack_frame object corresponding to the location of the call site.
static decimal abs(decimal value)
Returns the absolute value of a decimal number.
static xtd::byte max(xtd::byte a, xtd::byte b) noexcept
Returns the larger of two 8-bit unsigned integers.
The base class for assert.
Definition base_assert.hpp:30
static xtd::string join_items(const collection_t &collection)
Join specified collection into xtd::string.
Definition base_assert.hpp:153
static xtd::string join_items(const xtd::string &str)
Join specified string into xtd::string.
static void ignore(const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Ignore current test. This is used by the other assert functions.
static void succeed(const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Generates a success with a generic message. This is used by the other assert functions.
static bool equals(double value_a, double value_b, double tolerance)
Determines if specified values are equal with tolerance.
Definition base_assert.hpp:213
static void fail(const xtd::string &actual, const xtd::string &expected, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Throws an xtd::tunit::assert_error exception. This is used by the other assert functions.
static bool equals(float value_a, float value_b, float tolerance)
Determines if specified values are equal with tolerance.
Definition base_assert.hpp:229
static void ignore(const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Ignore current test. This is used by the other assert functions.
static xtd::string to_string(const value_t *value)
Convert specified value to xtd::string.
Definition base_assert.hpp:147
static void error()
Throws an xtd::tunit::assert_error exception. This is used by the other assert functions.
static void error(const xtd::string &message)
Throws an xtd::tunit::assert_error exception. This is used by the other assert functions.
static void error(const xtd::string &actual, const xtd::string &expected, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Throws an xtd::tunit::assert_error exception. This is used by the other assert functions.
static void fail(const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Throws an xtd::tunit::assert_error exception. This is used by the other assert functions.
static void abort(const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Abort current test. This is used by the other assert functions.
static void fail(const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Throws an xtd::tunit::assert_error exception. This is used by the other assert functions.
static void succeed(const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Generates a success with a generic message. This is used by the other assert functions.
static bool equals(const string &value_a, const char_t *value_b)
Determines if specified values are equal.
Definition base_assert.hpp:184
static bool equals(const value_a_t &value_a, const value_b_t &value_b)
Determines if specified values are equal.
Definition base_assert.hpp:168
static bool equals(double value_a, double value_b)
Determines if specified values are equal.
Definition base_assert.hpp:198
static xtd::string to_string(const value_t &value)
Convert specified value to xtd::string.
Definition base_assert.hpp:142
static void abort(const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Abort current test. This is used by the other assert functions.
static bool equals(const char_t *value_a, const string &value_b)
Determines if specified values are equal.
Definition base_assert.hpp:176
static bool equals(float value_a, float value_b)
Determines if specified values are equal.
Definition base_assert.hpp:205
static bool equals(long double value_a, long double value_b, long double tolerance)
Determines if specified values are equal with tolerance.
Definition base_assert.hpp:221
static bool equals(long double value_a, long double value_b)
Determines if specified values are equal.
Definition base_assert.hpp:191
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define tunit_export_
Define shared library export.
Definition tunit_export.hpp:13
Contains xtd::tunit::ignore_error exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10