Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / TestDiffFilter.cpp
blobe5bf36741dfb277ca30ab6b65d0be08dd9109769
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Math/DiffFilter.hpp"
24 #include "TestUtil.hpp"
26 #include <cstdio>
28 int
29 main(int argc, char **argv)
31 plan_tests(192 + 232 + 40);
33 DiffFilter df(fixed(0));
35 // Test steady-state response scaling
36 for (long dY = 1; dY <= 10000000; dY *= 10) {
37 df.Reset();
38 for (int Y = dY; Y < 30 * dY; Y += dY) {
39 if (Y < 6 * dY)
40 // Give the filter time to calm down before testing for steady state
41 df.Update(fixed(Y));
42 else {
43 // test if the filter response is close enough to dX
45 // the discrete filter design results in steady-state error
46 // of approximately 3.4507 percent
47 fixed error = fabs((df.Update(fixed(Y)) - fixed(dY)) / dY);
48 ok1(error < fixed(0.035));
53 // Test steady-state response scaling with reset(0, dX) call
54 for (long dY = 1; dY <= 10000000; dY *= 10) {
55 df.Reset(fixed(0), fixed(dY));
56 for (int Y = dY; Y < 30 * dY; Y += dY) {
57 // test if the filter response is close enough to dX
59 // the discrete filter design results in steady-state error
60 // of approximately 3.4507 percent
61 fixed error = fabs((df.Update(fixed(Y)) - fixed(dY)) / dY);
62 ok1(error < fixed(0.035));
66 df.Reset();
67 fixed p = fixed_two_pi / fixed(10);
68 for (int X = 0; X < 50; X += 1) {
69 // Y = sin(2 * pi * (X/10)
70 fixed Y = fixed(sin(p * X));
72 fixed dY_shifted = fixed(cos(p * (X - 3))) * p;
73 fixed dY_filter = df.Update(fixed(Y));
74 fixed error = fabs(dY_filter - dY_shifted);
75 if (X >= 10)
76 ok1(error < fixed(0.05));
79 return exit_status();