zero_mat_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/mat_operations.hpp>
  5. #include <boost/qvm/mat.hpp>
  6. #include "test_qvm_matrix.hpp"
  7. namespace
  8. {
  9. template <class T,class U>
  10. struct same_type;
  11. template <class T>
  12. struct
  13. same_type<T,T>
  14. {
  15. };
  16. template <class T,class U>
  17. void
  18. check_deduction( T const &, U const & )
  19. {
  20. same_type<T,typename boost::qvm::deduce_mat<U>::type>();
  21. }
  22. template <int Rows,int Cols>
  23. void
  24. test()
  25. {
  26. using namespace boost::qvm;
  27. test_qvm::matrix<M1,Rows,Cols> m1=zero_mat<float,Rows,Cols>();
  28. for( int i=0; i!=Rows; ++i )
  29. for( int j=0; j!=Cols; ++j )
  30. BOOST_TEST(!m1.a[i][j]);
  31. test_qvm::matrix<M2,Rows,Cols> m2(42,1);
  32. set_zero(m2);
  33. for( int i=0; i!=Rows; ++i )
  34. for( int j=0; j!=Cols; ++j )
  35. BOOST_TEST(!m2.a[i][j]);
  36. check_deduction(mat<float,Rows,Cols>(),zero_mat<float,Rows,Cols>());
  37. check_deduction(mat<int,Rows,Cols>(),zero_mat<int,Rows,Cols>());
  38. }
  39. template <int Dim>
  40. void
  41. test()
  42. {
  43. using namespace boost::qvm;
  44. test_qvm::matrix<M1,Dim,Dim> m1=zero_mat<float,Dim>();
  45. for( int i=0; i!=Dim; ++i )
  46. for( int j=0; j!=Dim; ++j )
  47. BOOST_TEST(!m1.a[i][j]);
  48. }
  49. }
  50. int
  51. main()
  52. {
  53. test<1,2>();
  54. test<2,1>();
  55. test<2,2>();
  56. test<1,3>();
  57. test<3,1>();
  58. test<3,3>();
  59. test<1,4>();
  60. test<4,1>();
  61. test<4,4>();
  62. test<1,5>();
  63. test<5,1>();
  64. test<5,5>();
  65. test<2>();
  66. test<3>();
  67. test<4>();
  68. test<5>();
  69. return boost::report_errors();
  70. }