Commit 3eb33bd7 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

remove HPP_POSTCONDITION, fix #12

parent 692575ff
Pipeline #1448 passed with stage
in 8 minutes and 47 seconds
......@@ -31,7 +31,6 @@ robotpkg-hpp-util-16.04-release:
robotpkg-hpp-util-18.04-release:
<<: *robotpkg-hpp-util
image: eur0c.laas.fr:5000/humanoid-path-planner/hpp-util/hpp-util:18.04
allow_failure: true
doc-coverage:
<<: *robotpkg-hpp-util
......@@ -51,4 +50,3 @@ doc-coverage:
paths:
- doxygen-html/
- coverage/
......@@ -46,32 +46,4 @@ namespace hpp
/// \brief Define macro for precondition checking.
# define HPP_PRECONDITION(CONDITION) HPP_ASSERT (CONDITION)
/// \brief Define macro for postcondition checking.
///
/// This macro allows an assertion to be done whenever a
/// scope is exited.
///
/// This macro takes two arguments: the condition which should
/// be evaluated and a list of captured variables.
/// All variables used in the condition must be in this list.
///
/// They can either be copied or taken by reference:
/// HPP_POSTCONDITION (a == 3, (a))
/// ...checks that a is equal to three and copy the variable a
/// when HPP_POSTCONDITION is called.
///
/// HPP_POSTCONDITION (a == 3, (&a))
/// ...takes a by reference and evaluated its final value (when
/// the scope is exited).
///
/// See Boost.ScopeExit for more details.
# define HPP_POSTCONDITION(CONDITION, CAPTURED_VARIABLES) \
BOOST_SCOPE_EXIT(CAPTURED_VARIABLES) \
{ \
HPP_ASSERT (CONDITION); \
} BOOST_SCOPE_EXIT_END \
struct _e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
#endif //! HPP_UTIL_ASSERTION_HH
......@@ -39,14 +39,15 @@ int my_plus_function (int a, int b)
HPP_PRECONDITION (a >= 0);
HPP_PRECONDITION (b >= 0);
int res = 0;
// This algorithm should compute a + b.
HPP_POSTCONDITION (res == a + b, (&res) (a) (b));
int res = 0, expected = a + b;
res = b;
while (a > 0)
--a, ++res;
// This algorithm should have computed a + b.
HPP_ASSERT (res == expected);
return res;
}
......@@ -56,12 +57,13 @@ int my_broken_plus_function (int a, int b)
HPP_PRECONDITION (a >= 0);
HPP_PRECONDITION (b >= 0);
int res = 0;
// This algorithm should compute a + b.
HPP_POSTCONDITION (res == a + b, (&res) (a) (b));
int res = 0, expected = a + b;
res = b; // This is wrong.
// This algorithm should have computed a + b.
HPP_ASSERT (res == expected);
return res;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment