Commit 894a0fca authored by Paul's avatar Paul
Browse files

Fix formatting

parent d12838be
...@@ -14,13 +14,10 @@ struct simple_operation ...@@ -14,13 +14,10 @@ struct simple_operation
void operation_copy_test() void operation_copy_test()
{ {
simple_operation s{}; simple_operation s{};
rtg::operation op1 = s; // NOLINT rtg::operation op1 = s; // NOLINT
rtg::operation op2 = op1; // NOLINT rtg::operation op2 = op1; // NOLINT
EXPECT(s.name() == op1.name()); EXPECT(s.name() == op1.name());
EXPECT(op2.name() == op1.name()); EXPECT(op2.name() == op1.name());
} }
int main() int main() { operation_copy_test(); }
{
operation_copy_test();
}
...@@ -54,16 +54,18 @@ void test_shape4() ...@@ -54,16 +54,18 @@ void test_shape4()
void test_shape4_nonpacked() void test_shape4_nonpacked()
{ {
std::vector<std::size_t> lens = {100, 32, 8, 8}; std::vector<std::size_t> lens = {100, 32, 8, 8};
std::array<std::size_t, 4> offsets = {{5, 10, 0, 6}}; std::array<std::size_t, 4> offsets = {{5, 10, 0, 6}};
std::array<std::size_t, 4> adj_lens = {{0, 0, 0, 0}}; std::array<std::size_t, 4> adj_lens = {{0, 0, 0, 0}};
std::transform( std::transform(
lens.begin(), lens.end(), offsets.begin(), adj_lens.begin(), std::plus<size_t>()); lens.begin(), lens.end(), offsets.begin(), adj_lens.begin(), std::plus<size_t>());
// adj_lens should be: { 105, 42, 8, 14 } // adj_lens should be: { 105, 42, 8, 14 }
std::vector<std::size_t> strides(4); std::vector<std::size_t> strides(4);
strides.back() = 1; strides.back() = 1;
std::partial_sum( std::partial_sum(adj_lens.rbegin(),
adj_lens.rbegin(), adj_lens.rend() - 1, strides.rbegin() + 1, std::multiplies<std::size_t>()); adj_lens.rend() - 1,
strides.rbegin() + 1,
std::multiplies<std::size_t>());
rtg::shape s{rtg::shape::float_type, lens, strides}; rtg::shape s{rtg::shape::float_type, lens, strides};
EXPECT(!s.packed()); EXPECT(!s.packed());
...@@ -88,7 +90,6 @@ void test_shape4_nonpacked() ...@@ -88,7 +90,6 @@ void test_shape4_nonpacked()
// EXPECT(s.index({0, 1, 0, 0}) == s.index(8 * 8)); // EXPECT(s.index({0, 1, 0, 0}) == s.index(8 * 8));
// EXPECT(s.index({1, 0, 0, 0}) == s.index(8 * 8 * 32)); // EXPECT(s.index({1, 0, 0, 0}) == s.index(8 * 8 * 32));
// EXPECT(s.index(s.elements() - 1) == 469273); // EXPECT(s.index(s.elements() - 1) == 469273);
} }
int main() int main()
......
...@@ -9,26 +9,25 @@ ...@@ -9,26 +9,25 @@
namespace test { namespace test {
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define TEST_FOREACH_OPERATOR(m) \ #define TEST_FOREACH_OPERATOR(m) \
m(==, equal) \ m(==, equal) m(!=, not_equal) m(<=, less_than_equal) m(>=, greater_than_equal) m(<, less_than) \
m(!=, not_equal) \ m(>, greater_than)
m(<=, less_than_equal) \
m(>=, greater_than_equal) \
m(<, less_than) \
m(>, greater_than)
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define TEST_EACH_OPERATOR_OBJECT(op, name) \ #define TEST_EACH_OPERATOR_OBJECT(op, name) \
struct name \ struct name \
{ \ { \
static std::string as_string() { return #op; } \ static std::string as_string() { return #op; } \
template<class T, class U> \ template <class T, class U> \
static decltype(auto) call(T&& x, U&& y) { return x op y; } \ static decltype(auto) call(T&& x, U&& y) \
}; { \
return x op y; \
} \
};
TEST_FOREACH_OPERATOR(TEST_EACH_OPERATOR_OBJECT) TEST_FOREACH_OPERATOR(TEST_EACH_OPERATOR_OBJECT)
template<class T, class U, class Operator> template <class T, class U, class Operator>
struct expression struct expression
{ {
T lhs; T lhs;
...@@ -43,28 +42,27 @@ struct expression ...@@ -43,28 +42,27 @@ struct expression
decltype(auto) value() const { return Operator::call(lhs, rhs); }; decltype(auto) value() const { return Operator::call(lhs, rhs); };
}; };
template<class T, class U, class Operator> template <class T, class U, class Operator>
expression<typename std::decay<T>::type, typename std::decay<U>::type, Operator> expression<typename std::decay<T>::type, typename std::decay<U>::type, Operator>
make_expression(T&& rhs, U&& lhs, Operator) make_expression(T&& rhs, U&& lhs, Operator)
{ {
return { std::forward<T>(rhs), std::forward<U>(lhs) }; return {std::forward<T>(rhs), std::forward<U>(lhs)};
} }
template<class T> template <class T>
struct lhs_expression; struct lhs_expression;
template<class T> template <class T>
lhs_expression<typename std::decay<T>::type> make_lhs_expression(T&& lhs) lhs_expression<typename std::decay<T>::type> make_lhs_expression(T&& lhs)
{ {
return lhs_expression<typename std::decay<T>::type>{ std::forward<T>(lhs) }; return lhs_expression<typename std::decay<T>::type>{std::forward<T>(lhs)};
} }
template<class T> template <class T>
struct lhs_expression struct lhs_expression
{ {
T lhs; T lhs;
explicit lhs_expression(T e) : lhs(e) explicit lhs_expression(T e) : lhs(e) {}
{}
friend std::ostream& operator<<(std::ostream& s, const lhs_expression& self) friend std::ostream& operator<<(std::ostream& s, const lhs_expression& self)
{ {
...@@ -72,41 +70,47 @@ struct lhs_expression ...@@ -72,41 +70,47 @@ struct lhs_expression
return s; return s;
} }
T value() const T value() const { return lhs; }
{
return lhs;
}
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define TEST_LHS_OPERATOR(op, name) \ #define TEST_LHS_OPERATOR(op, name) \
template<class U> \ template <class U> \
auto operator op(const U& rhs) const { return make_expression(lhs, rhs, name{}); } // NOLINT auto operator op(const U& rhs) const \
{ \
TEST_FOREACH_OPERATOR(TEST_LHS_OPERATOR) return make_expression(lhs, rhs, name{}); \
} // NOLINT
TEST_FOREACH_OPERATOR(TEST_LHS_OPERATOR)
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define TEST_LHS_REOPERATOR(op) \ #define TEST_LHS_REOPERATOR(op) \
template<class U> auto operator op(const U& rhs) const { return make_lhs_expression(lhs op rhs); } template <class U> \
TEST_LHS_REOPERATOR(+) auto operator op(const U& rhs) const \
TEST_LHS_REOPERATOR(-) { \
TEST_LHS_REOPERATOR(*) return make_lhs_expression(lhs op rhs); \
TEST_LHS_REOPERATOR(/) }
TEST_LHS_REOPERATOR(%) TEST_LHS_REOPERATOR(+)
TEST_LHS_REOPERATOR(&) TEST_LHS_REOPERATOR(-)
TEST_LHS_REOPERATOR(|) TEST_LHS_REOPERATOR(*)
TEST_LHS_REOPERATOR(&&) TEST_LHS_REOPERATOR(/)
TEST_LHS_REOPERATOR(||) TEST_LHS_REOPERATOR(%)
TEST_LHS_REOPERATOR(&)
TEST_LHS_REOPERATOR(|)
TEST_LHS_REOPERATOR(&&)
TEST_LHS_REOPERATOR(||)
}; };
struct capture struct capture
{ {
template<class T> template <class T>
auto operator->* (const T& x) { return make_lhs_expression(x); } auto operator->*(const T& x)
{
return make_lhs_expression(x);
}
}; };
template<class T, class F> template <class T, class F>
void failed(T x, const char* msg, const char* file, int line, F f) void failed(T x, const char* msg, const char* file, int line, F f)
{ {
if (!x.value()) if(!x.value())
{ {
std::cout << file << ":" << line << ":" << std::endl; std::cout << file << ":" << line << ":" << std::endl;
std::cout << " FAILED: " << msg << " " << x << std::endl; std::cout << " FAILED: " << msg << " " << x << std::endl;
...@@ -152,9 +156,11 @@ void run_test() ...@@ -152,9 +156,11 @@ void run_test()
} // namespace test } // namespace test
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define CHECK(...) test::failed(test::capture{} ->* __VA_ARGS__, #__VA_ARGS__, __FILE__, __LINE__, []{}) #define CHECK(...) \
test::failed(test::capture{}->*__VA_ARGS__, #__VA_ARGS__, __FILE__, __LINE__, [] {})
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define EXPECT(...) test::failed(test::capture{} ->* __VA_ARGS__, #__VA_ARGS__, __FILE__, __LINE__, &std::abort) #define EXPECT(...) \
test::failed(test::capture{}->*__VA_ARGS__, #__VA_ARGS__, __FILE__, __LINE__, &std::abort)
// NOLINTNEXTLINE // NOLINTNEXTLINE
#define STATUS(...) EXPECT((__VA_ARGS__) == 0) #define STATUS(...) EXPECT((__VA_ARGS__) == 0)
......
Markdown is supported
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