00001 #include <cstdlib>
00002 #include <iostream>
00003 #include <complex>
00004
00005 #include <kfilter/kvector.hpp>
00006
00007 using namespace std;
00008 using namespace Kalman;
00009
00010 template <typename T, K_UINT_32 BEG, bool DBG>
00011 void test() {
00012
00013 typedef KVector<T, BEG, DBG> Vector;
00014 T values[5] = {5.0, 4.0, 3.0, 2.0, 1.0};
00015
00016
00017 Vector v0;
00018 Vector v1(0);
00019 Vector v2(5);
00020 Vector v3(0, T(1.0));
00021 Vector v4(4, T(2.0));
00022 Vector v5(0, values);
00023 Vector v6(3, values);
00024 Vector v7(v5);
00025 Vector v8(v6);
00026
00027 cout << "v0 : " << v0 << endl;
00028 cout << "v1 : " << v1 << endl;
00029 cout << "v2 : " << v2 << endl;
00030 cout << "v3 : " << v3 << endl;
00031 cout << "v4 : " << v4 << endl;
00032 cout << "v5 : " << v5 << endl;
00033 cout << "v6 : " << v6 << endl;
00034 cout << "v7 : " << v7 << endl;
00035 cout << "v8 : " << v8 << endl << endl;
00036
00037
00038 v4.resize(0);
00039 v4 = T(-1.0);
00040 v5 = T(6.0);
00041 v6 = T(7.0);
00042 v7.resize(2);
00043 v7 = T(8.0);
00044 v8.resize(6);
00045 v8 = T(9.0);
00046
00047 cout << "v4 : " << v4 << endl;
00048 cout << "v5 : " << v5 << endl;
00049 cout << "v6 : " << v6 << endl;
00050 cout << "v7 : " << v7 << endl;
00051 cout << "v8 : " << v8 << endl << endl;
00052
00053
00054
00055 v5 = v7;
00056 v6 = v8;
00057 v7 = v0;
00058 v0.assign(0, values);
00059 v1.assign(2, values);
00060 v2.assign(0, values);
00061 v4.assign(3, values);
00062
00063 cout << "v0 : " << v0 << endl;
00064 cout << "v1 : " << v1 << endl;
00065 cout << "v2 : " << v2 << endl;
00066 cout << "v3 : " << v3 << endl;
00067 cout << "v4 : " << v4 << endl;
00068 cout << "v5 : " << v5 << endl;
00069 cout << "v6 : " << v6 << endl;
00070 cout << "v7 : " << v7 << endl;
00071 cout << "v8 : " << v8 << endl << endl;
00072
00073
00074
00075 const Vector& ref = v4;
00076
00077 cout << "v4(1) = " << v4(1) << endl;
00078 cout << "ref(1) = " << ref(1) << endl;
00079
00080 v4(1) = T(3.0);
00081
00082
00083 cout << "v4(1) = " << v4(1) << endl;
00084 cout << "ref(1) = " << ref(1) << endl;
00085
00086 if (DBG) {
00087
00088 try {
00089 v4(100) = T(7.0);
00090 } catch(OutOfBoundError& e) {
00091 cout << e.what() << endl;
00092 }
00093
00094 try {
00095 cout << ref(100) << endl;
00096 } catch(OutOfBoundError& e) {
00097 cout << e.what() << endl;
00098 }
00099
00100 }
00101
00102 cout << endl;
00103
00104
00105
00106
00107 cout << "v0 is of size : " << v0.size() << endl;
00108 cin >> v0;
00109 cout << "v0 : " << v0 << endl;
00110
00111 cout << "v1 is of size : " << v1.size() << endl;
00112 cin >> v1;
00113 cout << "v1 : " << v1 << endl;
00114
00115 cout << "----------------------------" << endl << endl;
00116
00117 }
00118
00119 int main() {
00120 test<float, 0, true>();
00121 test<float, 0, false>();
00122 test<float, 1, true>();
00123 test<float, 1, false>();
00124 test<double, 0, true>();
00125 test<double, 0, false>();
00126 test<double, 1, true>();
00127 test<double, 1, false>();
00128 test<complex<double>, 0, true>();
00129 test<complex<double>, 0, false>();
00130 test<complex<double>, 1, true>();
00131 test<complex<double>, 1, false>();
00132 return 0;
00133 }