tests: FFT of a constant input

This commit is contained in:
Alexander Kojevnikov 2013-04-11 10:48:39 -07:00
parent 0e03fc977b
commit 5eab9ea6f8
4 changed files with 68 additions and 0 deletions

View File

@ -8,6 +8,7 @@ check_PROGRAMS = $(TESTS)
test_SOURCES = \
test-audio.cc \
test-fft.cc \
test-utils.cc \
test.cc \
test.h

65
tests/test-fft.cc Normal file
View File

@ -0,0 +1,65 @@
/* test-fft.cc
*
* Copyright (C) 2013 Alexander Kojevnikov <alexander@kojevnikov.com>
*
* Spek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Spek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Spek. If not, see <http://www.gnu.org/licenses/>.
*/
#include "spek-fft.h"
#include "test.h"
static void test_const()
{
FFT fft;
for (int nbits = 4; nbits < 16; ++nbits) {
auto plan = fft.create(nbits);
test("input size", 1 << nbits, plan->get_input_size());
test("output size", (1 << nbits) / 2 + 1, plan->get_output_size());
// Test zero input.
for (int i = 0; i < plan->get_input_size(); ++i) {
plan->set_input(i, 0.0f);
}
plan->execute();
bool ok = true;
for (int i = 0; i < plan->get_output_size(); ++i) {
if (plan->get_output(i) > -1e12f) {
ok = false;
break;
}
}
test("zero input", true, ok);
// Test DC input.
for (int i = 0; i < plan->get_input_size(); ++i) {
plan->set_input(i, 1.0f);
}
plan->execute();
ok = true;
test("dc component", 0.0f, plan->get_output(0));
for (int i = 1; i < plan->get_output_size(); ++i) {
if (plan->get_output(i) > -1e12f) {
ok = false;
break;
}
}
test("dc input", true, ok);
}
}
void test_fft()
{
run("fft const", test_const);
}

View File

@ -26,6 +26,7 @@ int main()
std::cerr << "-------------" << std::endl;
test_audio();
test_fft();
test_utils();
if (g_passes < g_total) {

View File

@ -52,6 +52,7 @@ template<class T> void test(const std::string& message, const T& expected, const
}
void test_audio();
void test_fft();
void test_utils();
#endif