本文整理汇总了C++中BoundedBuffer::push方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundedBuffer::push方法的具体用法?C++ BoundedBuffer::push怎么用?C++ BoundedBuffer::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundedBuffer
的用法示例。
在下文中一共展示了BoundedBuffer::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_buffer_after_swap_argument_has_this_content
void test_buffer_after_swap_argument_has_this_content() {
std::vector<int> frontValues { }, expectedValues { 1, 2, 3 };
BoundedBuffer<int> buffer { 5 }, otherBuffer { 5 };
buffer.push(1);
buffer.push(2);
buffer.push(3);
buffer.swap(otherBuffer);
3_times([&]() {frontValues.push_back(otherBuffer.front()); otherBuffer.pop();});
ASSERT_EQUAL(expectedValues, frontValues);
}
示例2: test_const_buffer_back_gets_last_element_of_two_pushs
void test_const_buffer_back_gets_last_element_of_two_pushs() {
BoundedBuffer<int> buffer { 5 };
buffer.push(1);
buffer.push(2);
auto const & constBuffer = buffer;
ASSERT_EQUAL(2, constBuffer.back());
}
示例3: test_const_buffer_front_throws_after_push_pop
void test_const_buffer_front_throws_after_push_pop() {
BoundedBuffer<int, 5> buffer { };
buffer.push(5);
buffer.pop();
auto const & constBuffer = buffer;
ASSERT_THROWS(constBuffer.front(), std::logic_error);
}
示例4: test_const_buffer_front_gets_first_element_of_pushs
void test_const_buffer_front_gets_first_element_of_pushs() {
BoundedBuffer<int> buffer { 5 };
buffer.push(1);
buffer.push(2);
auto const & constBuffer = buffer;
ASSERT_EQUAL(1, constBuffer.front());
}
示例5: test_const_buffer_back_throws_after_push_pop
void test_const_buffer_back_throws_after_push_pop() {
BoundedBuffer<int> buffer { 5 };
buffer.push(5);
buffer.pop();
auto const & constBuffer = buffer;
ASSERT_THROWS(constBuffer.back(), std::logic_error);
}
示例6: test_buffer_wrap_around_behavior_back
void test_buffer_wrap_around_behavior_back() {
BoundedBuffer<int> buffer { 3 };
std::vector<int> backValues { }, expectedValues { 1, 2, 2, 3, 4, 4, 4, 5, 5, 6, 7, 7, 7 };
buffer.push(1);
backValues.push_back(buffer.back());
buffer.push(2);
backValues.push_back(buffer.back());
buffer.pop();
backValues.push_back(buffer.back());
buffer.push(3);
backValues.push_back(buffer.back());
buffer.push(4);
backValues.push_back(buffer.back());
buffer.pop();
backValues.push_back(buffer.back());
buffer.pop();
backValues.push_back(buffer.back());
buffer.push(5);
backValues.push_back(buffer.back());
buffer.pop();
backValues.push_back(buffer.back());
buffer.push(6);
backValues.push_back(buffer.back());
buffer.push(7);
backValues.push_back(buffer.back());
buffer.pop();
backValues.push_back(buffer.back());
buffer.pop();
backValues.push_back(buffer.back());
ASSERT_EQUAL(expectedValues, backValues);
}
示例7: test_buffer_wrap_around_behavior_front
void test_buffer_wrap_around_behavior_front() {
BoundedBuffer<int, 3> buffer { };
std::vector<int> frontValues { }, expectedValues { 1, 1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 7 };
buffer.push(1);
frontValues.push_back(buffer.front());
buffer.push(2);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(3);
frontValues.push_back(buffer.front());
buffer.push(4);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(5);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(6);
frontValues.push_back(buffer.front());
buffer.push(7);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
ASSERT_EQUAL(expectedValues, frontValues);
}
示例8: test_buffer_fronts_in_sequence_of_push_pop
void test_buffer_fronts_in_sequence_of_push_pop() {
BoundedBuffer<int> buffer { 5 };
std::vector<int> frontValues { }, expectedValues { 1, 1, 1, 2, 2, 3, 4, 4, 5 };
buffer.push(1);
frontValues.push_back(buffer.front());
buffer.push(2);
frontValues.push_back(buffer.front());
buffer.push(3);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(4);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(5);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
ASSERT_EQUAL(expectedValues, frontValues);
}
示例9: test_buffer_front_gets_first_element_of_pushs
void test_buffer_front_gets_first_element_of_pushs() {
BoundedBuffer<int> buffer { 5 };
buffer.push(1);
buffer.push(2);
ASSERT_EQUAL(1, buffer.front());
}
示例10: test_buffer_front_throws_after_push_pop
void test_buffer_front_throws_after_push_pop() {
BoundedBuffer<int> buffer { 5 };
buffer.push(5);
buffer.pop();
ASSERT_THROWS(buffer.front(), std::logic_error);
}
示例11: test_buffer_size_is_fifty_after_fifty_pushs
void test_buffer_size_is_fifty_after_fifty_pushs() {
BoundedBuffer<int> buffer { 75 };
50_times([&]() {buffer.push(5);});
ASSERT_EQUAL(50, buffer.size());
}
示例12: test_buffer_back_gets_element_of_push
void test_buffer_back_gets_element_of_push() {
BoundedBuffer<int> buffer { 5 };
buffer.push(5);
ASSERT_EQUAL(5, buffer.back());
}
示例13: test_buffer_of_size_two_is_full_after_two_pushs
void test_buffer_of_size_two_is_full_after_two_pushs() {
BoundedBuffer<int> buffer { 2 };
2_times([&]() {buffer.push(5);});
ASSERTM("Buffer of size two should be full after two pushs", buffer.full());
}
示例14: test_buffer_size_is_one_after_push
void test_buffer_size_is_one_after_push() {
BoundedBuffer<int> buffer { 2 };
buffer.push(1);
ASSERT_EQUAL(1, buffer.size());
}
示例15: test_buffer_is_empty_after_one_push_and_pop
void test_buffer_is_empty_after_one_push_and_pop() {
BoundedBuffer<int> buffer { 5 };
buffer.push(5);
buffer.pop();
ASSERTM("Buffer should be empty after one push and pop", buffer.empty());
}