ra-4.cc 868 B

123456789101112131415161718192021222324252627282930313233
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Regresion tests (1).
  3. // (c) Daniel Llorens - 2014
  4. // This library is free software; you can redistribute it and/or modify it under
  5. // the terms of the GNU Lesser General Public License as published by the Free
  6. // Software Foundation; either version 3 of the License, or (at your option) any
  7. // later version.
  8. #include <iostream>
  9. #include <iterator>
  10. #include "ra/test.hh"
  11. using std::cout, std::endl, std::flush, ra::TestRecorder;
  12. using complex = std::complex<double>;
  13. using ra::sqrm;
  14. template <class AA>
  15. double sqrm_ai(AA && a)
  16. {
  17. double c(0.);
  18. ply(ra::expr([&c](complex const a) { c += sqrm(a); }, a));
  19. return c;
  20. }
  21. int main()
  22. {
  23. TestRecorder tr;
  24. ra::Unique<complex, 1> a({3}, {1, 2, 3});
  25. tr.test_eq(14, sqrm_ai(ra::expr([](complex a) { return a; }, a.iter())));
  26. return tr.summary();
  27. }