2016-08-18 22:34:36 +08:00
|
|
|
#define CATCH_CONFIG_MAIN
|
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include "data_structures/concurrent/concurrent_list.hpp"
|
|
|
|
|
|
|
|
TEST_CASE("Conncurent List insert")
|
|
|
|
{
|
2016-09-13 03:13:04 +08:00
|
|
|
ConcurrentList<int> list;
|
2016-08-18 22:34:36 +08:00
|
|
|
auto it = list.begin();
|
|
|
|
it.push(32);
|
|
|
|
it.reset();
|
|
|
|
REQUIRE(*it == 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Conncurent List iterate")
|
|
|
|
{
|
2016-09-13 03:13:04 +08:00
|
|
|
ConcurrentList<int> list;
|
2016-08-18 22:34:36 +08:00
|
|
|
auto it = list.begin();
|
|
|
|
it.push(32);
|
|
|
|
it.push(7);
|
|
|
|
it.push(9);
|
|
|
|
it.push(0);
|
|
|
|
it.reset();
|
|
|
|
|
|
|
|
REQUIRE(*it == 0);
|
|
|
|
it++;
|
|
|
|
REQUIRE(*it == 9);
|
|
|
|
it++;
|
|
|
|
REQUIRE(*it == 7);
|
|
|
|
it++;
|
|
|
|
REQUIRE(*it == 32);
|
|
|
|
it++;
|
|
|
|
REQUIRE(it == list.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Conncurent List head remove")
|
|
|
|
{
|
2016-09-13 03:13:04 +08:00
|
|
|
ConcurrentList<int> list;
|
2016-08-18 22:34:36 +08:00
|
|
|
auto it = list.begin();
|
|
|
|
it.push(32);
|
|
|
|
it.reset();
|
|
|
|
|
|
|
|
REQUIRE(it.remove());
|
|
|
|
REQUIRE(it.is_removed());
|
|
|
|
REQUIRE(!it.remove());
|
|
|
|
|
|
|
|
it.reset();
|
|
|
|
REQUIRE(it == list.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Conncurent List remove")
|
|
|
|
{
|
2016-09-13 03:13:04 +08:00
|
|
|
ConcurrentList<int> list;
|
2016-08-18 22:34:36 +08:00
|
|
|
auto it = list.begin();
|
|
|
|
it.push(32);
|
|
|
|
it.push(7);
|
|
|
|
it.push(9);
|
|
|
|
it.push(0);
|
|
|
|
it.reset();
|
|
|
|
|
|
|
|
it++;
|
|
|
|
it++;
|
|
|
|
REQUIRE(it.remove());
|
|
|
|
REQUIRE(it.is_removed());
|
|
|
|
REQUIRE(!it.remove());
|
|
|
|
|
|
|
|
it.reset();
|
|
|
|
REQUIRE(*it == 0);
|
|
|
|
it++;
|
|
|
|
REQUIRE(*it == 9);
|
|
|
|
it++;
|
|
|
|
REQUIRE(*it == 32);
|
|
|
|
it++;
|
|
|
|
REQUIRE(it == list.end());
|
|
|
|
}
|