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