Last active
August 29, 2015 14:11
-
-
Save yaraki/ef6b03190cc2ffe6ffbf to your computer and use it in GitHub Desktop.
Minimal testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang++ -o minitest minitest.cpp -std=c++1y -stdlib=libc++ | |
#include <iostream> | |
#define TEST_PREDICATE(expr, oper) \ | |
do { \ | |
auto expr__ = (expr); \ | |
if (!(expr__ oper)) { \ | |
std::cout << __FILE__ << ":" << __LINE__ << " " \ | |
<< "FAILED " << #expr << " " << #oper \ | |
<< " (actual: " << expr__ << ")" << std::endl; \ | |
} \ | |
} while (0) | |
#define TEST_TRUE(expr) \ | |
do { \ | |
if (!(expr)) { \ | |
std::cout << __FILE__ << ":" << __LINE__ << " " \ | |
<< "FAILED " #expr << std::endl; \ | |
} \ | |
} while (0) | |
#define TEST_MACRO(_1, _2, NAME, ...) NAME | |
#define TEST(...) TEST_MACRO(__VA_ARGS__, TEST_PREDICATE, TEST_TRUE)(__VA_ARGS__) | |
// Test target sample | |
template <typename item_t> | |
class rectangle | |
{ | |
private: | |
item_t width_; | |
item_t height_; | |
public: | |
rectangle(item_t width, item_t height) | |
: width_(width), height_(height) | |
{ | |
} | |
item_t area() const | |
{ | |
return width_ + height_; // TODO: Fix bug here | |
} | |
bool is_square() const | |
{ | |
return width_ == height_; | |
} | |
}; | |
// Test sample | |
int main() | |
{ | |
rectangle<int> r(2, 3); | |
TEST(r.area(), == 6); | |
TEST(r.area(), >= 6); | |
TEST(r.area(), != 5); | |
TEST(r.is_square()); // TODO: Fix bug here | |
return 0; | |
} |
Author
yaraki
commented
Dec 16, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment