1 //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc.
2 //Copyright (c) 2019 agate-pris
3
4 //Distributed under the Boost Software License, Version 1.0. (See accompanying
5 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/qvm/vec.hpp>
8 #include <boost/qvm/vec_operations.hpp>
9 #include <boost/qvm/vec_traits_array.hpp>
10 #include "test_qvm_vector.hpp"
11 #include "gold.hpp"
12 #include <functional>
13
14 namespace
15 {
16 template <int Dim>
17 void
test()18 test()
19 {
20 using namespace boost::qvm::sfinae;
21 test_qvm::vector<V1,Dim> const x(42,1);
22 for( int i=0; i!=Dim; ++i )
23 {
24 {
25 test_qvm::vector<V1,Dim> y(x);
26 BOOST_TEST(cmp(x,y,std::equal_to<float>()));
27 y.a[i]=0;
28 BOOST_TEST(!cmp(x,y,std::equal_to<float>()));
29 }
30 }
31 }
32
33 template <class T>
34 struct test_scalar
35 {
36 T value_;
test_scalar__anon82e1ec1f0111::test_scalar37 test_scalar( T value ): value_(value) {}
38 }; //No operator==
39
40 struct
41 equal_to
42 {
43 template <class T,class U>
44 bool
operator ()__anon82e1ec1f0111::equal_to45 operator()( T const & a, U const & b )
46 {
47 return a.value_==b.value_;
48 }
49 };
50
51 template <class A, class B>
52 void
test2()53 test2()
54 {
55 typedef test_scalar<A> scalar_a;
56 typedef test_scalar<B> scalar_b;
57 typedef boost::qvm::vec<scalar_a, 5> vec_a;
58 typedef boost::qvm::vec<scalar_b, 5> vec_b;
59 vec_a const a = { { 42, 94, 96, 72, 95 } };
60 vec_b const b = { { 42, 94, 96, 72, 95 } };
61 vec_a const c = { { 21, 47, 48, 36, 47 } };
62 vec_b const d = { { 21, 47, 48, 36, 47 } };
63 BOOST_TEST(cmp(a,a,equal_to()));
64 BOOST_TEST(cmp(a,b,equal_to()));
65 BOOST_TEST(cmp(b,a,equal_to()));
66 BOOST_TEST(cmp(b,b,equal_to()));
67 BOOST_TEST(cmp(c,c,equal_to()));
68 BOOST_TEST(cmp(c,d,equal_to()));
69 BOOST_TEST(cmp(d,c,equal_to()));
70 BOOST_TEST(cmp(d,d,equal_to()));
71 BOOST_TEST(!cmp(a,c,equal_to()));
72 BOOST_TEST(!cmp(c,a,equal_to()));
73 BOOST_TEST(!cmp(a,d,equal_to()));
74 BOOST_TEST(!cmp(d,a,equal_to()));
75 BOOST_TEST(!cmp(b,c,equal_to()));
76 BOOST_TEST(!cmp(c,b,equal_to()));
77 BOOST_TEST(!cmp(b,d,equal_to()));
78 BOOST_TEST(!cmp(d,b,equal_to()));
79 }
80 }
81
82 int
main()83 main()
84 {
85 test<2>();
86 test<3>();
87 test<4>();
88 test<5>();
89 test2<int, int>();
90 test2<int, double>();
91 test2<double, int>();
92 test2<double, double>();
93 return boost::report_errors();
94 }
95