summaryrefslogtreecommitdiff
path: root/test/test_mixramp.cxx
blob: ea245f72ff45018f375f7fadd960c66578c9e368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Unit tests for mixramp_interpolate()
 */

#include "config.h"
#include "player/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;
}