1 // This file is part of Eigen, a lightweight C++ template library 2 // for linear algebra. 3 // 4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1 (at) gmail.com> 5 // 6 // This Source Code Form is subject to the terms of the Mozilla 7 // Public License v. 2.0. If a copy of the MPL was not distributed 8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 10 #define EIGEN_NO_STATIC_ASSERT 11 #include "main.h" 12 13 template<typename Scalar> void smallVectors() 14 { 15 typedef Matrix<Scalar, 1, 2> V2; 16 typedef Matrix<Scalar, 3, 1> V3; 17 typedef Matrix<Scalar, 1, 4> V4; 18 typedef Matrix<Scalar, Dynamic, 1> VX; 19 Scalar x1 = internal::random<Scalar>(), 20 x2 = internal::random<Scalar>(), 21 x3 = internal::random<Scalar>(), 22 x4 = internal::random<Scalar>(); 23 V2 v2(x1, x2); 24 V3 v3(x1, x2, x3); 25 V4 v4(x1, x2, x3, x4); 26 VERIFY_IS_APPROX(x1, v2.x()); 27 VERIFY_IS_APPROX(x1, v3.x()); 28 VERIFY_IS_APPROX(x1, v4.x()); 29 VERIFY_IS_APPROX(x2, v2.y()); 30 VERIFY_IS_APPROX(x2, v3.y()); 31 VERIFY_IS_APPROX(x2, v4.y()); 32 VERIFY_IS_APPROX(x3, v3.z()); 33 VERIFY_IS_APPROX(x3, v4.z()); 34 VERIFY_IS_APPROX(x4, v4.w()); 35 36 if (!NumTraits<Scalar>::IsInteger) 37 { 38 VERIFY_RAISES_ASSERT(V3(2, 1)) 39 VERIFY_RAISES_ASSERT(V3(3, 2)) 40 VERIFY_RAISES_ASSERT(V3(Scalar(3), 1)) 41 VERIFY_RAISES_ASSERT(V3(3, Scalar(1))) 42 VERIFY_RAISES_ASSERT(V3(Scalar(3), Scalar(1))) 43 VERIFY_RAISES_ASSERT(V3(Scalar(123), Scalar(123))) 44 45 VERIFY_RAISES_ASSERT(V4(1, 3)) 46 VERIFY_RAISES_ASSERT(V4(2, 4)) 47 VERIFY_RAISES_ASSERT(V4(1, Scalar(4))) 48 VERIFY_RAISES_ASSERT(V4(Scalar(1), 4)) 49 VERIFY_RAISES_ASSERT(V4(Scalar(1), Scalar(4))) 50 VERIFY_RAISES_ASSERT(V4(Scalar(123), Scalar(123))) 51 52 VERIFY_RAISES_ASSERT(VX(3, 2)) 53 VERIFY_RAISES_ASSERT(VX(Scalar(3), 1)) 54 VERIFY_RAISES_ASSERT(VX(3, Scalar(1))) 55 VERIFY_RAISES_ASSERT(VX(Scalar(3), Scalar(1))) 56 VERIFY_RAISES_ASSERT(VX(Scalar(123), Scalar(123))) 57 } 58 } 59 60 void test_smallvectors() 61 { 62 for(int i = 0; i < g_repeat; i++) { 63 CALL_SUBTEST(smallVectors<int>() ); 64 CALL_SUBTEST(smallVectors<float>() ); 65 CALL_SUBTEST(smallVectors<double>() ); 66 } 67 } 68