Chris@47: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@47: /* Chris@47: This file is Copyright (c) 2012 Chris Cannam Chris@47: Chris@47: Permission is hereby granted, free of charge, to any person Chris@47: obtaining a copy of this software and associated documentation Chris@47: files (the "Software"), to deal in the Software without Chris@47: restriction, including without limitation the rights to use, copy, Chris@47: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@47: of the Software, and to permit persons to whom the Software is Chris@47: furnished to do so, subject to the following conditions: Chris@47: Chris@47: The above copyright notice and this permission notice shall be Chris@47: included in all copies or substantial portions of the Software. Chris@47: Chris@47: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@47: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@47: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@47: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@47: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@47: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@47: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@47: */ Chris@47: Chris@47: #include "MeanFilter.h" Chris@47: Chris@47: #define BOOST_TEST_DYN_LINK Chris@47: #define BOOST_TEST_MAIN Chris@47: Chris@47: #include Chris@47: Chris@47: BOOST_AUTO_TEST_SUITE(TestMeanFilter) Chris@47: Chris@47: BOOST_AUTO_TEST_CASE(simpleFilter) Chris@47: { Chris@47: double in[] = { 1.0, 2.0, 3.0 }; Chris@47: double out[3]; Chris@47: MeanFilter(3).filter(in, out, 3); Chris@47: BOOST_CHECK_EQUAL(out[0], 1.5); Chris@47: BOOST_CHECK_EQUAL(out[1], 2.0); Chris@47: BOOST_CHECK_EQUAL(out[2], 2.5); Chris@47: } Chris@47: Chris@47: BOOST_AUTO_TEST_CASE(simpleSubset) Chris@47: { Chris@47: double in[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; Chris@47: double out[3]; Chris@47: MeanFilter(3).filterSubsequence(in, out, 5, 3, 1); Chris@47: BOOST_CHECK_EQUAL(out[0], 2.0); Chris@47: BOOST_CHECK_EQUAL(out[1], 3.0); Chris@47: BOOST_CHECK_EQUAL(out[2], 4.0); Chris@47: } Chris@47: Chris@47: BOOST_AUTO_TEST_CASE(flenExceedsArraySize) Chris@47: { Chris@47: double in[] = { 1.0, 2.0, 3.0 }; Chris@47: double out[3]; Chris@47: MeanFilter(5).filter(in, out, 3); Chris@47: BOOST_CHECK_EQUAL(out[0], 2.0); Chris@47: BOOST_CHECK_EQUAL(out[1], 2.0); Chris@47: BOOST_CHECK_EQUAL(out[2], 2.0); Chris@47: } Chris@47: Chris@47: BOOST_AUTO_TEST_CASE(flenIs1) Chris@47: { Chris@47: double in[] = { 1.0, 2.0, 3.0 }; Chris@47: double out[3]; Chris@47: MeanFilter(1).filter(in, out, 3); Chris@47: BOOST_CHECK_EQUAL(out[0], in[0]); Chris@47: BOOST_CHECK_EQUAL(out[1], in[1]); Chris@47: BOOST_CHECK_EQUAL(out[2], in[2]); Chris@47: } Chris@47: Chris@47: BOOST_AUTO_TEST_CASE(arraySizeIs1) Chris@47: { Chris@47: double in[] = { 1.0 }; Chris@47: double out[1]; Chris@47: MeanFilter(3).filter(in, out, 1); Chris@47: BOOST_CHECK_EQUAL(out[0], in[0]); Chris@47: } Chris@47: Chris@47: BOOST_AUTO_TEST_CASE(subsequenceLengthIs1) Chris@47: { Chris@47: double in[] = { 1.0, 2.0, 3.0 }; Chris@47: double out[1]; Chris@47: MeanFilter(3).filterSubsequence(in, out, 3, 1, 2); Chris@47: BOOST_CHECK_EQUAL(out[0], 2.5); Chris@47: } Chris@47: Chris@47: BOOST_AUTO_TEST_SUITE_END() Chris@47: