~ubuntu-branches/ubuntu/quantal/aqsis/quantal

« back to all changes in this revision

Viewing changes to libs/math/matrix2d_test.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-06 04:53:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806045326-z6xeaaao62idxcc6
Tags: 1.6.0-0ubuntu1
* New upstream release
* debian/control:
  - changed name of lib package to libaqsis1 instead of aqsis-libsc2a
  - changed name of dev package to libaqsis-dev instead of aqsis-libs-dev
  - Added aqsis-data package
  - Revised summary text according to that specified by the RISpec (Pixar)
* Moved examples installation from aqsis.install to aqsis-data.install
* debian/rules: 
  - added content to binary-indep target
* debian/rules: added explicit name of mime file to force dh_installmime
  to generate postinst and prerm scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright (C) 1997 - 2007, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.org
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
/** \file
 
21
 *
 
22
 * \brief Unit tests for SqMatrix2D
 
23
 * \author Chris Foster [ chris42f (at) gmail (dot) com ]
 
24
 */
 
25
 
 
26
#include <aqsis/math/matrix2d.h>
 
27
 
 
28
#ifndef AQSIS_SYSTEM_WIN32
 
29
#define BOOST_TEST_DYN_LINK
 
30
#endif //AQSIS_SYSTEM_WIN32
 
31
 
 
32
#include <boost/test/auto_unit_test.hpp>
 
33
#include <boost/test/floating_point_comparison.hpp>
 
34
 
 
35
static const TqFloat closeEps = 1e-5f;
 
36
 
 
37
BOOST_AUTO_TEST_CASE(SqMatrix2D_inv_test)
 
38
{
 
39
        Aqsis::SqMatrix2D A(1,2,3,4);
 
40
        Aqsis::SqMatrix2D Ainv = A.inv();
 
41
        Aqsis::SqMatrix2D I = A*Ainv;
 
42
        BOOST_CHECK_CLOSE(I.a, 1.0f, closeEps);
 
43
        BOOST_CHECK_SMALL(I.b, closeEps);
 
44
        BOOST_CHECK_SMALL(I.c, closeEps);
 
45
        BOOST_CHECK_CLOSE(I.d, 1.0f, closeEps);
 
46
}
 
47
 
 
48
BOOST_AUTO_TEST_CASE(SqMatrix2D_eigenvalue_test)
 
49
{
 
50
        TqFloat l1, l2;
 
51
 
 
52
        Aqsis::SqMatrix2D A(1);
 
53
        A.eigenvalues(l1,l2);
 
54
        BOOST_CHECK_CLOSE(l1, 1.0f, closeEps);
 
55
        BOOST_CHECK_CLOSE(l2, 1.0f, closeEps);
 
56
 
 
57
        A = Aqsis::SqMatrix2D(1,2);
 
58
        A.eigenvalues(l1,l2);
 
59
        BOOST_CHECK_CLOSE(l1, 2.0f, closeEps);
 
60
        BOOST_CHECK_CLOSE(l2, 1.0f, closeEps);
 
61
 
 
62
        A = Aqsis::SqMatrix2D(1,1, 1,2);
 
63
        A.eigenvalues(l1,l2);
 
64
        BOOST_CHECK_CLOSE(l1, TqFloat((3+std::sqrt(5.0f))/2), closeEps);
 
65
        BOOST_CHECK_CLOSE(l2, TqFloat((3-std::sqrt(5.0f))/2), closeEps);
 
66
}
 
67
 
 
68
BOOST_AUTO_TEST_CASE(SqMatrix2D_orthogDiagonalize_test)
 
69
{
 
70
        {
 
71
                TqFloat l1, l2;
 
72
                Aqsis::SqMatrix2D A = Aqsis::SqMatrix2D(1,2);
 
73
                A.eigenvalues(l1,l2);
 
74
                Aqsis::SqMatrix2D R = A.orthogDiagonalize(l1,l2);
 
75
                Aqsis::SqMatrix2D D = R.transpose()*A*R;
 
76
                BOOST_CHECK_CLOSE(D.a, l1, closeEps);
 
77
                BOOST_CHECK_CLOSE(D.d, l2, closeEps);
 
78
                BOOST_CHECK_SMALL(D.b, closeEps);
 
79
                BOOST_CHECK_SMALL(D.c, closeEps);
 
80
        }
 
81
 
 
82
        {
 
83
                TqFloat l1, l2;
 
84
                Aqsis::SqMatrix2D A(1,1, 1,2);
 
85
                A.eigenvalues(l1,l2);
 
86
                Aqsis::SqMatrix2D R = A.orthogDiagonalize(l1,l2);
 
87
                Aqsis::SqMatrix2D D = R.transpose()*A*R;
 
88
                BOOST_CHECK_CLOSE(D.a, TqFloat((3+std::sqrt(5.0f))/2), closeEps);
 
89
                BOOST_CHECK_CLOSE(D.d, TqFloat((3-std::sqrt(5.0f))/2), closeEps);
 
90
                BOOST_CHECK_SMALL(D.b, closeEps);
 
91
                BOOST_CHECK_SMALL(D.c, closeEps);
 
92
        }
 
93
}