Skip to content
Snippets Groups Projects
Commit 17fd2797 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

+ std excludes

parent 642063f4
No related branches found
No related tags found
No related merge requests found
#ifndef __ALGORITHM_HEADER_WRAPPER_
#define __ALGORITHM_HEADER_WRAPPER_
#include <bits/../algorithm>
#include "extensions/algorithm.hpp"
#endif /* __ALGORITHM_HEADER_WRAPPER_ */
/*
* algorithm.hpp
*
* Created on: May 28, 2015
* Author: Jan Travnicek
*/
#ifndef ALGORITHM_HPP_
#define ALGORITHM_HPP_
namespace std {
template<class InputIt1, class InputIt2>
bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) {
while (first2 != last2 && first1 != last1) {
if ( *first2 < *first1 ) {
++first2;
} else if( *first1 < *first2 ) {
++first1;
} else {
return false;
}
}
return true;
}
template<class InputIt1, class InputIt2, class Compare>
bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp) {
while (first2 != last2 && first1 != last1) {
if (comp(*first2, *first1)) {
++first2;
} else if (comp(*first1, *first2)) {
++first1;
} else {
return false;
}
}
return true;
}
} /* namespace std */
#endif /* ALGORITHM_HPP_ */
#include "AlgorithmTest.h"
#include <algorithm>
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AlgorithmTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION( AlgorithmTest );
void AlgorithmTest::setUp() {
}
void AlgorithmTest::tearDown() {
}
void AlgorithmTest::testExclude() {
{
int array1[] = {1, 2, 3};
int array2[] = {2, 3, 4};
std::cout << sizeof(array1) / sizeof(int);
CPPUNIT_ASSERT(std::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == false);
}
{
int array1[] = {1, 3, 5};
int array2[] = {2, 4, 6, 8};
CPPUNIT_ASSERT(std::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == true);
CPPUNIT_ASSERT(std::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == true);
}
{
int array1[] = {1, 3, 5, 8};
int array2[] = {2, 4, 6, 8};
CPPUNIT_ASSERT(std::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == false);
CPPUNIT_ASSERT(std::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == false);
}
{
int array1[] = {0};
int array2[] = {2, 4, 6, 8};
CPPUNIT_ASSERT(std::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == true);
CPPUNIT_ASSERT(std::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == true);
CPPUNIT_ASSERT(std::excludes(array1, array1, array2, array2) == true);
CPPUNIT_ASSERT(std::excludes(array2, array2, array1, array1) == true);
}
}
#ifndef ALGORITHM_TEST_H_
#define ALGORITHM_TEST_H_
#include <cppunit/extensions/HelperMacros.h>
class AlgorithmTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( AlgorithmTest );
CPPUNIT_TEST( testExclude );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testExclude();
};
#endif // ALGORITHM_TEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment