swap_rows_test.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/qvm/map_mat_mat.hpp>
  5. #include <boost/qvm/mat_operations.hpp>
  6. #include <boost/qvm/mat_traits_array.hpp>
  7. #include <boost/qvm/mat.hpp>
  8. #include "test_qvm.hpp"
  9. #include "test_qvm_matrix.hpp"
  10. #include "gold.hpp"
  11. namespace
  12. {
  13. template <int Rows,int Cols,int R1,int R2>
  14. void
  15. test()
  16. {
  17. using namespace boost::qvm;
  18. test_qvm::matrix<M1,Rows,Cols> x(42,1);
  19. float r1[Rows][Cols];
  20. for( int i=0; i!=Rows; ++i )
  21. for( int j=0; j!=Cols; ++j )
  22. r1[i][j]=x.a[i==R1?R2:i==R2?R1:i][j];
  23. float r2[Rows][Cols];
  24. assign(r2,swap_rows<R1,R2>(x));
  25. BOOST_QVM_TEST_EQ(r1,r2);
  26. swap_rows<R1,R2>(x) *= 2;
  27. for( int i=0; i!=Rows; ++i )
  28. for( int j=0; j!=Cols; ++j )
  29. r1[i][j]=x.a[i==R1?R2:i==R2?R1:i][j];
  30. assign(r2,swap_rows<R1,R2>(x));
  31. BOOST_QVM_TEST_EQ(r1,r2);
  32. swap_rows<R1,R2>(x)+swap_rows<R1,R2>(x);
  33. -swap_rows<R1,R2>(x);
  34. }
  35. }
  36. int
  37. main()
  38. {
  39. test<2,2,0,0>();
  40. test<2,2,0,1>();
  41. test<2,2,1,0>();
  42. test<2,2,1,1>();
  43. test<3,3,0,0>();
  44. test<3,3,0,1>();
  45. test<3,3,0,2>();
  46. test<3,3,1,0>();
  47. test<3,3,1,1>();
  48. test<3,3,1,2>();
  49. test<3,3,2,0>();
  50. test<3,3,2,1>();
  51. test<3,3,2,2>();
  52. test<4,4,0,0>();
  53. test<4,4,0,1>();
  54. test<4,4,0,2>();
  55. test<4,4,0,3>();
  56. test<4,4,1,0>();
  57. test<4,4,1,1>();
  58. test<4,4,1,2>();
  59. test<4,4,1,3>();
  60. test<4,4,2,0>();
  61. test<4,4,2,1>();
  62. test<4,4,2,2>();
  63. test<4,4,2,3>();
  64. test<4,4,3,0>();
  65. test<4,4,3,1>();
  66. test<4,4,3,2>();
  67. test<4,4,3,3>();
  68. test<5,5,0,0>();
  69. test<5,5,0,1>();
  70. test<5,5,0,2>();
  71. test<5,5,0,3>();
  72. test<5,5,0,4>();
  73. test<5,5,1,0>();
  74. test<5,5,1,1>();
  75. test<5,5,1,2>();
  76. test<5,5,1,3>();
  77. test<5,5,1,4>();
  78. test<5,5,2,0>();
  79. test<5,5,2,1>();
  80. test<5,5,2,2>();
  81. test<5,5,2,3>();
  82. test<5,5,2,4>();
  83. test<5,5,3,0>();
  84. test<5,5,3,1>();
  85. test<5,5,3,2>();
  86. test<5,5,3,3>();
  87. test<5,5,3,4>();
  88. test<5,5,4,0>();
  89. test<5,5,4,1>();
  90. test<5,5,4,2>();
  91. test<5,5,4,3>();
  92. test<5,5,4,4>();
  93. return boost::report_errors();
  94. }