Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <set>
- #include <string>
- #include <utility>
- #include <vector>
- #include <map>
- #include <cmath>
- #include <cassert>
- using namespace std;
- /*
- Подставьте сюда вашу реализацию макросов
- ASSERT, ASSERT_EQUAL, ASSERT_EQUAL_HINT, ASSERT_HINT и RUN_TEST
- */
- template <typename T, typename U>
- ostream& operator<<(ostream& out, const pair<T, U>& container)
- {
- return out << container.first << ": " << container.second;
- }
- template <typename T>
- void Print(ostream& out, const T& container)
- {
- bool is_first = true;
- for (const auto& element : container)
- {
- if (is_first)
- {
- out << element;
- is_first = false;
- }
- else
- {
- out << ", "s << element;
- }
- }
- }
- template <typename T>
- ostream& operator<<(ostream& out, const vector<T>& container)
- {
- out << "["s;
- Print(out, container);
- out << "]"s;
- return out;
- }
- template <typename T>
- ostream& operator<<(ostream& out, const set<T>& container)
- {
- out << "{"s;
- Print(out, container);
- out << "}"s;
- return out;
- }
- template <typename T, typename U>
- ostream& operator<<(ostream& out, const map<T, U>& container)
- {
- out << "{"s;
- Print(out, container);
- out << "}"s;
- return out;
- }
- template <typename T, typename U>
- void AssertEqualImpl(const T& t, const U& u, const string& t_str, const string& u_str, const string& file,
- const string& func, unsigned line, const string& hint)
- {
- if (t != u)
- {
- cerr << boolalpha;
- cerr << file << "("s << line << "): "s << func << ": "s;
- cerr << "ASSERT_EQUAL("s << t_str << ", "s << u_str << ") failed: "s;
- cerr << t << " != "s << u << "."s;
- if (!hint.empty())
- {
- cerr << " Hint: "s << hint;
- }
- cerr << endl;
- abort();
- }
- }
- void AssertImpl(bool value, const string& expr_str, const string& file, const string& func, unsigned line,
- const string& hint)
- {
- if (!value)
- {
- cerr << file << "("s << line << "): "s << func << ": "s;
- cerr << "ASSERT("s << expr_str << ") failed."s;
- if (!hint.empty())
- {
- cerr << " Hint: "s << hint;
- }
- cerr << endl;
- abort();
- }
- }
- template <typename T>
- void RunTestImpl(T func, const string& func_str)
- {
- func();
- cerr << func_str << " OK" << endl;
- }
- #define ASSERT(expr) AssertImpl(!!(expr), #expr, __FILE__, __FUNCTION__, __LINE__, ""s)
- #define ASSERT_EQUAL(a, b) AssertEqualImpl((a), (b), #a, #b, __FILE__, __FUNCTION__, __LINE__, ""s)
- #define ASSERT_EQUAL_HINT(a, b, hint) AssertEqualImpl((a), (b), #a, #b, __FILE__, __FUNCTION__, __LINE__, (hint))
- #define ASSERT_HINT(expr, hint) AssertImpl(!!(expr), #expr, __FILE__, __FUNCTION__, __LINE__, (hint))
- #define RUN_TEST(func) RunTestImpl((func), #func)
- // -------- Начало модульных тестов ----------
- void Test1()
- {
- ///
- }
- void Test2()
- {
- ///
- }
- // Функция TestSearchServer является точкой входа для запуска тестов
- void TestSearchServer()
- {
- RUN_TEST(Test1);
- RUN_TEST(Test2);
- }
- //--------- Окончание модульных тестов -----------
- int main()
- {
- TestSearchServer();
- ///
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement