Skip to content

Commit

Permalink
feat: incorrect impl of 'assertNotEquals' on the test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRustifyer committed Sep 6, 2024
1 parent a7cdbd3 commit 9d5ecc6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
32 changes: 16 additions & 16 deletions zero/ifc/test-suite/assertions.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import concepts;

using namespace zero::concepts;

template <Printable T, Printable U>
constexpr inline void throw_on_failed_test(const T& expected, const U& actual);
template <Printable T, Printable U, typename Op>
constexpr inline void throw_on_failed_test(const T& expected, const U& actual, const Op& comp);

export {
/// @brief Compares two values. Generates a test failed if values are non-equal.
Expand All @@ -15,7 +15,7 @@ export {
template<typename T, typename U>
requires (!std::is_pointer_v<T> && !std::is_pointer_v<U>)
constexpr void assertEquals(const T& expected, const U& actual) {
::throw_on_failed_test(expected, actual);
::throw_on_failed_test(expected, actual, [](auto expected, auto actual){ return expected == actual; });
}

/// @brief Compares two values being T pointer types.
Expand All @@ -25,15 +25,15 @@ export {
const auto expected = *expected_ptr;
const auto actual = *actual_ptr;

::throw_on_failed_test(expected, actual);
::throw_on_failed_test(expected, actual, [](auto expected, auto actual){ return expected == actual; });
}


/// @brief Compares two values. Generates a test failed if the values are equals.
template<typename T>
requires (!std::is_pointer_v<T>)
constexpr void assertNotEquals(const T& expected, const T& actual) {
::throw_on_failed_test(expected, actual);
::throw_on_failed_test(expected, actual, [](auto expected, auto actual){ return expected != actual; });
}


Expand All @@ -45,7 +45,7 @@ export {
const auto expected = *expected_ptr;
const auto actual = *actual_ptr;

::throw_on_failed_test(expected, actual);
::throw_on_failed_test(expected, actual, [](auto expected, auto actual){ return expected != actual; });
}
}

Expand All @@ -67,9 +67,9 @@ public:

/// \brief helper to reduce cognitive complexity,
/// \enabled when the concept {\link @StringConvertible} is satisfied
template<typename T, typename U>
constexpr inline void throw_on_failed_test_str_impl(const T& expected, const U& actual) {
if (expected != actual) {
template<typename T, typename U, typename Op>
constexpr inline void throw_on_failed_test_str_impl(const T& expected, const U& actual, const Op& comp) {
if (!comp(expected, actual)) {
const auto expected_str = std::to_string(expected);
const auto actual_str = std::to_string(actual);

Expand All @@ -87,9 +87,9 @@ constexpr inline void throw_on_failed_test_str_impl(const T& expected, const U&

/// \brief helper to reduce cognitive complexity,
/// \enabled when the concept {\link @Ostreamable} is satisfied
template<typename T, typename U>
constexpr inline void throw_on_failed_test_oss_impl(const T& expected, const U& actual) {
if (expected != actual) {
template<typename T, typename U, typename Op>
constexpr inline void throw_on_failed_test_oss_impl(const T& expected, const U& actual, const Op& comp) {
if (!comp(expected, actual)) {
std::ostringstream oss;
oss << "Assertion failed: expected = ";
oss << expected;
Expand All @@ -100,10 +100,10 @@ constexpr inline void throw_on_failed_test_oss_impl(const T& expected, const U&
}
}

template <Printable T, Printable U>
constexpr inline void throw_on_failed_test(const T& expected, const U& actual) {
template <Printable T, Printable U, typename Op>
constexpr inline void throw_on_failed_test(const T& expected, const U& actual, const Op& comp) {
if constexpr (StringConvertible<T> && StringConvertible<U>)
throw_on_failed_test_str_impl(expected, actual);
throw_on_failed_test_str_impl(expected, actual, comp);
else
throw_on_failed_test_oss_impl(expected, actual);
throw_on_failed_test_oss_impl(expected, actual, comp);
}
7 changes: 6 additions & 1 deletion zero/tests/math/numbers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ void numbers_tests() {
assertEquals(10., real.number());

auto real_from_integer = Real(integer);
assertEquals(8, real_from_integer.number());
assertEquals(7, real_from_integer.number());

auto real_from_rational = Real(rational);
assertEquals(rational, real_from_rational.number());
});

TEST_CASE(numbers_suite, "Testing the Numbers types equalities", [] {
assertEquals(Natural(1), Natural(1));
assertEquals(Integer(-1), Integer(-1));

assertEquals(Rational(1, 2), Rational(1, 2));
assertNotEquals(Rational(1, 2), Rational(2, 4));
});

TEST_CASE(numbers_suite, "Arithmetic operations with Naturals", [] {
Expand Down
4 changes: 2 additions & 2 deletions zork_config/zork_clang.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ cpp_compiler = "clang"
driver_path = "clang++" # This binary is soft linked and included in our local path
cpp_standard = "23"
std_lib = "LIBCPP"
std_lib_installed_dir = "/usr/local/share/libc++/v1"
# std_lib_installed_dir = "C:/msys64/clang64/share/libc++/v1"
# std_lib_installed_dir = "/usr/local/share/libc++/v1"
std_lib_installed_dir = "C:/msys64/clang64/share/libc++/v1"
extra_args = [
'-Werror', '-Wall', '-Wpedantic', '-pedantic', '-Wextra', '-Wconversion', '-Wfloat-conversion', '-Wsign-conversion',
'-Wshadow', '-Wnon-virtual-dtor', '-Wold-style-cast', '-Wcast-align', '-Wunused', '-Woverloaded-virtual',
Expand Down
1 change: 1 addition & 0 deletions zork_config/zork_windows_msvc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ interfaces = [
{ file = 'math/numbers/naturals.cppm', partition = { module = 'math', partition_name = 'numbers.naturals' } },
{ file = 'math/numbers/integers.cppm', partition = { module = 'math', partition_name = 'numbers.integers' } },
{ file = 'math/numbers/rationals.cppm', partition = { module = 'math', partition_name = 'numbers.rationals' } },
{ file = 'math/numbers/reals.cppm', partition = { module = 'math', partition_name = 'numbers.reals' } },
{ file = 'math/numbers/detail.cpp', partition = { module = 'math', partition_name = 'numbers.detail', is_internal_partition = true } },
{ file = 'math/numbers/numbers.cppm', partition = { module = 'math', partition_name = 'numbers' } },
# Root
Expand Down

0 comments on commit 9d5ecc6

Please sign in to comment.