test-ra-9.C 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // (c) Daniel Llorens - 2017
  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-9.C
  7. /// @brief Regressions in array-in-ra::scalar
  8. #include <iostream>
  9. #include <iterator>
  10. #include "ra/mpdebug.H"
  11. #include "ra/complex.H"
  12. #include "ra/format.H"
  13. #include "ra/test.H"
  14. #include "ra/big.H"
  15. #include "ra/operators.H"
  16. #include "ra/io.H"
  17. using std::cout; using std::endl; using std::flush; using std::tuple;
  18. using int2 = ra::Small<int, 2>;
  19. using int1 = ra::Small<int, 1>;
  20. int main()
  21. {
  22. TestRecorder tr(std::cout);
  23. tr.section("regression [ra21]");
  24. {
  25. ra::Big<int2, 1> b { {1, 10}, {2, 20}, {3, 30} };
  26. b += ra::scalar(int2 { 1, 0 });
  27. tr.test_eq(ra::Big<int2, 1> { {2, 10}, {3, 20}, {4, 30} }, b);
  28. ra::Big<int2, 1> c { {1, 0}, {2, 0}, {3, 0} };
  29. }
  30. tr.section("regression [ra22]");
  31. {
  32. ra::Big<int2, 1> b { {0, 10}, {0, 20}, {0, 30} };
  33. ra::Big<int2, 1> c { {1, 0}, {2, 0}, {3, 0} };
  34. tr.test_eq(ra::scalar("3\n2 0 3 0 4 0"), ra::scalar(format(c + ra::scalar(int2 { 1, 0 })))); // FIXME try both -O3 -O0
  35. b = c + ra::scalar(int2 { 1, 0 });
  36. tr.test_eq(ra::Big<int2, 1> { {2, 0}, {3, 0}, {4, 0} }, b);
  37. }
  38. tr.section("regression [ra24]");
  39. {
  40. {
  41. tr.test_eq(int1{91}, ra::scalar(int1{88}) + ra::scalar(int1{3}));
  42. }
  43. {
  44. auto a = int1{88};
  45. auto b = int1{3};
  46. tr.test_eq(int1{91}, a+b);
  47. }
  48. {
  49. auto a = ra::scalar(int1{88});
  50. auto b = ra::scalar(int1{3});
  51. tr.test_eq(int1{91}, a+b);
  52. }
  53. {
  54. auto a = ra::scalar(int1{88});
  55. auto b = ra::scalar(int1{3});
  56. tr.test_eq(int1{91}, ra::scalar(a)+ra::scalar(b));
  57. }
  58. }
  59. tr.section("regression [ra25]");
  60. {
  61. ra::Big<int1, 1> c { {7}, {8} };
  62. tr.test_eq(ra::scalar("2\n8 9"), ra::scalar(format(c+1)));
  63. }
  64. tr.section("regression [ra26]"); // This uses Scalar.at().
  65. {
  66. ra::Big<int1, 1> c { {7}, {8} };
  67. tr.test_eq(ra::scalar("2\n8 9"), ra::scalar(format(c+ra::scalar(int1{1}))));
  68. }
  69. tr.section("regression [ra23]");
  70. {
  71. // This is just to show that it works the same way with 'scalar' = int as with 'scalar' = int2.
  72. int x = 2;
  73. ra::Big<int, 1> c { 3, 4 };
  74. ra::scalar(x) += c + ra::scalar(99);
  75. tr.test_eq(2+3+99+4+99, x); // FIXME
  76. }
  77. {
  78. int2 x {2, 0};
  79. ra::Big<int2, 1> c { {1, 3}, {2, 4} };
  80. ra::scalar(x) += c + ra::scalar(int2 { 1, 99 });
  81. tr.test_eq(int2{2, 0}+int2{1, 3}+int2{1, 99}+int2{2, 4}+int2{1, 99}, x);
  82. }
  83. return tr.summary();
  84. }