test-ra-4.C 919 B

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