matthiasm@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
matthiasm@0
|
2 /*
|
matthiasm@0
|
3 This file is Copyright (c) 2012 Chris Cannam
|
matthiasm@0
|
4
|
matthiasm@0
|
5 Permission is hereby granted, free of charge, to any person
|
matthiasm@0
|
6 obtaining a copy of this software and associated documentation
|
matthiasm@0
|
7 files (the "Software"), to deal in the Software without
|
matthiasm@0
|
8 restriction, including without limitation the rights to use, copy,
|
matthiasm@0
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
matthiasm@0
|
10 of the Software, and to permit persons to whom the Software is
|
matthiasm@0
|
11 furnished to do so, subject to the following conditions:
|
matthiasm@0
|
12
|
matthiasm@0
|
13 The above copyright notice and this permission notice shall be
|
matthiasm@0
|
14 included in all copies or substantial portions of the Software.
|
matthiasm@0
|
15
|
matthiasm@0
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
matthiasm@0
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
matthiasm@0
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
matthiasm@0
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
matthiasm@0
|
20 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
matthiasm@0
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
matthiasm@0
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
matthiasm@0
|
23 */
|
matthiasm@0
|
24
|
matthiasm@0
|
25 #include "MeanFilter.h"
|
matthiasm@0
|
26
|
matthiasm@0
|
27 #define BOOST_TEST_DYN_LINK
|
matthiasm@0
|
28 #define BOOST_TEST_MAIN
|
matthiasm@0
|
29
|
matthiasm@0
|
30 #include <boost/test/unit_test.hpp>
|
matthiasm@0
|
31
|
matthiasm@0
|
32 BOOST_AUTO_TEST_SUITE(TestMeanFilter)
|
matthiasm@0
|
33
|
matthiasm@0
|
34 BOOST_AUTO_TEST_CASE(simpleFilter)
|
matthiasm@0
|
35 {
|
matthiasm@0
|
36 double in[] = { 1.0, 2.0, 3.0 };
|
matthiasm@0
|
37 double out[3];
|
matthiasm@0
|
38 MeanFilter(3).filter(in, out, 3);
|
matthiasm@0
|
39 BOOST_CHECK_EQUAL(out[0], 1.5);
|
matthiasm@0
|
40 BOOST_CHECK_EQUAL(out[1], 2.0);
|
matthiasm@0
|
41 BOOST_CHECK_EQUAL(out[2], 2.5);
|
matthiasm@0
|
42 }
|
matthiasm@0
|
43
|
matthiasm@0
|
44 BOOST_AUTO_TEST_CASE(simpleSubset)
|
matthiasm@0
|
45 {
|
matthiasm@0
|
46 double in[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
|
matthiasm@0
|
47 double out[3];
|
matthiasm@0
|
48 MeanFilter(3).filterSubsequence(in, out, 5, 3, 1);
|
matthiasm@0
|
49 BOOST_CHECK_EQUAL(out[0], 2.0);
|
matthiasm@0
|
50 BOOST_CHECK_EQUAL(out[1], 3.0);
|
matthiasm@0
|
51 BOOST_CHECK_EQUAL(out[2], 4.0);
|
matthiasm@0
|
52 }
|
matthiasm@0
|
53
|
matthiasm@0
|
54 BOOST_AUTO_TEST_CASE(flenExceedsArraySize)
|
matthiasm@0
|
55 {
|
matthiasm@0
|
56 double in[] = { 1.0, 2.0, 3.0 };
|
matthiasm@0
|
57 double out[3];
|
matthiasm@0
|
58 MeanFilter(5).filter(in, out, 3);
|
matthiasm@0
|
59 BOOST_CHECK_EQUAL(out[0], 2.0);
|
matthiasm@0
|
60 BOOST_CHECK_EQUAL(out[1], 2.0);
|
matthiasm@0
|
61 BOOST_CHECK_EQUAL(out[2], 2.0);
|
matthiasm@0
|
62 }
|
matthiasm@0
|
63
|
matthiasm@0
|
64 BOOST_AUTO_TEST_CASE(flenIs1)
|
matthiasm@0
|
65 {
|
matthiasm@0
|
66 double in[] = { 1.0, 2.0, 3.0 };
|
matthiasm@0
|
67 double out[3];
|
matthiasm@0
|
68 MeanFilter(1).filter(in, out, 3);
|
matthiasm@0
|
69 BOOST_CHECK_EQUAL(out[0], in[0]);
|
matthiasm@0
|
70 BOOST_CHECK_EQUAL(out[1], in[1]);
|
matthiasm@0
|
71 BOOST_CHECK_EQUAL(out[2], in[2]);
|
matthiasm@0
|
72 }
|
matthiasm@0
|
73
|
matthiasm@0
|
74 BOOST_AUTO_TEST_CASE(arraySizeIs1)
|
matthiasm@0
|
75 {
|
matthiasm@0
|
76 double in[] = { 1.0 };
|
matthiasm@0
|
77 double out[1];
|
matthiasm@0
|
78 MeanFilter(3).filter(in, out, 1);
|
matthiasm@0
|
79 BOOST_CHECK_EQUAL(out[0], in[0]);
|
matthiasm@0
|
80 }
|
matthiasm@0
|
81
|
matthiasm@0
|
82 BOOST_AUTO_TEST_CASE(subsequenceLengthIs1)
|
matthiasm@0
|
83 {
|
matthiasm@0
|
84 double in[] = { 1.0, 2.0, 3.0 };
|
matthiasm@0
|
85 double out[1];
|
matthiasm@0
|
86 MeanFilter(3).filterSubsequence(in, out, 3, 1, 2);
|
matthiasm@0
|
87 BOOST_CHECK_EQUAL(out[0], 2.5);
|
matthiasm@0
|
88 }
|
matthiasm@0
|
89
|
matthiasm@0
|
90 BOOST_AUTO_TEST_SUITE_END()
|
matthiasm@0
|
91
|