You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

  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@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. #define EIGEN_NO_STATIC_ASSERT
  10. #include "main.h"
  11. template<typename Scalar> void smallVectors()
  12. {
  13. typedef Matrix<Scalar, 1, 2> V2;
  14. typedef Matrix<Scalar, 3, 1> V3;
  15. typedef Matrix<Scalar, 1, 4> V4;
  16. typedef Matrix<Scalar, Dynamic, 1> VX;
  17. Scalar x1 = internal::random<Scalar>(),
  18. x2 = internal::random<Scalar>(),
  19. x3 = internal::random<Scalar>(),
  20. x4 = internal::random<Scalar>();
  21. V2 v2(x1, x2);
  22. V3 v3(x1, x2, x3);
  23. V4 v4(x1, x2, x3, x4);
  24. VERIFY_IS_APPROX(x1, v2.x());
  25. VERIFY_IS_APPROX(x1, v3.x());
  26. VERIFY_IS_APPROX(x1, v4.x());
  27. VERIFY_IS_APPROX(x2, v2.y());
  28. VERIFY_IS_APPROX(x2, v3.y());
  29. VERIFY_IS_APPROX(x2, v4.y());
  30. VERIFY_IS_APPROX(x3, v3.z());
  31. VERIFY_IS_APPROX(x3, v4.z());
  32. VERIFY_IS_APPROX(x4, v4.w());
  33. if (!NumTraits<Scalar>::IsInteger)
  34. {
  35. VERIFY_RAISES_ASSERT(V3(2, 1))
  36. VERIFY_RAISES_ASSERT(V3(3, 2))
  37. VERIFY_RAISES_ASSERT(V3(Scalar(3), 1))
  38. VERIFY_RAISES_ASSERT(V3(3, Scalar(1)))
  39. VERIFY_RAISES_ASSERT(V3(Scalar(3), Scalar(1)))
  40. VERIFY_RAISES_ASSERT(V3(Scalar(123), Scalar(123)))
  41. VERIFY_RAISES_ASSERT(V4(1, 3))
  42. VERIFY_RAISES_ASSERT(V4(2, 4))
  43. VERIFY_RAISES_ASSERT(V4(1, Scalar(4)))
  44. VERIFY_RAISES_ASSERT(V4(Scalar(1), 4))
  45. VERIFY_RAISES_ASSERT(V4(Scalar(1), Scalar(4)))
  46. VERIFY_RAISES_ASSERT(V4(Scalar(123), Scalar(123)))
  47. VERIFY_RAISES_ASSERT(VX(3, 2))
  48. VERIFY_RAISES_ASSERT(VX(Scalar(3), 1))
  49. VERIFY_RAISES_ASSERT(VX(3, Scalar(1)))
  50. VERIFY_RAISES_ASSERT(VX(Scalar(3), Scalar(1)))
  51. VERIFY_RAISES_ASSERT(VX(Scalar(123), Scalar(123)))
  52. }
  53. }
  54. void test_smallvectors()
  55. {
  56. for(int i = 0; i < g_repeat; i++) {
  57. CALL_SUBTEST(smallVectors<int>() );
  58. CALL_SUBTEST(smallVectors<float>() );
  59. CALL_SUBTEST(smallVectors<double>() );
  60. }
  61. }