early.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Tests for early().
  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. using std::cout, std::endl, ra::TestRecorder;
  10. int main()
  11. {
  12. TestRecorder tr(std::cout);
  13. tr.section("early with rank 0");
  14. {
  15. {
  16. ra::Big<int, 0> a = 99;
  17. tr.test(ra::any(a==99));
  18. tr.test(ra::every(a==99));
  19. }
  20. {
  21. ra::Big<int> a = 99;
  22. tr.test_eq(0, a.rank());
  23. tr.test(ra::any(a==99));
  24. tr.test(ra::every(a==99));
  25. }
  26. }
  27. tr.section("early with static lens");
  28. {
  29. ra::Small<int, 2, 3> a = ra::_0*2 + ra::_1*10;
  30. tr.test(!ra::any(odd(a)));
  31. tr.test(ra::every(!odd(a)));
  32. }
  33. tr.section("early with static lens. Regression with ununrolled expr");
  34. {
  35. ra::Small<int, 2, 3> a = { { 1, 1, 1 }, { 1, 0, 1} };
  36. tr.test(!every(1==a));
  37. tr.test(any(0==a));
  38. auto b = ra::transpose<1, 0>(a);
  39. tr.test(!every(1==b));
  40. tr.test(any(0==b));
  41. }
  42. tr.section("early with static lens is constexpr");
  43. {
  44. constexpr ra::Small<int, 2, 3> a = ra::_0*2 + ra::_1*10;
  45. constexpr bool not_any = !ra::any(odd(a));
  46. constexpr bool every_not = ra::every(!odd(a));
  47. tr.test(not_any);
  48. tr.test(every_not);
  49. }
  50. tr.section("early with static rank");
  51. {
  52. ra::Big<int, 2> a({2, 3}, ra::_0*2 + ra::_1*10);
  53. tr.test(!ra::any(odd(a)));
  54. tr.test(ra::every(!odd(a)));
  55. }
  56. tr.section("early with var rank");
  57. {
  58. ra::Big<int> a = ra::iota(9)*2;
  59. tr.test(!ra::any(odd(a)));
  60. tr.test(ra::every(!odd(a)));
  61. }
  62. return tr.summary();
  63. }