Chris@52: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@52: /* Chris@52: This file is Copyright (c) 2012 Chris Cannam Chris@52: Chris@52: Permission is hereby granted, free of charge, to any person Chris@52: obtaining a copy of this software and associated documentation Chris@52: files (the "Software"), to deal in the Software without Chris@52: restriction, including without limitation the rights to use, copy, Chris@52: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@52: of the Software, and to permit persons to whom the Software is Chris@52: furnished to do so, subject to the following conditions: Chris@52: Chris@52: The above copyright notice and this permission notice shall be Chris@52: included in all copies or substantial portions of the Software. Chris@52: Chris@52: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@52: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@52: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@52: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@52: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@52: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@52: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@52: */ Chris@52: Chris@52: #include "AgentFeeder.h" Chris@52: Chris@52: #define BOOST_TEST_DYN_LINK Chris@52: #define BOOST_TEST_MAIN Chris@52: Chris@52: #include Chris@52: Chris@52: static Vamp::RealTime ms(int n) { return Vamp::RealTime::fromMilliseconds(n); } Chris@52: Chris@54: static const int low = 500, high = 700; Chris@54: Chris@52: typedef NoteHypothesis::Estimate Est; Chris@52: Chris@52: BOOST_AUTO_TEST_SUITE(TestAgentFeeder) Chris@52: Chris@52: BOOST_AUTO_TEST_CASE(feederEmpty) Chris@52: { Chris@52: AgentFeeder f; Chris@52: f.finish(); Chris@52: AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses(); Chris@52: BOOST_CHECK(accepted.empty()); Chris@52: } Chris@52: Chris@52: BOOST_AUTO_TEST_CASE(feederSingle) Chris@52: { Chris@54: Est e0(low, ms(0), 1); Chris@54: Est e10(low, ms(10), 1); Chris@54: Est e20(low, ms(20), 1); Chris@54: Est e30(low, ms(30), 1); Chris@52: Chris@52: AgentFeeder f; Chris@52: f.feed(e0); Chris@52: f.feed(e10); Chris@52: f.feed(e20); Chris@52: f.feed(e30); Chris@52: f.finish(); Chris@52: Chris@52: AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(accepted.size(), size_t(1)); Chris@52: } Chris@52: Chris@52: BOOST_AUTO_TEST_CASE(feederPairSeparate) Chris@52: { Chris@54: Est e0(low, ms(0), 1); Chris@54: Est e10(low, ms(10), 1); Chris@54: Est e20(low, ms(20), 1); Chris@54: Est e30(low, ms(30), 1); Chris@52: Chris@54: Est f0(high, ms(2000), 1); Chris@54: Est f10(high, ms(2010), 1); Chris@54: Est f20(high, ms(2020), 1); Chris@54: Est f30(high, ms(2030), 1); Chris@52: Chris@52: AgentFeeder f; Chris@52: f.feed(e0); Chris@52: f.feed(e10); Chris@52: f.feed(e20); Chris@52: f.feed(e30); Chris@52: f.feed(f0); Chris@52: f.feed(f10); Chris@52: f.feed(f20); Chris@52: f.feed(f30); Chris@52: f.finish(); Chris@52: Chris@52: AgentFeeder::Hypotheses accepted = Chris@52: f.getAcceptedHypotheses(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(accepted.size(), size_t(2)); Chris@52: } Chris@52: Chris@52: BOOST_AUTO_TEST_CASE(feederPairOverlapping) Chris@52: { Chris@52: // eeee Chris@52: // fffffff Chris@52: Chris@52: // (With fffffff stopping before eeee has expired.) Chris@52: Chris@54: // This should give us one hypothesis, eeee, because eeee is still Chris@54: // the current hypothesis by the time fffffff ends. Chris@52: Chris@54: Est e0(low, ms(0), 1); Chris@54: Est e10(low, ms(10), 1); Chris@52: Chris@54: Est e20(low, ms(20), 1); Chris@54: Est f20(high, ms(20), 1); Chris@52: Chris@54: Est e30(low, ms(30), 1); Chris@54: Est f30(high, ms(30), 1); Chris@52: Chris@54: Est f40(high, ms(40), 1); Chris@54: Est f41(high, ms(41), 1); Chris@54: Est f42(high, ms(42), 1); Chris@54: Est f43(high, ms(43), 1); Chris@54: Est f44(high, ms(44), 1); Chris@52: Chris@52: AgentFeeder f; Chris@52: f.feed(e0); Chris@52: f.feed(e10); Chris@52: f.feed(e20); Chris@52: f.feed(f20); Chris@52: f.feed(e30); Chris@52: f.feed(f30); Chris@52: f.feed(f40); Chris@54: f.feed(f41); Chris@54: f.feed(f42); Chris@54: f.feed(f43); Chris@54: f.feed(f44); Chris@52: f.finish(); Chris@52: Chris@52: AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(accepted.size(), size_t(1)); Chris@52: Chris@52: AgentFeeder::Hypotheses::const_iterator i = accepted.begin(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(i->getStartTime(), ms(0)); Chris@52: BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4)); Chris@52: } Chris@52: Chris@52: BOOST_AUTO_TEST_CASE(feederPairOverlappingLong) Chris@52: { Chris@52: // eeee Chris@52: // fffffff Chris@52: Chris@52: // (With fffffff continuing until after eeee has expired.) Chris@52: Chris@52: // This should give us two overlapping hypotheses. Even though Chris@52: // the mono feeder only has one satisfied hypothesis at a Chris@52: // time, the eeee hypothesis should become satisfied before Chris@52: // the fffffff hypothesis has been, but when the eeee Chris@52: // hypothesis ends, the fffffff one should replace it. So, Chris@52: // both should be recognised. Chris@52: Chris@54: Est e0(low, ms(0), 1); Chris@54: Est e10(low, ms(10), 1); Chris@52: Chris@54: Est e20(low, ms(20), 1); Chris@54: Est f20(high, ms(20), 1); Chris@52: Chris@54: Est e30(low, ms(30), 1); Chris@54: Est f30(high, ms(30), 1); Chris@52: Chris@54: Est f40(high, ms(40), 1); Chris@54: Est f50(high, ms(50), 1); Chris@54: Est f60(high, ms(60), 1); Chris@54: Est f70(high, ms(70), 1); Chris@54: Est f80(high, ms(80), 1); Chris@52: Chris@52: AgentFeeder f; Chris@52: f.feed(e0); Chris@52: f.feed(e10); Chris@52: f.feed(e20); Chris@52: f.feed(f20); Chris@52: f.feed(e30); Chris@52: f.feed(f30); Chris@52: f.feed(f40); Chris@52: f.feed(f50); Chris@52: f.feed(f60); Chris@52: f.feed(f70); Chris@52: f.feed(f80); Chris@52: f.finish(); Chris@52: Chris@52: AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(accepted.size(), size_t(2)); Chris@52: Chris@52: AgentFeeder::Hypotheses::const_iterator i = accepted.begin(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(i->getStartTime(), ms(0)); Chris@52: BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4)); Chris@52: ++i; Chris@52: Chris@54: BOOST_CHECK_EQUAL(i->getStartTime(), ms(20)); Chris@52: BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(7)); Chris@52: ++i; Chris@52: } Chris@52: Chris@52: Chris@52: BOOST_AUTO_TEST_CASE(feederPairContaining) Chris@52: { Chris@52: // eeeeeeee Chris@52: // ffff Chris@52: Chris@52: // This should give us eeeeeeee only. The ffff hypothesis Chris@52: // (even when satisfied itself) cannot replace the single Chris@52: // satisfied hypothesis eeeeeeee while it is still in Chris@52: // progress. Chris@52: Chris@54: Est e0(low, ms(0), 1); Chris@54: Est e10(low, ms(10), 1); Chris@54: Est e20(low, ms(20), 1); Chris@54: Est e30(low, ms(30), 1); Chris@54: Est e40(low, ms(40), 1); Chris@54: Est e50(low, ms(50), 1); Chris@54: Est e60(low, ms(60), 1); Chris@54: Est e70(low, ms(70), 1); Chris@52: Chris@54: Est f20(high, ms(20), 1); Chris@54: Est f30(high, ms(30), 1); Chris@54: Est f40(high, ms(40), 1); Chris@54: Est f50(high, ms(50), 1); Chris@52: Chris@52: AgentFeeder f; Chris@52: Chris@52: f.feed(e0); Chris@52: f.feed(e10); Chris@52: Chris@52: f.feed(e20); Chris@52: f.feed(f20); Chris@52: Chris@52: f.feed(e30); Chris@52: f.feed(f30); Chris@52: Chris@52: f.feed(e40); Chris@52: f.feed(f40); Chris@52: Chris@52: f.feed(e50); Chris@52: f.feed(f50); Chris@52: Chris@52: f.feed(e60); Chris@52: f.feed(e70); Chris@52: Chris@52: f.finish(); Chris@52: Chris@52: AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(accepted.size(), size_t(1)); Chris@52: Chris@52: AgentFeeder::Hypotheses::const_iterator i = accepted.begin(); Chris@52: Chris@52: BOOST_CHECK_EQUAL(i->getStartTime(), ms(0)); Chris@52: BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(8)); Chris@52: ++i; Chris@52: } Chris@52: Chris@52: BOOST_AUTO_TEST_SUITE_END() Chris@52: