| 1 | #include <iostream> |
| 2 | #include <string> |
| 3 | #include <boost/optional.hpp> |
| 4 | #include <nix.hpp> |
| 5 | |
| 6 | |
| 7 | int compare(const std::string &a, const std::string &b) { |
| 8 | if (a != b) { |
| 9 | std::cout << "Expected '" << a << "' got '" << b << "'" << std::endl; |
| 10 | return 1; |
| 11 | } |
| 12 | return 0; |
| 13 | } |
| 14 | |
| 15 | int compare(const std::vector<std::string> &a, const std::vector<std::string> &b) { |
| 16 | if (a != b) { |
| 17 | std::cout << "Mismatch in string vectors" << std::endl; |
| 18 | std::cout << "Expected {"; |
| 19 | for (const auto& i : a) { |
| 20 | std::cout << i << " "; |
| 21 | } |
| 22 | std::cout << "} got {"; |
| 23 | for (const auto& i : b) { |
| 24 | std::cout << i << " "; |
| 25 | |
| 26 | } |
| 27 | std::cout << "}" << std::endl; |
| 28 | return 1; |
| 29 | } |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | template <typename T> |
| 34 | int compare(const T a, const T b) { |
| 35 | if (a != b) { |
| 36 | std::cout << "Expected '" << a << "' got '" << b << "'" << std::endl; |
| 37 | return 1; |
| 38 | } |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | template <typename T> |
| 43 | int compare(const std::string &a, boost::optional<T> b) { |
| 44 | return compare(a, nix::util::deRef(b)); |
| 45 | } |
| 46 | |
| 47 | template <typename T> |
| 48 | int compare(const std::vector<T> &a, const std::vector<T> &b, std::string name = "") { |
| 49 | if (a != b) { |
| 50 | std::cout << "Mismatch in data vectors"; |
| 51 | if (name != "") { |
| 52 | std::cout << " (name: " << name << ")"; |
| 53 | } |
| 54 | std::cout << std::endl; |
| 55 | std::cout << "Expected {"; |
| 56 | for (const auto& i : a) { |
| 57 | std::cout << i << " "; |
| 58 | } |
| 59 | std::cout << "} got {"; |
| 60 | for (const auto& i : b) { |
| 61 | std::cout << i << " "; |
| 62 | |
| 63 | } |
| 64 | std::cout << "}" << std::endl; |
| 65 | return 1; |
| 66 | } |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int compare(const nix::NDSize &a, const nix::NDSize &b, std::string name = "") { |
| 71 | if (a != b) { |
| 72 | std::cout << "Mismatch in data extents"; |
| 73 | if (name != "") { |
| 74 | std::cout << " (name: " << name << ")"; |
| 75 | } |
| 76 | std::cout << std::endl; |
| 77 | std::cout << "Exp " << a << "Got " << b << std::endl; |
| 78 | return 1; |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | int testassert(bool cond, std::string message = "") { |
| 84 | if (!cond && message != "") { |
| 85 | std::cout << message << std::endl; |
| 86 | } |
| 87 | return !cond; |
| 88 | } |