2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2021-04-25 08:53:23 +03:00
|
|
|
#include <LibTest/TestCase.h>
|
2019-08-02 10:23:03 +03:00
|
|
|
|
2023-12-16 17:19:34 +03:00
|
|
|
#include <AK/ByteString.h>
|
2019-06-15 11:34:03 +03:00
|
|
|
#include <AK/Queue.h>
|
|
|
|
|
2019-07-16 11:08:39 +03:00
|
|
|
TEST_CASE(construct)
|
2019-06-15 11:34:03 +03:00
|
|
|
{
|
|
|
|
EXPECT(Queue<int>().is_empty());
|
|
|
|
EXPECT(Queue<int>().size() == 0);
|
2019-07-16 11:08:39 +03:00
|
|
|
}
|
2019-06-15 11:34:03 +03:00
|
|
|
|
2019-07-16 11:08:39 +03:00
|
|
|
TEST_CASE(populate_int)
|
|
|
|
{
|
2019-06-15 11:34:03 +03:00
|
|
|
Queue<int> ints;
|
|
|
|
ints.enqueue(1);
|
|
|
|
ints.enqueue(2);
|
|
|
|
ints.enqueue(3);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 3u);
|
2019-06-15 11:39:19 +03:00
|
|
|
EXPECT_EQ(ints.dequeue(), 1);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 2u);
|
2019-06-15 11:39:19 +03:00
|
|
|
EXPECT_EQ(ints.dequeue(), 2);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 1u);
|
2019-06-15 11:39:19 +03:00
|
|
|
EXPECT_EQ(ints.dequeue(), 3);
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(ints.size(), 0u);
|
2019-07-16 11:08:39 +03:00
|
|
|
}
|
2019-06-15 11:34:03 +03:00
|
|
|
|
2019-07-16 11:08:39 +03:00
|
|
|
TEST_CASE(populate_string)
|
|
|
|
{
|
2023-12-16 17:19:34 +03:00
|
|
|
Queue<ByteString> strings;
|
2019-06-15 11:34:03 +03:00
|
|
|
strings.enqueue("ABC");
|
|
|
|
strings.enqueue("DEF");
|
2020-03-06 13:21:23 +03:00
|
|
|
EXPECT_EQ(strings.size(), 2u);
|
2019-06-15 11:39:19 +03:00
|
|
|
EXPECT_EQ(strings.dequeue(), "ABC");
|
|
|
|
EXPECT_EQ(strings.dequeue(), "DEF");
|
|
|
|
EXPECT(strings.is_empty());
|
2019-07-16 11:08:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(order)
|
|
|
|
{
|
2023-12-16 17:19:34 +03:00
|
|
|
Queue<ByteString> strings;
|
2019-07-16 11:08:39 +03:00
|
|
|
EXPECT(strings.is_empty());
|
2019-06-15 11:39:19 +03:00
|
|
|
|
2020-03-06 13:21:23 +03:00
|
|
|
for (size_t i = 0; i < 10000; ++i) {
|
2023-12-16 17:19:34 +03:00
|
|
|
strings.enqueue(ByteString::number(i));
|
2019-06-15 11:39:19 +03:00
|
|
|
EXPECT_EQ(strings.size(), i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
2023-12-23 05:59:14 +03:00
|
|
|
EXPECT_EQ(strings.dequeue().to_number<int>().value(), i);
|
2019-06-15 11:39:19 +03:00
|
|
|
}
|
|
|
|
|
2019-06-15 11:34:03 +03:00
|
|
|
EXPECT(strings.is_empty());
|
|
|
|
}
|