assert.h 709 B

12345678910111213141516171819202122
  1. #include <iostream>
  2. #define equals(x,y) assertEquals(x, y, __LINE__)
  3. template < typename X, typename Y >
  4. void OutputAssert(X expect, char const* compare, Y get, unsigned long const &line) {
  5. std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl;
  6. }
  7. template < typename X, typename Y >
  8. void assertEquals(X expect, Y get, unsigned long const &line) {
  9. if (expect == get)
  10. return;
  11. OutputAssert(expect, "==", get, line);
  12. }
  13. void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) {
  14. if (get < 0)
  15. OutputAssert(expect, "==", get, line);
  16. assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
  17. }