xtd 0.2.0
Loading...
Searching...
No Matches
math_valid.cpp

Shows how to create your own xtd::tunit::valid class.

#include <xtd/xtd.tunit>
#include <algorithm>
class math_valid final : private xtd::tunit::base_assert {
public:
template<typename TValue1, typename TValue2>
static void is_max(TValue1 value1, TValue2 value2) {is_max(value1, value2, "", xtd::diagnostics::stack_frame());}
template<typename TValue1, typename TValue2>
static void is_max(TValue1 value1, TValue2 value2, const xtd::diagnostics::stack_frame& stack_frame) {is_max(value1, value2, "", stack_frame);}
template<typename TValue1, typename TValue2>
static void is_max(TValue1 value1, TValue2 value2, const std::string& message) {is_max(value1, value2, message, xtd::diagnostics::stack_frame());}
template<typename TValue1, typename TValue2>
static void is_max(TValue1 value1, TValue2 value2, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame) {
try {
if (std::max(value1, value2) == value1)
base_assert::succeed(message, stack_frame);
else
base_assert::fail("greater of " + base_assert::to_string(value2), base_assert::to_string(value1), message, stack_frame);
} catch(...) {
}
}
template<typename TValue1, typename TValue2>
static void is_min(TValue1 value1, TValue2 value2) {is_min(value1, value2, "", xtd::diagnostics::stack_frame());}
template<typename TValue1, typename TValue2>
static void is_min(TValue1 value1, TValue2 value2, const xtd::diagnostics::stack_frame& stack_frame) {is_min(value1, value2, "", stack_frame);}
template<typename TValue1, typename TValue2>
static void is_min(TValue1 value1, TValue2 value2, const std::string& message) {is_min(value1, value2, message, xtd::diagnostics::stack_frame());}
template<typename TValue1, typename TValue2>
static void is_min(TValue1 value1, TValue2 value2, const std::string& message, const xtd::diagnostics::stack_frame& stack_frame) {
try {
if (std::min(value1, value2) == value1)
base_assert::succeed(message, stack_frame);
else
base_assert::fail("lesser of " + base_assert::to_string(value2), base_assert::to_string(value1), message, stack_frame);
} catch(...) {
}
}
};
class test_class_(math_test) {
public:
void test_method_(test_case_success) {
math_valid::is_max(100, 20);
}
void test_method_(test_case_failed) {
math_valid::is_max(20, 100);
}
};
auto main() -> int {
}
// This code can produce the following output :
//
// Start 2 tests from 1 test case
// Run tests:
// SUCCEED math_test.test_case_success (0 ms total)
// FAILED math_test.test_case_failed (0 ms total)
// Expected: greater of 100
// But was: 20
// Stack Trace: in |---OMITTED---|/math_valid.cpp:47
//
// Test results:
// SUCCEED 1 test.
// FAILED 1 test.
// End 2 tests from 1 test case ran. (0 ms total)
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.hpp:47
The base class for assert.
Definition base_assert.hpp:29
static void error()
Throws an xtd::tunit::assert_error exception. 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.
The console_unit_test class is console unit test interface.
Definition console_unit_test.hpp:23
int32 run() noexcept
Runs all tests in this unit_test object and prints the result.
#define test_method_(method_name)
Add test method to class test.
Definition test_method_attribute.hpp:73