#include "queue.h" #include #include namespace NThreading { //////////////////////////////////////////////////////////////////////////////// Y_UNIT_TEST_SUITE(TOneOneQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ TOneOneQueue queue; int result = 0; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } Y_UNIT_TEST(ShouldReturnEntries) { TOneOneQueue queue; queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 1); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 3); UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } Y_UNIT_TEST(ShouldStoreMultipleChunks) { TOneOneQueue queue; for (int i = 0; i < 1000; ++i) { queue.Enqueue(i); } for (int i = 0; i < 1000; ++i) { int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, i); } } } //////////////////////////////////////////////////////////////////////////////// Y_UNIT_TEST_SUITE(TManyOneQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ TManyOneQueue queue; int result; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } Y_UNIT_TEST(ShouldReturnEntries) { TManyOneQueue queue; queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 1); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 3); UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } //////////////////////////////////////////////////////////////////////////////// Y_UNIT_TEST_SUITE(TManyManyQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ TManyManyQueue queue; int result = 0; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } Y_UNIT_TEST(ShouldReturnEntries) { TManyManyQueue queue; queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 1); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 2); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT_EQUAL(result, 3); UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } //////////////////////////////////////////////////////////////////////////////// Y_UNIT_TEST_SUITE(TRelaxedManyOneQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ TRelaxedManyOneQueue queue; int result; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } Y_UNIT_TEST(ShouldReturnEntries) { TSet items = {1, 2, 3}; TRelaxedManyOneQueue queue; for (int item : items) { queue.Enqueue(item); } int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } //////////////////////////////////////////////////////////////////////////////// Y_UNIT_TEST_SUITE(TRelaxedManyManyQueueTest){ Y_UNIT_TEST(ShouldBeEmptyAtStart){ TRelaxedManyManyQueue queue; int result = 0; UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } Y_UNIT_TEST(ShouldReturnEntries) { TSet items = {1, 2, 3}; TRelaxedManyManyQueue queue; for (int item : items) { queue.Enqueue(item); } int result = 0; UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); UNIT_ASSERT(!queue.IsEmpty()); UNIT_ASSERT(queue.Dequeue(result)); UNIT_ASSERT(items.erase(result)); UNIT_ASSERT(queue.IsEmpty()); UNIT_ASSERT(!queue.Dequeue(result)); } } }