2010-04-11 01:11:39 +02:00
|
|
|
|
/*
|
|
|
|
|
|
AdviceIndex(Test) - cover the index datastructure used to implement Advice dispatch
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2010-04-11 01:11:39 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file advice-index-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref AdviceIndex_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2010-04-11 01:11:39 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2012-12-02 23:03:37 +01:00
|
|
|
|
#include "lib/hash-value.h"
|
2012-12-01 08:44:07 +01:00
|
|
|
|
#include "common/advice/index.hpp"
|
2010-04-11 01:11:39 +02:00
|
|
|
|
|
2010-04-25 01:51:30 +02:00
|
|
|
|
#include <vector>
|
2010-04-11 01:11:39 +02:00
|
|
|
|
|
2010-04-24 17:31:01 +02:00
|
|
|
|
using lib::Literal;
|
2010-04-11 01:11:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-01 08:44:07 +01:00
|
|
|
|
namespace lumiera {
|
2010-04-11 01:11:39 +02:00
|
|
|
|
namespace advice {
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2010-04-24 17:31:01 +02:00
|
|
|
|
namespace { // test support definitions
|
|
|
|
|
|
|
2010-05-06 03:52:11 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Test dummy record, representing
|
|
|
|
|
|
* either a provision or an request.
|
|
|
|
|
|
* The advice binding is simulated by
|
|
|
|
|
|
* storing a pattern matcher, and for
|
|
|
|
|
|
* the case of the advice request, the
|
|
|
|
|
|
* solution is simulated by a \c TestPOA*
|
|
|
|
|
|
*/
|
2010-04-24 17:31:01 +02:00
|
|
|
|
struct TestPOA
|
|
|
|
|
|
{
|
2010-04-25 01:51:30 +02:00
|
|
|
|
TestPOA* solution_;
|
|
|
|
|
|
Binding::Matcher pattern_;
|
2010-04-24 17:31:01 +02:00
|
|
|
|
|
2010-04-25 01:51:30 +02:00
|
|
|
|
explicit
|
|
|
|
|
|
TestPOA(Literal spec="missing")
|
|
|
|
|
|
: solution_(0)
|
|
|
|
|
|
, pattern_(Binding(spec).buildMatcher())
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
matches (Literal refSpec) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return pattern_.matches (Binding(refSpec));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-06-04 17:25:33 +02:00
|
|
|
|
void
|
|
|
|
|
|
changeBinding (Literal newSpec)
|
|
|
|
|
|
{
|
|
|
|
|
|
pattern_ = Binding(newSpec).buildMatcher();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-25 01:51:30 +02:00
|
|
|
|
|
2010-04-25 15:15:53 +02:00
|
|
|
|
/* == Adapter interface for use within the Index == */
|
|
|
|
|
|
|
2010-06-06 02:11:40 +02:00
|
|
|
|
void setSolution (TestPOA* p) { solution_ = p; }
|
|
|
|
|
|
const TestPOA* getSolution () const { return solution_;}
|
|
|
|
|
|
Binding::Matcher getMatcher () const { return pattern_; }
|
|
|
|
|
|
|
2010-04-25 15:15:53 +02:00
|
|
|
|
friend HashVal
|
|
|
|
|
|
hash_value (TestPOA const& entry)
|
|
|
|
|
|
{
|
|
|
|
|
|
return hash_value (entry.pattern_);
|
|
|
|
|
|
}
|
2010-04-24 17:31:01 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-25 01:51:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint MAX_TEST_ENTRIES = 10;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TestPOA> testEntries(MAX_TEST_ENTRIES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-24 17:31:01 +02:00
|
|
|
|
/** convenience shortcut for writing testcases inline */
|
2010-04-25 01:51:30 +02:00
|
|
|
|
inline TestPOA&
|
2010-04-24 17:31:01 +02:00
|
|
|
|
_entry (uint id, Literal spec)
|
|
|
|
|
|
{
|
2010-04-25 01:51:30 +02:00
|
|
|
|
REQUIRE (id < testEntries.size());
|
|
|
|
|
|
|
|
|
|
|
|
if (!testEntries[id].matches(spec))
|
|
|
|
|
|
testEntries[id] = TestPOA(spec);
|
|
|
|
|
|
|
|
|
|
|
|
return testEntries[id];
|
2010-04-24 17:31:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** check if the given request got the denoted solution */
|
|
|
|
|
|
inline bool
|
|
|
|
|
|
_hasSolution (uint req, uint prov)
|
|
|
|
|
|
{
|
2010-04-25 01:51:30 +02:00
|
|
|
|
REQUIRE (req < testEntries.size());
|
|
|
|
|
|
REQUIRE (prov < testEntries.size());
|
|
|
|
|
|
|
|
|
|
|
|
return testEntries[req].solution_ == & testEntries[prov];
|
2010-04-24 17:31:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** check if the given request holds a default solution */
|
|
|
|
|
|
inline bool
|
|
|
|
|
|
_hasDefault (uint req)
|
|
|
|
|
|
{
|
2010-04-25 01:51:30 +02:00
|
|
|
|
REQUIRE (req < testEntries.size());
|
|
|
|
|
|
return NULL == testEntries[req].solution_;
|
2010-04-24 17:31:01 +02:00
|
|
|
|
}
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2010-04-24 17:31:01 +02:00
|
|
|
|
typedef Index<TestPOA> Index;
|
|
|
|
|
|
|
2010-04-11 01:11:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/**************************************************************************************//**
|
2010-04-24 17:31:01 +02:00
|
|
|
|
* @test the Advice system uses an index datastructure to support matching the bindings
|
|
|
|
|
|
* to get pairs of participants to connect by an individual advice channel.
|
2010-04-11 01:11:39 +02:00
|
|
|
|
*
|
2010-04-24 17:31:01 +02:00
|
|
|
|
* This test covers the properties of this implementation datastructure in isolation.
|
2010-05-06 03:52:11 +02:00
|
|
|
|
* We employ special \link TestPOA test entries \endlink, different from what is used
|
|
|
|
|
|
* in the advice system (contrary to the real thing we're not differentiating between
|
|
|
|
|
|
* advice request and advice provision, as for the test all we need is the possibility
|
|
|
|
|
|
* to set an "advice solution"). To use these test records, we create a specific
|
|
|
|
|
|
* instantiation of the advice::Index template solely for this test.
|
2010-04-11 01:11:39 +02:00
|
|
|
|
*
|
|
|
|
|
|
* @see advice.hpp
|
|
|
|
|
|
* @see AdviceBasics_test
|
|
|
|
|
|
* @see AdviceBindingPattern_test
|
|
|
|
|
|
*/
|
|
|
|
|
|
class AdviceIndex_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
Index idx;
|
|
|
|
|
|
buildIndex (idx);
|
|
|
|
|
|
|
|
|
|
|
|
addRequest (idx);
|
|
|
|
|
|
addProvision (idx);
|
|
|
|
|
|
removeRequest (idx);
|
|
|
|
|
|
retractProvision (idx);
|
|
|
|
|
|
modifyRequest (idx);
|
|
|
|
|
|
modifyProvision (idx);
|
|
|
|
|
|
|
|
|
|
|
|
clearIndex (idx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
buildIndex (Index& idx)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
CHECK (0 == idx.size());
|
|
|
|
|
|
|
|
|
|
|
|
idx.addRequest (_entry (1,"cat"));
|
|
|
|
|
|
idx.addRequest (_entry (2,"cat"));
|
|
|
|
|
|
idx.addRequest (_entry (3,"dog"));
|
|
|
|
|
|
CHECK (3 == idx.size());
|
|
|
|
|
|
CHECK (3 == idx.request_count());
|
|
|
|
|
|
CHECK (0 == idx.provision_count());
|
|
|
|
|
|
|
|
|
|
|
|
idx.addProvision (_entry (4,"dog"));
|
|
|
|
|
|
CHECK (4 == idx.size());
|
|
|
|
|
|
CHECK (3 == idx.request_count());
|
|
|
|
|
|
CHECK (1 == idx.provision_count());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasDefault (1));
|
|
|
|
|
|
CHECK (_hasDefault (2));
|
|
|
|
|
|
CHECK (_hasSolution (3,4));
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
addRequest (Index& idx)
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
uint req_cnt = idx.request_count();
|
|
|
|
|
|
|
|
|
|
|
|
idx.addRequest (_entry (5,"dog"));
|
|
|
|
|
|
idx.addRequest (_entry (6,"cat"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (idx.hasRequest (_entry (5,"dog")));
|
|
|
|
|
|
CHECK (idx.hasRequest (_entry (6,"cat")));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasDefault (6));
|
|
|
|
|
|
CHECK (_hasSolution (5,4));
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
CHECK (2 + req_cnt == idx.request_count());
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-24 17:31:01 +02:00
|
|
|
|
addProvision (Index& idx)
|
2010-04-11 01:11:39 +02:00
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
uint r_cnt = idx.request_count();
|
|
|
|
|
|
uint p_cnt = idx.provision_count();
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasDefault (1));
|
|
|
|
|
|
CHECK (_hasDefault (2));
|
|
|
|
|
|
CHECK (_hasDefault (6));
|
|
|
|
|
|
CHECK (_hasSolution (3,4));
|
|
|
|
|
|
CHECK (_hasSolution (5,4));
|
|
|
|
|
|
|
|
|
|
|
|
idx.addProvision (_entry (7,"cat"));
|
|
|
|
|
|
CHECK (idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasSolution (1,7)); // all cats got the cat solution
|
|
|
|
|
|
CHECK (_hasSolution (2,7));
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,4)); // dogs unaltered
|
|
|
|
|
|
CHECK (_hasSolution (5,4));
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
CHECK (1 + p_cnt == idx.provision_count());
|
|
|
|
|
|
CHECK (0 + r_cnt == idx.request_count());
|
|
|
|
|
|
|
|
|
|
|
|
idx.addProvision (_entry (8,"dog"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasSolution (1,7)); // cats remain unaffected
|
|
|
|
|
|
CHECK (_hasSolution (2,7));
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,8)); // all dogs got the new solution
|
|
|
|
|
|
CHECK (_hasSolution (5,8));
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
CHECK (2 + p_cnt == idx.provision_count());
|
|
|
|
|
|
CHECK (0 + r_cnt == idx.request_count());
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-24 17:31:01 +02:00
|
|
|
|
removeRequest (Index& idx)
|
2010-04-11 01:11:39 +02:00
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
uint r_cnt = idx.request_count();
|
|
|
|
|
|
uint p_cnt = idx.provision_count();
|
|
|
|
|
|
CHECK (_hasSolution (1,7));
|
|
|
|
|
|
CHECK (_hasSolution (2,7));
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,8));
|
|
|
|
|
|
CHECK (_hasSolution (5,8));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( idx.hasRequest (_entry (2,"cat")));
|
|
|
|
|
|
|
|
|
|
|
|
idx.removeRequest (_entry (2,"cat"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (!idx.hasRequest (_entry (2,"cat")));
|
|
|
|
|
|
CHECK (p_cnt == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt-1 == idx.request_count());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasSolution (1,7)); // no effect on the other requests
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,8));
|
|
|
|
|
|
CHECK (_hasSolution (5,8));
|
|
|
|
|
|
|
|
|
|
|
|
idx.removeRequest (_entry (2,"cat")); // idempotent
|
|
|
|
|
|
CHECK (!idx.hasRequest (_entry (2,"cat")));
|
|
|
|
|
|
CHECK (p_cnt == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt-1 == idx.request_count());
|
|
|
|
|
|
CHECK (idx.isValid());
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-24 17:31:01 +02:00
|
|
|
|
retractProvision (Index& idx)
|
2010-04-11 01:11:39 +02:00
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
uint r_cnt = idx.request_count();
|
|
|
|
|
|
uint p_cnt = idx.provision_count();
|
|
|
|
|
|
CHECK (_hasSolution (1,7));
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,8));
|
|
|
|
|
|
CHECK (_hasSolution (5,8));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (4,"dog")));
|
|
|
|
|
|
|
|
|
|
|
|
idx.removeProvision (_entry (4,"dog"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (4,"dog")));
|
|
|
|
|
|
CHECK (p_cnt-1 == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt == idx.request_count());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasSolution (1,7)); // no effect on the solutions, because of the more recent dog solution 8
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,8));
|
|
|
|
|
|
CHECK (_hasSolution (5,8));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (8,"dog")));
|
|
|
|
|
|
|
|
|
|
|
|
idx.removeProvision (_entry (8,"dog"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (8,"dog")));
|
|
|
|
|
|
CHECK (p_cnt-2 == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt == idx.request_count());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (_hasSolution (1,7)); // no effect on the cat solutions
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (!_hasSolution (3,8));
|
|
|
|
|
|
CHECK (!_hasSolution (5,8));
|
|
|
|
|
|
CHECK (_hasDefault (3)); // but all dog requests reverted to default
|
|
|
|
|
|
CHECK (_hasDefault (5));
|
|
|
|
|
|
|
|
|
|
|
|
idx.removeProvision (_entry (8,"dog")); // idempotent
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (8,"dog")));
|
|
|
|
|
|
CHECK (p_cnt-2 == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt == idx.request_count());
|
|
|
|
|
|
CHECK (idx.isValid());
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-24 17:31:01 +02:00
|
|
|
|
modifyRequest (Index& idx)
|
2010-04-11 01:11:39 +02:00
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
uint r_cnt = idx.request_count();
|
|
|
|
|
|
uint p_cnt = idx.provision_count();
|
|
|
|
|
|
CHECK (_hasSolution (1,7));
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasDefault (3));
|
|
|
|
|
|
CHECK (_hasDefault (5));
|
|
|
|
|
|
|
2010-06-04 17:25:33 +02:00
|
|
|
|
HashVal dogHash (hash_value (_entry (5,"dog")));
|
|
|
|
|
|
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK ( idx.hasRequest (_entry (5,"dog")));
|
2010-06-04 17:25:33 +02:00
|
|
|
|
_entry (5,"dog").changeBinding("cat"); // transmogrify existing request into cat-request
|
|
|
|
|
|
CHECK (_hasDefault (5)); // of course this didn't change the solution
|
2025-06-07 23:59:57 +02:00
|
|
|
|
CHECK (!idx.hasRequest (_entry (5,"cat"))); // can't find it anymore because of changed binding
|
2010-04-24 17:31:01 +02:00
|
|
|
|
|
2010-06-04 17:25:33 +02:00
|
|
|
|
idx.modifyRequest (dogHash, _entry (5,"cat"));
|
2010-04-24 17:31:01 +02:00
|
|
|
|
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK ( idx.hasRequest (_entry (5,"cat")));
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (p_cnt == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt == idx.request_count());
|
|
|
|
|
|
CHECK (_hasSolution (1,7));
|
|
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasDefault (3));
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasSolution (5,7)); // automatically got the current cat solution
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-24 17:31:01 +02:00
|
|
|
|
modifyProvision (Index& idx)
|
2010-04-11 01:11:39 +02:00
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
uint r_cnt = idx.request_count();
|
|
|
|
|
|
uint p_cnt = idx.provision_count();
|
|
|
|
|
|
CHECK (_hasSolution (1,7));
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasSolution (5,7));
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasDefault (3));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (8,"dog")));
|
|
|
|
|
|
|
|
|
|
|
|
idx.modifyProvision (_entry (7,"cat"), _entry (8,"dog"));
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (8,"dog")));
|
|
|
|
|
|
CHECK (p_cnt == idx.provision_count());
|
|
|
|
|
|
CHECK (r_cnt == idx.request_count());
|
|
|
|
|
|
CHECK (_hasDefault (1));
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasDefault (5));
|
2010-05-05 04:01:26 +02:00
|
|
|
|
CHECK (_hasDefault (6));
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (_hasSolution (3,8));
|
|
|
|
|
|
|
|
|
|
|
|
idx.addProvision (_entry (7,"cat"));
|
|
|
|
|
|
idx.addProvision (_entry (9,"cat"));
|
2010-05-05 04:01:26 +02:00
|
|
|
|
CHECK (p_cnt+2 == idx.provision_count());
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
CHECK (idx.hasProvision (_entry (9,"cat")));
|
|
|
|
|
|
CHECK (_hasSolution (1,9)); // all cats got the second cat solution
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasSolution (5,9));
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (_hasSolution (6,9));
|
|
|
|
|
|
CHECK (_hasSolution (3,8)); // the dog is unaffected
|
2010-05-06 03:52:11 +02:00
|
|
|
|
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK ( idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (4,"dog")));
|
|
|
|
|
|
|
|
|
|
|
|
idx.modifyProvision (_entry (7,"cat"), _entry (4,"dog"));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (4,"dog")));
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasSolution (1,9)); // cats unaffected, because we're changing a shadowed cat provision
|
|
|
|
|
|
CHECK (_hasSolution (5,9));
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (_hasSolution (6,9));
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasSolution (3,4)); // but the dog got switched to the replaced-by-dog solution,
|
2010-04-24 17:31:01 +02:00
|
|
|
|
// because it was added later than the existing solution 8
|
2010-05-06 03:52:11 +02:00
|
|
|
|
|
|
|
|
|
|
// a switch within the same cluster ("cat")
|
|
|
|
|
|
idx.modifyProvision (_entry (9,"cat"), _entry (7,"cat"));
|
|
|
|
|
|
CHECK (!idx.hasProvision (_entry (9,"cat")));
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (7,"cat")));
|
|
|
|
|
|
CHECK ( idx.hasProvision (_entry (4,"dog")));
|
2010-05-25 06:51:37 +02:00
|
|
|
|
CHECK (_hasSolution (1,7)); // because cat-7 is newly added, it shadows the older cat-9
|
2010-06-04 17:25:33 +02:00
|
|
|
|
CHECK (_hasSolution (5,7));
|
2010-05-06 03:52:11 +02:00
|
|
|
|
CHECK (_hasSolution (6,7));
|
|
|
|
|
|
CHECK (_hasSolution (3,4)); // but dog remains dog
|
|
|
|
|
|
|
2010-05-05 04:01:26 +02:00
|
|
|
|
CHECK (p_cnt+2 == idx.provision_count());
|
2010-04-24 17:31:01 +02:00
|
|
|
|
CHECK (r_cnt == idx.request_count());
|
|
|
|
|
|
CHECK (idx.isValid());
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-04-24 17:31:01 +02:00
|
|
|
|
clearIndex (Index& idx)
|
2010-04-11 01:11:39 +02:00
|
|
|
|
{
|
2010-04-24 17:31:01 +02:00
|
|
|
|
idx.clear();
|
|
|
|
|
|
CHECK (idx.isValid());
|
|
|
|
|
|
CHECK (0 == idx.size());
|
2010-04-11 01:11:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (AdviceIndex_test, "function common");
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-01 08:44:07 +01:00
|
|
|
|
}}} // namespace lumiera::advice::test
|