diag_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/vec_operations.hpp>
  5. #include <boost/qvm/vec.hpp>
  6. #include <boost/qvm/map_mat_vec.hpp>
  7. #include "test_qvm_matrix.hpp"
  8. #include "test_qvm_vector.hpp"
  9. #include "gold.hpp"
  10. namespace
  11. {
  12. template <int A,int B,bool LessThan=(A<B)>
  13. struct
  14. get_min
  15. {
  16. static int const value=B;
  17. };
  18. template <int A,int B>
  19. struct
  20. get_min<A,B,true>
  21. {
  22. static int const value=A;
  23. };
  24. template <int Rows,int Cols>
  25. void
  26. test()
  27. {
  28. using namespace boost::qvm;
  29. int const D=get_min<Rows,Cols>::value;
  30. test_qvm::matrix<M1,Rows,Cols> x(42,1);
  31. test_qvm::vector<V1,D> y=diag(x);
  32. for( int i=0; i!=D; ++i )
  33. y.b[i]=x.a[i][i];
  34. BOOST_QVM_TEST_EQ(y.a,y.b);
  35. diag(x) *= 2;
  36. for( int i=0; i!=D; ++i )
  37. x.b[i][i] *= 2;
  38. BOOST_QVM_TEST_EQ(x.a,x.b);
  39. diag(x) + diag(x);
  40. -diag(x);
  41. }
  42. }
  43. int
  44. main()
  45. {
  46. test<1,2>();
  47. test<1,3>();
  48. test<1,4>();
  49. test<1,5>();
  50. test<2,1>();
  51. test<3,1>();
  52. test<4,1>();
  53. test<5,1>();
  54. test<2,2>();
  55. test<3,3>();
  56. test<4,4>();
  57. test<5,5>();
  58. return boost::report_errors();
  59. }