Files
android
doc
m4
scripts
src
systemd
test
.gitignore
DivideStringTest.hxx
DumpDatabase.cxx
FakeDecoderAPI.cxx
FakeDecoderAPI.hxx
FakeReplayGainConfig.cxx
ScopeIOThread.hxx
ShutdownHandler.cxx
ShutdownHandler.hxx
SplitStringTest.hxx
TestCircularBuffer.hxx
TestIcu.cxx
UriUtilTest.hxx
WriteFile.cxx
dump_playlist.cxx
dump_rva2.cxx
dump_text_file.cxx
read_conf.cxx
read_mixer.cxx
read_tags.cxx
run_avahi.cxx
run_convert.cxx
run_decoder.cxx
run_encoder.cxx
run_filter.cxx
run_gunzip.cxx
run_gzip.cxx
run_inotify.cxx
run_input.cxx
run_neighbor_explorer.cxx
run_normalize.cxx
run_output.cxx
run_resolver.cxx
run_storage.cxx
software_volume.cxx
stdbin.h
test_archive.cxx
test_archive_bzip2.sh
test_archive_iso9660.sh
test_archive_zzip.sh
test_byte_reverse.cxx
test_icy_parser.cxx
test_mixramp.cxx
test_pcm_all.hxx
test_pcm_channels.cxx
test_pcm_dither.cxx
test_pcm_export.cxx
test_pcm_format.cxx
test_pcm_main.cxx
test_pcm_mix.cxx
test_pcm_pack.cxx
test_pcm_util.hxx
test_pcm_volume.cxx
test_protocol.cxx
test_queue_priority.cxx
test_rewind.cxx
test_translate_song.cxx
test_util.cxx
test_vorbis_encoder.cxx
visit_archive.cxx
win32
.gitignore
AUTHORS
COPYING
INSTALL
Makefile.am
NEWS
README
autogen.sh
configure.ac
mpd.svg
valgrind.suppressions
mpd/test/test_mixramp.cxx
Max Kellermann 39257717d8 test/test_mixramp: add threshold to floating point comparisons
Fixes bogus test failures on Debian build machines due to rounding
errors (hopefully).
2013-11-04 22:08:59 +01:00

88 lines
2.0 KiB
C++

/*
* Unit tests for mixramp_interpolate()
*/
#include "config.h"
#include "CrossFade.cxx"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <string.h>
class MixRampTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(MixRampTest);
CPPUNIT_TEST(TestInterpolate);
CPPUNIT_TEST_SUITE_END();
public:
void TestInterpolate() {
const char *input = "1.0 0.00;3.0 0.10;6.0 2.50;";
char *foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(double(0),
mixramp_interpolate(foo, 0),
0.05);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(0),
mixramp_interpolate(foo, 1),
0.005);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(0.1),
mixramp_interpolate(foo, 3),
0.005);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(2.5),
mixramp_interpolate(foo, 6),
0.01);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT(mixramp_interpolate(foo, 6.1) < 0);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(0.05),
mixramp_interpolate(foo, 2),
0.05);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(1.3),
mixramp_interpolate(foo, 4.5),
0.05);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(0.9),
mixramp_interpolate(foo, 4),
0.05);
free(foo);
foo = strdup(input);
CPPUNIT_ASSERT_DOUBLES_EQUAL(float(1.7),
mixramp_interpolate(foo, 5),
0.05);
free(foo);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(MixRampTest);
int
main(gcc_unused int argc, gcc_unused char **argv)
{
CppUnit::TextUi::TestRunner runner;
auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
}