comparison data/model/test/TestFFTModel.h @ 1086:9f4505ac9072

Tidy dense time-value model API a bit; add first simple unit test for FFT model
author Chris Cannam
date Wed, 10 Jun 2015 17:06:02 +0100
parents
children 5fab8e4f5f19
comparison
equal deleted inserted replaced
1085:bf6f64dabe73 1086:9f4505ac9072
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 #ifndef TEST_FFT_MODEL_H
16 #define TEST_FFT_MODEL_H
17
18 #include "../FFTModel.h"
19
20 #include "MockWaveModel.h"
21
22 #include "Compares.h"
23
24 #include <QObject>
25 #include <QtTest>
26 #include <QDir>
27
28 #include <iostream>
29
30 using namespace std;
31
32 class TestFFTModel : public QObject
33 {
34 Q_OBJECT
35
36 private slots:
37
38 void example() {
39 MockWaveModel mwm({ DC }, 16);
40 FFTModel fftm(&mwm, 0, RectangularWindow, 8, 8, 8, false);
41 float reals[6], imags[6];
42 reals[5] = 999.f; // overrun guards
43 imags[5] = 999.f;
44 fftm.getValuesAt(0, reals, imags);
45 cerr << "reals: " << reals[0] << "," << reals[1] << "," << reals[2] << "," << reals[3] << "," << reals[4] << endl;
46 cerr << "imags: " << imags[0] << "," << imags[1] << "," << imags[2] << "," << imags[3] << "," << imags[4] << endl;
47 QCOMPARE(reals[0], 4.f); // rectangular window scales by 0.5
48 QCOMPARE(reals[1], 0.f);
49 QCOMPARE(reals[2], 0.f);
50 QCOMPARE(reals[3], 0.f);
51 QCOMPARE(reals[4], 0.f);
52 QCOMPARE(reals[5], 999.f);
53 QCOMPARE(imags[5], 999.f);
54 imags[5] = 0.f;
55 COMPARE_ALL_TO_F(imags, 0.f);
56 }
57
58 };
59
60 #endif