2013-01-13 16:49:20 +01:00
|
|
|
|
/*
|
|
|
|
|
|
UtilCollection(Test) - helpers and shortcuts for working with collections
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2012, Hermann Vosseler <Ichthyostega@web.de>
|
2013-01-13 16:49:20 +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.
|
2013-01-13 16:49:20 +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
|
|
|
|
* *****************************************************************/
|
2013-01-13 16:49:20 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file util-collection-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref UtilCollection_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2013-01-13 16:49:20 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/itertools.hpp"
|
|
|
|
|
|
#include "lib/util-coll.hpp"
|
|
|
|
|
|
#include "lib/iter-adapter.hpp"
|
|
|
|
|
|
#include "lib/meta/trait.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using ::Test;
|
|
|
|
|
|
|
|
|
|
|
|
using util::first;
|
|
|
|
|
|
using util::last;
|
|
|
|
|
|
|
|
|
|
|
|
using lib::meta::can_STL_ForEach;
|
|
|
|
|
|
using lib::meta::can_IterForEach;
|
|
|
|
|
|
using lib::meta::can_STL_backIteration;
|
|
|
|
|
|
|
|
|
|
|
|
using boost::lexical_cast;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace util {
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<uint> VecI;
|
|
|
|
|
|
typedef lib::RangeIter<VecI::iterator> RangeI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace{ // Test data and operations
|
|
|
|
|
|
|
|
|
|
|
|
VecI
|
|
|
|
|
|
someNumberz (uint count)
|
|
|
|
|
|
{
|
|
|
|
|
|
VecI numbers;
|
|
|
|
|
|
numbers.reserve(count);
|
|
|
|
|
|
while (count)
|
|
|
|
|
|
numbers.push_back(count--);
|
|
|
|
|
|
|
|
|
|
|
|
return numbers;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // (End) test data and operations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/*****************************************************************//**
|
2013-01-13 16:49:20 +01:00
|
|
|
|
* @test verify some convenience shortcuts and helpers dealing
|
|
|
|
|
|
* with Collections and sequences (Iterators).
|
|
|
|
|
|
* - metafunctions to distinguish STL containers and Lumiera Iterators
|
|
|
|
|
|
* - get the first element
|
|
|
|
|
|
* - get the last element
|
|
|
|
|
|
*/
|
|
|
|
|
|
class UtilCollection_test : public Test
|
|
|
|
|
|
{
|
2024-11-15 19:02:48 +01:00
|
|
|
|
virtual void
|
2013-01-13 16:49:20 +01:00
|
|
|
|
run (Arg arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
verify_typeDetectors();
|
|
|
|
|
|
|
2024-11-15 19:02:48 +01:00
|
|
|
|
uint NUM_ELMS = firstVal (arg, 20);
|
2013-01-13 16:49:20 +01:00
|
|
|
|
VecI container = someNumberz (NUM_ELMS);
|
|
|
|
|
|
RangeI iterator(container.begin(), container.end());
|
|
|
|
|
|
|
|
|
|
|
|
verify_accessFirstLast (container, NUM_ELMS);
|
|
|
|
|
|
verify_accessFirstLast (iterator, NUM_ELMS);
|
2020-03-08 02:05:39 +01:00
|
|
|
|
|
|
|
|
|
|
verify_Min_Max (container, NUM_ELMS);
|
|
|
|
|
|
verify_Min_Max (iterator, NUM_ELMS);
|
2013-01-13 16:49:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class COL>
|
|
|
|
|
|
void
|
|
|
|
|
|
verify_accessFirstLast (COL const& col, uint lim)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint theFirst = lim;
|
|
|
|
|
|
uint theLast = 1;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (first(col) == theFirst);
|
|
|
|
|
|
CHECK (last(col) == theLast);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-08 02:05:39 +01:00
|
|
|
|
template<class COL>
|
|
|
|
|
|
void
|
|
|
|
|
|
verify_Min_Max (COL const& col, uint lim)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint expectedMax = lim;
|
|
|
|
|
|
uint expectedMin = 1;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (max (col) == expectedMax);
|
|
|
|
|
|
CHECK (min (col) == expectedMin);
|
|
|
|
|
|
|
|
|
|
|
|
COL empty;
|
|
|
|
|
|
|
2025-07-05 20:08:18 +02:00
|
|
|
|
using Val = COL::value_type;
|
2020-03-08 02:05:39 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (max (empty) == std::numeric_limits<Val>::min());
|
|
|
|
|
|
CHECK (min (empty) == std::numeric_limits<Val>::max());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-13 16:49:20 +01:00
|
|
|
|
void
|
|
|
|
|
|
verify_typeDetectors()
|
|
|
|
|
|
{
|
|
|
|
|
|
CHECK ( can_STL_ForEach<VecI>::value);
|
|
|
|
|
|
CHECK ( can_STL_backIteration<VecI>::value);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (!can_STL_ForEach<RangeI>::value);
|
|
|
|
|
|
CHECK (!can_STL_backIteration<RangeI>::value);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (!can_IterForEach<VecI>::value);
|
|
|
|
|
|
CHECK ( can_IterForEach<RangeI>::value);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LAUNCHER (UtilCollection_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace util::test
|
|
|
|
|
|
|