mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Unit Tests - list.t
- Added listIntersect and a Boolean listDiff implementation in main.h. - Added a set of unit tests for the above.
This commit is contained in:
parent
42981c746e
commit
75e738a9c9
4 changed files with 144 additions and 1 deletions
31
src/main.h
31
src/main.h
|
@ -124,6 +124,19 @@ std::string colorizeDebug (const std::string&);
|
|||
int handleImport (std::string&);
|
||||
|
||||
// list template
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <class T> bool listDiff (const T& left, const T& right)
|
||||
{
|
||||
if (left.size () != right.size ())
|
||||
return true;
|
||||
|
||||
for (unsigned int i = 0; i < left.size (); ++i)
|
||||
if (left[i] != right[i])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <class T> void listDiff (
|
||||
const T& left, const T& right, T& leftOnly, T& rightOnly)
|
||||
|
@ -164,5 +177,23 @@ template <class T> void listDiff (
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class T> void listIntersect (const T& left, const T& right, T& join)
|
||||
{
|
||||
join.clear ();
|
||||
|
||||
for (unsigned int l = 0; l < left.size (); ++l)
|
||||
{
|
||||
for (unsigned int r = 0; r < right.size (); ++r)
|
||||
{
|
||||
if (left[l] == right[r])
|
||||
{
|
||||
join.push_back (left[l]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue