cellrank.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - How args are passed when cell rank > 0.
  3. // (c) Daniel Llorens - 2023
  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 "ra/test.hh"
  9. #ifdef __STDCPP_FLOAT128_T__
  10. #include <stdfloat>
  11. #endif
  12. using std::cout, std::endl, std::flush, ra::TestRecorder;
  13. int main()
  14. {
  15. TestRecorder tr(std::cout);
  16. tr.section("positive cell rank iterators pass reference to sliding view");
  17. {
  18. ra::Big<int, 3> A({4, 2, 3}, 0);
  19. ra::Big<int, 2> B({4, 2}, 1);
  20. ra::Big<int, 1> C({4}, 10);
  21. for_each([&](auto & a, auto & b, auto & c)
  22. {
  23. a = b + c;
  24. }, iter<2>(A), iter<1>(B), C);
  25. tr.test_eq(11, A);
  26. for_each([&](auto & a, auto & b, auto & c)
  27. {
  28. a += b + c;
  29. }, iter<2>(A), iter<1>(B), C);
  30. tr.test_eq(22, A);
  31. }
  32. {
  33. ra::Big<int, 3> A({4, 2, 3}, 0);
  34. ra::Big<int, 2> B({4, 2}, 1);
  35. ra::Big<int, 1> C({4}, 10);
  36. for_each([&](auto && a, auto && b, auto & c)
  37. {
  38. a += b + c;
  39. }, iter<2>(A), iter<1>(B), C);
  40. tr.test_eq(11, A);
  41. }
  42. tr.section("using View::operator= on sliding view");
  43. {
  44. ra::Big<int, 2> A({3, 2}, 0);
  45. for_each([&](auto && a)
  46. {
  47. a = { 3, 7 };
  48. }, iter<1>(A));
  49. ra::Big<int, 2> ref = {{3, 7}, {3, 7}, {3, 7}};
  50. tr.test_eq(ref, A);
  51. }
  52. return tr.summary();
  53. }