ra-4.cc 893 B

12345678910111213141516171819202122232425262728293031323334
  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. #include "ra/complex.hh"
  12. using std::cout, std::endl, std::flush, ra::TestRecorder;
  13. using complex = std::complex<double>;
  14. using ra::sqrm;
  15. template <class AA>
  16. double sqrm_ai(AA && a)
  17. {
  18. double c(0.);
  19. ply(ra::expr([&c](complex const a) { c += sqrm(a); }, a));
  20. return c;
  21. }
  22. int main()
  23. {
  24. TestRecorder tr;
  25. ra::Unique<complex, 1> a({3}, {1, 2, 3});
  26. tr.test_eq(14, sqrm_ai(ra::expr([](complex a) { return a; }, a.iter())));
  27. return tr.summary();
  28. }