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