Skip to content
Snippets Groups Projects
ForeachTest.cpp 1010 B
Newer Older
Jan Trávníček's avatar
Jan Trávníček committed
#include "ForeachTest.h"
#include <list>
#include <vector>
#include <foreach>


CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ForeachTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION( ForeachTest );

void ForeachTest::setUp() {
}

void ForeachTest::tearDown() {
}

void ForeachTest::testForeach() {
	ext::vector<int> vector1 {1, 2, 3};
	ext::list<int> list1 {2, 3, 4};
Jan Trávníček's avatar
Jan Trávníček committed

	int i = 1;
	for(const ext::tuple<const int&, const int&>& elements : ext::make_tuple_foreach(vector1, list1)) {
Jan Trávníček's avatar
Jan Trávníček committed
		CPPUNIT_ASSERT(std::get<0>(elements) == i);
		CPPUNIT_ASSERT(std::get<1>(elements) == i + 1);
		i++;
	}
}

void ForeachTest::testForeach2() {
	ext::vector<int> vector1 {1, 2, 3};
	ext::list<int> list1 {2, 3, 4};
	ext::set<int> set1 {3, 4, 5};
	for(const ext::tuple<const int&, const int&, const int&>& elements : ext::make_tuple_foreach(vector1, list1, set1)) {
		CPPUNIT_ASSERT(std::get<0>(elements) == i);
		CPPUNIT_ASSERT(std::get<1>(elements) == i + 1);
		CPPUNIT_ASSERT(std::get<2>(elements) == i + 2);
		i++;
	}
}