• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
2 
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <boost/qvm/mat_operations.hpp>
7 #include <boost/qvm/mat_traits_array.hpp>
8 #include <boost/qvm/mat.hpp>
9 #include "test_qvm_matrix.hpp"
10 #include "gold.hpp"
11 
12 namespace
13     {
14     template <int Rows,int Cols>
15     void
test()16     test()
17         {
18         using namespace boost::qvm::sfinae;
19         test_qvm::matrix<M1,Rows,Cols> const x(42,1);
20         for( int i=0; i!=Rows; ++i )
21             for( int j=0; j!=Cols; ++j )
22                 {
23                     {
24                     test_qvm::matrix<M1,Rows,Cols> y(x);
25                     BOOST_QVM_TEST_EQ(x,y);
26                     y.a[i][j]=0;
27                     BOOST_QVM_TEST_NEQ(x,y);
28                     }
29                     {
30                     test_qvm::matrix<M2,Rows,Cols> y; assign(y,x);
31                     BOOST_QVM_TEST_EQ(x,y);
32                     y.a[i][j]=0;
33                     BOOST_QVM_TEST_NEQ(x,y);
34                     }
35                 }
36         }
37 
38     template <class T>
39     struct test_scalar
40     {
41         T value_;
test_scalar__anon94bc3f0e0111::test_scalar42         test_scalar( T value ): value_(value) {}
43     }; //No operator==
44 
45     struct
46     equal_to
47     {
48         template <class T,class U>
49         bool
operator ()__anon94bc3f0e0111::equal_to50         operator()( T const & a, U const & b )
51         {
52             return a.value_==b.value_;
53         }
54     };
55 
56     template <class A, class B>
57     void
test2()58     test2()
59         {
60         typedef test_scalar<A> scalar_a;
61         typedef test_scalar<B> scalar_b;
62         typedef boost::qvm::mat<scalar_a, 3, 3> mat_a;
63         typedef boost::qvm::mat<scalar_b, 3, 3> mat_b;
64         mat_a const a = { { {42, 94, 96}, {72, 95, 81}, {12, 84, 33} } };
65         mat_b const b = { { {42, 94, 96}, {72, 95, 81}, {12, 84, 33} } };
66         mat_a const c = { { {21, 47, 48}, {36, 47, 65}, {79, 27, 41} } };
67         mat_b const d = { { {21, 47, 48}, {36, 47, 65}, {79, 27, 41} } };
68         BOOST_TEST(cmp(a,a,equal_to()));
69         BOOST_TEST(cmp(a,b,equal_to()));
70         BOOST_TEST(cmp(b,a,equal_to()));
71         BOOST_TEST(cmp(b,b,equal_to()));
72         BOOST_TEST(cmp(c,c,equal_to()));
73         BOOST_TEST(cmp(c,d,equal_to()));
74         BOOST_TEST(cmp(d,c,equal_to()));
75         BOOST_TEST(cmp(d,d,equal_to()));
76         BOOST_TEST(!cmp(a,c,equal_to()));
77         BOOST_TEST(!cmp(c,a,equal_to()));
78         BOOST_TEST(!cmp(a,d,equal_to()));
79         BOOST_TEST(!cmp(d,a,equal_to()));
80         BOOST_TEST(!cmp(b,c,equal_to()));
81         BOOST_TEST(!cmp(c,b,equal_to()));
82         BOOST_TEST(!cmp(b,d,equal_to()));
83         BOOST_TEST(!cmp(d,b,equal_to()));
84         }
85     }
86 
87 int
main()88 main()
89     {
90     test<1,2>();
91     test<2,1>();
92     test<2,2>();
93     test<1,3>();
94     test<3,1>();
95     test<3,3>();
96     test<1,4>();
97     test<4,1>();
98     test<4,4>();
99     test<1,5>();
100     test<5,1>();
101     test<5,5>();
102     test2<int, int>();
103     test2<int, double>();
104     test2<double, int>();
105     test2<double, double>();
106     return boost::report_errors();
107     }
108