Add more tests to UnitTest for TSLQueue

This commit is contained in:
Stephen Seo 2019-11-06 12:54:03 +09:00
parent 3830be6e2d
commit 3f338be365

View file

@ -188,4 +188,49 @@ TEST(TSLQueue, Iterator) {
}
EXPECT_TRUE(q.pop());
}
// remove from start
q.push(0);
q.push(1);
q.push(2);
q.push(3);
{
auto iter = q.begin();
EXPECT_TRUE(iter.remove());
}
i = 1;
while(!q.empty()) {
op = q.top();
EXPECT_TRUE(op.has_value());
EXPECT_EQ(i++, op.value());
EXPECT_TRUE(q.pop());
}
// remove from end
q.push(0);
q.push(1);
q.push(2);
q.push(3);
{
auto iter = q.begin();
while(true) {
EXPECT_TRUE(iter.next());
op = iter.current();
EXPECT_TRUE(op.has_value());
if(op.value() == 3) {
EXPECT_FALSE(iter.remove());
break;
}
}
}
i = 0;
while(!q.empty()) {
op = q.top();
EXPECT_TRUE(op.has_value());
EXPECT_EQ(i++, op.value());
EXPECT_TRUE(q.pop());
if(i == 3) {
EXPECT_TRUE(q.empty());
}
}
}